User:Iceblock/wlh.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Iceblock/wlh. |
// This script creates a list of pages that redirects to the current page. The list is put at the top of every visited page. The maximum is 50 redirects. If there 50 or more redirects, a link to Special:WhatLinksHere is provided.
// Made by [[User:Iceblock]]
function wlh()
{
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
var req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
req.open("GET", wgServer + wgScriptPath+"/api.php?action=query&list=backlinks&bltitle="+encodeURIComponent(mw.config.get('wgPageName'))+"&bllimit=50&blfilterredir=redirects&format=xml", false);
req.send("");
var response = req.responseXML;
var wlhdiv = document.createElement("div");
var tableNode = document.createElement("table");
tableNode.style.borderColor="#888";
tableNode.style.borderWidth="1px";
tableNode.style.borderStyle="solid";
tableNode.style.width="100%";
document.getElementById("bodyContent").insertBefore(wlhdiv, document.getElementById("jump-to-nav"));
for (x = 0; x < response.getElementsByTagName("bl").length; x++) {
if (x % 8 == 0) var trNode = document.createElement("tr");
var tdNode = document.createElement("td");
var textNode = document.createTextNode(response.getElementsByTagName("bl")[x].getAttribute("title"));
var aNode = document.createElement("a");
aNode.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(response.getElementsByTagName("bl")[x].getAttribute("title"))+"&redirect=no";
aNode.appendChild(textNode);
tdNode.appendChild(aNode);
trNode.appendChild(tdNode);
tableNode.appendChild(trNode);
}
if (response.getElementsByTagName("bl").length == 0) {
var trNode = document.createElement("tr");
var tdNode = document.createElement("td");
var textNode = document.createTextNode("No redirects found.");
tdNode.appendChild(textNode);
trNode.appendChild(tdNode);
tableNode.appendChild(trNode);
}
wlhdiv.appendChild(document.createTextNode("These pages redirect to the current page: "));
if (response.getElementsByTagName("bl").length >= 50) {
var aNode = document.createElement("a");
aNode.href=wgServer + wgScript+"?title=Special%3AWhatLinksHere&hidetrans=1&hidelinks=1&target="+encodeURIComponent(mw.config.get('wgPageName'));
aNode.appendChild(document.createTextNode("List all"));
wlhdiv.appendChild(aNode);
}
wlhdiv.appendChild(tableNode);
}
}
$ ( wlh );