User:Frietjes/lmlist.js

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

function getLocationMapText(title){ // This function was taken from User:Timotheus Canens/massedit.js var req = new XMLHttpRequest; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&prop=revisions&rvprop=content&format=json&indexpageids=1&titles="+encodeURIComponent(title), false); req.send; var response = JSON.parse(req.responseText); pageid = response.query.pageids[0]; if (pageid == "-1") { return ''; }	var pagetext = response.query.pages[pageid].revisions[0]['*']; return pagetext; }

function doListLocationMaps { document.getElementById("wpListLocationMapsSubmit").disabled = true;

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 = "&apcontinue=" + ckey; }		req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json" +			"&action=query&continue=" + cstr + 			"&list=allpages&aplimit=500&apnamespace=828&apprefix=" + 			encodeURIComponent('Location map/data/'), false); req.send; var response = JSON.parse(req.responseText).query.allpages; for(var index in response) { var info = response[index]; if(info.title.search(/\/(?:sandbox|testcases|doc)$/g) < 0) { articlelist.push(info.title); }		}		if(JSON.parse(req.responseText).continue) { loopflag = true; ckey = JSON.parse(req.responseText).continue.apcontinue; } else { loopflag = false; }	}	articlelist.sort; articlelist = articlelist.filter( function( item, index, inputArray ) {		return inputArray.indexOf(item) == index;	});

for (var i=0; i<articlelist.length; i++) { var article = articlelist[i]; var articleshort = article.replace(/^Module:Location map\/data\//g, ''); articlelist[i] = ':' + articleshort + ''; }	document.getElementById("wpLocationMapList").innerHTML = articlelist.join(' '); if(document.getElementById("wpListLocationMapsRedirects").checked) { for(i=0; i< articlelist.length; i++) { document.getElementById("wpListLocationMapsSubmit").value = "(" + (i+1) + " / " + (articlelist.length) + ")"; var modulename = articlelist[i].replace(/:\[\[([^\[\]\|]*)\|[^\[\]\|]*\]\]/, '$1'); var mytxt = getLocationMapText(modulename); if (mytxt.search(/return[\t ]+require[\t ]*\(['"\t ]+(Module:Location[_ ]+map\/data\/[^'"]*)['" ]+\)/gi) >= 0) {				var article = mytxt.match(/return[\t ]+require[\t ]*\(['"\t ]+(Module:Location[_ ]+map\/data\/[^'"]*)['" ]+\)/gi)[0]; article = article.replace(/return[\t ]+require[\t ]*\(['"\t ]+(Module:Location[_ ]+map\/data\/[^'"]*)['" ]+\)/gi, '$1');				var articleshort = article.replace(/^Module:Location map\/data\//g, );				articlelist[i] = ':' + articleshort + ' ← ' + articlelist[i].replace(/^:/, );			}		}	}	articlelist.sort(function (a, b) {return a.toLowerCase.localeCompare(b.toLowerCase);});

document.getElementById("wpLocationMapList").innerHTML = articlelist.join(' '); }

function listlocationmapsform { 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 Location Maps"; document.title = "List Location Maps - Wikipedia, the free encyclopedia"; document.getElementById(bodyContent).innerHTML = 'From Wikipedia, the free encyclopedia

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