MediaWiki talk:Common.js

How
How do you use ImportScript and ImportStyleSheet? 14:00, 6 February 2009 (EST)

Removed
14:28, 6 July 2017 (UTC)

Random CP Page
/* Random CP page User:Nx 01:24, 9 April 2009 (EDT)

//Toggle indentation randomcpindent = false;

function randomCP { if (n_randompage = document.getElementById('n-randompage')) { if (wgNamespaceNumber == 100 || wgNamespaceNumber == 101) { n_randomcp = document.createElement('li'); n_randomcp.id = "n-randomcp"; n_randomcp.innerHTML = "Random CP page'; if (randomcpindent) { n_randomcpul = document.createElement('ul'); n_randomcpul.appendChild(n_randomcp); n_randomcp = n_randomcpul; }     n_randompage.parentNode.insertBefore(n_randomcp,n_randompage.nextSibling); } } }

$(document).ready(randomCP) 14:28, 6 July 2017 (UTC)

Random block reasons
/* Inserts random block reasons from RationalWiki:Random_Block_Reasons and per-user block reasons from user's CustomBlockReasons subpage function insertAdditionalBlockReasons { var blockReasonList = document.getElementById("wpBlockReasonList"); if (null != blockReasonList) {

// attempt to get a XmlHTTPRequest object var req = false; if (window.XMLHttpRequest) { // for sane browsers req = new XMLHttpRequest; }		else if (window.ActiveXObject) { // oh dear, here's a nickel kid, get yourself a better browser. req = new ActiveXObject("Microsoft.XMLHTTP"); }		if (req) { var reasonsArray; var reasonOption;

req.open("GET", "http://rationalwiki.org/wiki/index.php?title=RationalWiki:Random_Block_Reasons&action=raw&ctype=text/javascript", false); req.send(null);

if (req.status == 200 && req.responseText != "/* Empty */" ) { // split lines in to an array reasonsArray = req.responseText.split("\n"); reason = reasonsArray[Math.floor(Math.random * reasonsArray.length)]; var randomOptGroup = document.createElement('optgroup'); randomOptGroup.label = "Random block reason"; reasonOption = document.createElement("option"); reasonOption.value = reason; if (typeof(reasonOption.innerText) != "undefined") { reasonOption.innerText = reason; }				else { reasonOption.text = reason; }				randomOptGroup.appendChild(reasonOption); blockReasonList.appendChild(randomOptGroup); }

req.open("GET", "http://rationalwiki.org/wiki/index.php?title=User:" +wgUserName+ "/CustomBlockReasons&action=raw&ctype=text/javascript", false); req.send(null);

if (req.status == 200 && req.responseText != "/* Empty */") { // split lines in to an array reasonsArray = req.responseText.split("\n"); var customOptGroup = document.createElement('optgroup'); customOptGroup.label = "Custom block reasons"; var i;				for (i=0;i<reasonsArray.length;++i) {					reason = reasonsArray[i]; reasonOption = document.createElement("option"); reasonOption.value = reason; if (typeof(reasonOption.innerText) != "undefined") { reasonOption.innerText = reason; }					else { reasonOption.text = reason; }					customOptGroup.appendChild(reasonOption);

}					blockReasonList.appendChild(customOptGroup);

}		}	} }

$(document).ready(insertAdditionalBlockReasons); 14:28, 6 July 2017 (UTC)

Add section bottom (already commented out)
/* addsectionbottom Add a new section link to the bottom of discussion pages

function addsectionbottom { if (!wgIsArticle) return; if ((document.URL.indexOf('?')>=0) && (document.URL.indexOf('action=delete')>=0)) return; var caplus; if (!(caplus = document.getElementById("ca-addsection"))) return; var addsection = document.createElement("span"); addsection.innerHTML = " " + (skin == "vector" ? " Add topic " : " Add section " ) + " " addsection.className = "noprint"; addsection.id = "addsectionbottom"; var content; if (!(content = document.getElementById("bodyContent"))) return; var catlinks = document.getElementById("catlinks"); if (catlinks == null) {   content.appendChild(addsection); } else { content.insertBefore(addsection, catlinks); } }

$(document).ready(addsectionbottom); 14:28, 6 July 2017 (UTC)

"Use of [variable] is deprecated. Use mw.config instead."
See MediaWiki Developer's Handbook/Add JavaScript/Predefined variables:

14:52, 6 July 2017 (UTC)

Lack of anonymous functions
Any particular reason there's so much of rather than ?

Then they could even all be merged into one function, if that were important.—Kazitor, pending 07:14, 27 May 2018 (UTC)