Jump to content

User:Frietjes/sortcat.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Frietjes (talk | contribs) at 15:13, 1 May 2017. The present address (URL) is a permanent link to this version.
(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.
/// Sort cat
jQuery(document).ready(function($) {
// -------------------------------------------------------------------------------- //

if(mw.config.get('wgNamespaceNumber') != -1 ) {
mw.loader.using(['mediawiki.util']).done( function() {
  var portletlink = mw.util.addPortletLink('p-tb', '#', 'Sort cat', 't-sortcat');
  $(portletlink).click(function(e) {
    e.preventDefault();
    getNonArticles(0);
  });
});
}

function getNonArticles() {
 	var loopflag = true;
	var ckey;
	var plist = "";
	var k = 0;
	var ns = "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|100|101|108" +
    		 "|109|118|119|446|447|710|711|828|829|2300|2301|2302|2303|2600";
    var cat = "Category:Pages using infobox river with deprecated parameters";
	cat = prompt("Category",cat);
	cat = cat.replace(/ /g, '_');
	while(loopflag) {
    	k = k + 1;
    	var req = new XMLHttpRequest();
    	var cstr = "";
    	if(k > 1) {
    		cstr = "&cmcontinue=" + ckey; 
    	}
    	req.open("GET", wgScriptPath + "/api.php?format=json" +
    		"&action=query&continue=" + cstr + 
    		"&list=categorymembers&cmlimit=500&cmtitle=" + cat +
    		"&cmnamespace=0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|100|101|108" +
    		"|109|118|119|446|447|710|711|828|829|2300|2301|2302|2303|2600", false);
    	req.send(null);
    	var response = eval("(" + req.responseText + ")").query.categorymembers;
    	for(var index in response) {
    		var info = response[index];
    		plist = info.title + "\n" + plist;
    	}
    	if(eval("(" + req.responseText + ")").continue) {
    		loopflag = true;
    		ckey = eval("(" + req.responseText + ")").continue.cmcontinue;
    	} else {
    		loopflag = false;
    	}
	}
	var parray = plist.split('\n');
	parray.sort();
	alert(parray.join('\n'));
}
// -------------------------------------------------------------------------------- //

});