User:Krinkle/Scripts/SpecialAbuseLog HistLink.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * Article history link for SpecialAbuseLog
 *
 * @author Krinkle
 * @revision 2015-04-10)
 * @license This script is released in the public domain. Released as-is without guarantee of any kind.
 * @stats [[File:Krinkle_SpecialAbuseLog_HistLink.js]]
 * @source https://meta.wikimedia.org/wiki/User:Krinkle/Scripts/SpecialAbuseLog_HistLink
 *
 * Adds an additional (hist) link for article link on Special:AbuseLog
 * Is appended after the link in $5 of [[MediaWiki:Abusefilter-log-detailedentry-meta]].
 * (due to $5 including the [[ and ]], {{fullurl:}} can't be used, hence this work-around
 *
 * Message:
 *	$1: $2 triggered $3, performing the action "$4" on $5. Actions taken: $6; Filter description: $7 ($8)
 * Sample:
 *	<div class="mw-specialpage-summary"> <!-- (...) -->   </div>
 *	<fieldset>
 *		<p>$1: <a href="/wiki/Special:Contributions/Foo">Foo</a> <span class="mw-usertoollinks">(<a>talk</a> | <a>block</a>)</span> triggered <a>filter 10</a>, performing the action "edit" on <a href="/wiki/Article" title="Article">Article</a>. Action taken: Warn; Filter description: Filternamehere (<a>details</a> | <a>examine</a>)</p>
 *		<!-- (...) -->
 *	</fieldset>
 *
 * The following script assumes that the *third* (0,1,2) anchor link that is a *direct child* of the paragraph tag.
 */
jQuery( function( $ ) {

	var	histLinkText = 'hist', // [[MediaWiki:hist]]
		linkOffset = 2; // 0 = first. By default the 3rd link is the article link (thus offset = 2)

	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'AbuseLog' ) {
		$( '.mw-specialpage-summary:first' )
			.next( 'fieldset' )
			.find( '> p:first > a' )
			.eq( linkOffset )
			.each( function() {
				var	$el = $(this),
					$histLink = $( '<a>', {
						title: $el.attr( 'title' ), 
						href: $el.attr( 'href' ) + '?action=history',
						text: histLinkText
					} );
				$el.after( ') ' ).after( $histLink ).after( ' (' );
		} );
	}
} );