Snippets/Last revision action

From MediaWiki.org
Jump to navigation Jump to search
How to use Snippets
List of Snippets
Crystal Clear action run.png
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' );
	}
} );