User:Frietjes/etlist.js

/// Query Old Transclusions /// Adapted from User:Timotheus_Canens/massedit.js /// Once installed, go to Special:ElectionTables

function istfdlisted(title){ var k = 0; var loopflag = true; var ckey; while(loopflag) { k = k + 1; var req = new XMLHttpRequest; var cstr = ""; if(k > 1) { cstr = "&eicontinue=" + ckey; }		req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json" +			"&action=query&continue=" + cstr + 			"&list=embeddedin&eilimit=500&einamespace=2&eititle="+encodeURIComponent(title), false); req.send; var response = JSON.parse(req.responseText).query.embeddedin; for(var index in response) { var info = response[index]; if(info.title.search(/noinclude[_ ]+list$/g) >=0) { return true; }		}		if(JSON.parse(req.responseText).continue) { loopflag = true; ckey = JSON.parse(req.responseText).continue.eicontinue; } else { loopflag = false; }	}

return false; }

function gettransclusioncounts(title){ var k = 0; var loopflag = true; var ckey; var articlelist = []; while(loopflag) { k = k + 1; var req = new XMLHttpRequest; var cstr = ""; if(k > 1) { cstr = "&eicontinue=" + ckey; }		req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json" +			"&action=query&continue=" + cstr + 			"&list=embeddedin&eilimit=500&einamespace=0&eititle="+encodeURIComponent(title), false); req.send; var response = JSON.parse(req.responseText).query.embeddedin; for(var index in response) { var info = response[index]; if(info.title.search(/(?:[Tt]emplate:[Ee]nd|[Tt]emplate:[Ee]lection[ _]table|\/(?:sandbox|testcases|doc))$/g) < 0) { articlelist.push(info.title); }		}		if(JSON.parse(req.responseText).continue) { loopflag = true; ckey = JSON.parse(req.responseText).continue.eicontinue; } else { loopflag = false; }	}	articlelist.sort; articlelist = articlelist.filter( function( item, index, inputArray ) {		return inputArray.indexOf(item) == index;	});

return articlelist.length; }

function doListElectionTables { document.getElementById("wpListElectionTablesSubmit").disabled = true; var k = 0; var loopflag = true; var ckey; var pagelist = []; while(loopflag) { k = k + 1; var req = new XMLHttpRequest; var cstr = ""; if(k > 1) { cstr = "&eicontinue=" + ckey; }		req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json" +			"&action=query&continue=" + cstr + 			"&list=embeddedin&eilimit=500&einamespace=10&eititle=Template:Election_table", false); req.send; var response = JSON.parse(req.responseText).query.embeddedin; for(var index in response) { var info = response[index]; if(info.title.search(/(?:[Tt]emplate:[Ee]nd|[Tt]emplate:[Ee]lection[ _]table|\/(?:sandbox|testcases|doc))$/g) < 0) { pagelist.push(info.title); }		}		if(JSON.parse(req.responseText).continue) { loopflag = true; ckey = JSON.parse(req.responseText).continue.eicontinue; } else { loopflag = false; }		document.getElementById("wpListElectionTablesSubmit").value = "(" + pagelist.length + ")"; }	pagelist.sort; pagelist = pagelist.filter( function( item, index, inputArray ) {		return inputArray.indexOf(item) == index;	});

for (var i=0; i<pagelist.length; i++) { pagelist[i] = ':' + pagelist[i] + ''; }	document.getElementById("wpElectionTablesList").innerHTML = pagelist.join(' '); if(document.getElementById("wpListTransclusionCounts").checked) { for(i=0; i< pagelist.length; i++) { var templatename = pagelist[i].replace(/:\[\[([^\[\]\|]*)\]\]/, '$1'); var tcount = gettransclusioncounts(templatename); var tfdlisted = false; if (tcount < 1) { tfdlisted = istfdlisted(templatename); }			if (tcount < 10) { if (tfdlisted === true) { pagelist[i] = ':TFD ' + templatename + ' '; } else { pagelist[i] = ':0' + tcount + ' ' + templatename + ''; }			} else { pagelist[i] = ':' + tcount + ' ' + templatename + ''; }			document.getElementById("wpListElectionTablesSubmit").value = "(" + (i+1) + " / " + pagelist.length + ")"; }	}	pagelist.sort(function (a, b) {return a.toLowerCase.localeCompare(b.toLowerCase);});

document.getElementById("wpElectionTablesList").innerHTML = pagelist.join(' '); }

function listElectionTablesform { var bodyContent = 'bodyContent'; switch (mw.config.get('skin')) { case 'modern': bodyContent = 'mw_contentholder'; break; case 'cologneblue': bodyContent = 'article'; break; case 'vector': case 'monobook': case 'vector': default: bodyContent = 'bodyContent'; break; }	document.getElementsByTagName("h1")[0].textContent = "List election table templates"; document.title = "List election table templates - Wikipedia, the free encyclopedia"; document.getElementById(bodyContent).innerHTML = 'From Wikipedia, the free encyclopedia

'		+ '' + 'If you abuse this tool, it\'s your fault, not mine.' + ' ' + ' Compute transclusion counts (slow) ' + '' + ' '		+ ' '; } if(mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgPageName') === "Special:ElectionTables" || mw.config.get('wgPageName') === "Special:ElectionTablesList") ) { $.when( $.ready, mw.loader.using(['mediawiki.util'])).done( listElectionTablesform ); }