Jump to content

User:Technical 13/Scripts/Gadget-codeBacklinks.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Technical 13 (talk | contribs) at 19:34, 17 January 2014 (Copying my script from http://ddowiki.com/page/MediaWiki:Gadget-codeBacklinks.js). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var PCM = mw.config.get( "wgPageContentModel" );
$("pre.source-" + PCM).find("span.coMULTI").each(function(){
	var codeComment = $(this).html().substr($(this).html().indexOf("[["));
	var wikiLinkPipe = "";
	var extraLinks =  "";
	while(codeComment.indexOf("[[") !== -1 && codeComment.indexOf("]]") !== -1){
		if(codeComment.indexOf("|") !== -1 && codeComment.indexOf("|") > codeComment.indexOf("[[") && codeComment.indexOf("|") < codeComment.indexOf("]]")){
			var wikiLink = codeComment.slice(codeComment.indexOf("[[") +2, codeComment.indexOf("|"));
			wikiLinkPipe = codeComment.slice(codeComment.indexOf("|"), codeComment.indexOf("]]"));
		} else {
			var wikiLink = codeComment.slice(codeComment.indexOf("[[") +2, codeComment.indexOf("]]"));
		}
		var replaceWikiLink = codeComment.slice(codeComment.indexOf("[["), codeComment.indexOf("]]") +2);
		codeComment = codeComment.substr(codeComment.indexOf("]]") +2);
		if(wikiLink.search("Special:") === -1){
			extraLinks =  " <small style=\"font-style: normal;\">( <a href=\"" + mw.config.get("wgServer") + "/edit/" + wikiLink + "\" title=\"Please use [show preview] before saving.\">edit</a> | <a href=\"" + mw.config.get("wgServer") + mw.config.get("wgArticlePath").replace("$1", "Special:WhatLinksHere/" + wikiLink) + "\" title=\"A list of all wiki pages that link here.\">wlh</a> )</small>";
		}
		$(this).html($(this).html().replace(replaceWikiLink, "<b>[[</b><a href=\"" + mw.config.get("wgServer") + mw.config.get("wgArticlePath").replace('$1', wikiLink) + "\" title=\"" + wikiLink + "\">" + wikiLink + "</a><b>" + wikiLinkPipe + "]]</b>" + extraLinks));
		wikiLinkPipe = "";
		extraLinks =  "";
	}
});