Snippets/Last revision action

From mediawiki.org
How to use Snippets
List of Snippets
Last revision action
Language(s): JavaScript
Compatible with: MediaWiki 1.22+ (Vector; Monobook)

Description[edit]

Adds a link to the content actions for the difference view of the most recent edit to the current page.

Code[edit]

/**
 * Action link: Last revision diff
 *
 * @source: https://www.mediawiki.org/wiki/Snippets/Last_revision_action
 * @rev: 2014-08-12
 */
mw.hook( 'wikipage.content' ).add( function() {
	// Not on Special pages
	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) ) {
		return;
	}
	var url = mw.util.getUrl( mw.config.get( 'wgPageName' ) ) +
		'?diff=' + mw.config.get( 'wgCurRevisionId' ),
		$link = $( '#ca-lastdiff' ).find( 'a' );
	if ( $link.length ) {
		$link.attr( 'href', url );
	} else {
		mw.util.addPortletLink( 'p-cactions', url, 'Last', 'ca-lastdiff', 'Show most recent diff' );
	}
} );