User:Frietjes/lclist.js

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

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(/(?:\/(?:sandbox|testcases|doc))$/g) < 0) { var r = new RegExp(title,'i'); if(info.title.search(r) < 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 doListTemplates { document.getElementById("wpListTemplatesSubmit").disabled = true; var k = 0; var loopflag = true; var ckey; var pagelist = []; var templates = document.getElementById("wpListTemplatesTemplates").value.split("\n"); if(templates.length > 0) { if(templates[0].search(/[^\s]/g) < 0) { templates.shift; }	}	for(i=0; i< templates.length; i++) { while(loopflag) { k = k + 1; var req = new XMLHttpRequest; var cstr = ""; if(k > 1) { cstr = "&eicontinue=" + ckey; }		templates[i] = templates[i].replace(/^[\t _]+/g, ''); templates[i] = templates[i].replace(/^[\t _]$/g, ''); templates[i] = templates[i].replace(/[\t ]/g, '_'); req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json" +			"&action=query&continue=" + cstr + 			"&list=embeddedin&eilimit=500&einamespace=10&eititle="+encodeURIComponent(templates[i]), false); req.send; var response = JSON.parse(req.responseText).query.embeddedin; for(var index in response) { var info = response[index]; if(info.title.search(/(?:\/(?:sandbox|testcases|doc))$/g) < 0) { var r = new RegExp(templates[i],'i'); if(info.title.search(templates[i]) < 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("wpListTemplatesSubmit").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("wpTemplatesList").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("wpListTemplatesSubmit").value = "(" + (i+1) + " / " + pagelist.length + ")"; }	}	pagelist.sort(function (a, b) {return a.toLowerCase.localeCompare(b.toLowerCase);});

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

function listTemplatesform { 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 templates"; document.title = "List 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.' + ' ' + 'Templates to check (one on each line, with namespace prefix): '		+ ' ' + ' Compute transclusion counts (slow) ' + '' + ' '		+ ' '; } if(mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgPageName') === "Special:TemplateList" || mw.config.get('wgPageName') === "Special:TemplatesList") ) { $.when( $.ready, mw.loader.using(['mediawiki.util'])).done( listTemplatesform ); }