User:Animum/moveRV-severe.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:Animum/moveRV-severe. |
importScript('User:Animum/urlparameters.js');
importScript('User:Animum/formatresponse.js');
importScript('User:Animum/moveRV-movefunc.js');
function zeroPad(str) {
return ("0" + str).slice(-2);
}
var isSysop = /sysop/.test(wgUserGroups);
function isBlocked(name) {
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&list=blocks&bkusers=" + name + "&format=json", false);
req.send(null);
var info = eval("(" + req.responseText + ")");
return (info.query.blocks[0] ? true : false);
}
function blockip(name) {
// Safeguards against errors
if(isBlocked(name)) {
document.getElementById("contentSub").innerHTML += "<br /><br /><b>Error: " + name + " is already blocked. Defaulting to protection...</b>";
protect("User talk:" + name);
return;
}
if(name == "undefined") {
document.getElementById("contentSub").innerHTML += "<br /><br /><b>Error: No valid username was given; please block manually.";
return;
}
//If none of these safeguards have been triggered, continue.
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/index.php?title=Special:BlockIP/" + name, false);
req.send(null);
document.getElementById("contentSub").innerHTML += "<br /><br />";
var edittoken = req.responseText.split('<input name="wpEditToken" type="hidden" value="')[1].split('" />')[0];
var postdata = "wpBlockAddress=" + encodeURIComponent(name)
+ "&wpBlockOther=indefinite"
+ "&wpBlockReason=" + encodeURIComponent("Page-move vandalism")
+ "&wpBlockReasonList=other"
+ "&wpEmailBan=0"
+ "&wpCreateAccount=1"
+ "&wpEnableAutoblock=1"
+ "&wpAllowUsertalk=0"
+ "&wpEditToken=" + encodeURIComponent(edittoken)
+ "&wpBlock=block";
var req = sajax_init_object();
req.open("POST", wgScriptPath + "/index.php?title=Special:BlockIP&action=submit", false);
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
req.setRequestHeader('Content-length', postdata.length);
req.send(postdata);
if(isBlocked(name)) { //Make sure we really are done.
document.getElementById("contentSub").innerHTML += "<b>" + name + " has been blocked.</b>";
revertmoves();
}
}
function beginRectification() {
var doContinue = confirm("This script will block " + unescape(UrlParameters["user"].replace(/[+_]/g, " ")) + ", protect his/her talk page, revert ALL of his/her moves, and delete the redirects created therefrom.\n\nClick \"OK\" to continue, or \"Cancel\" to abort.");
if(doContinue) {
blockip(unescape(UrlParameters["user"]).replace(/[+_]/g, " "));
} else {
alert("Aborted.");
}
}
addOnloadHook(function() {
if(wgNamespaceNumber == -1 && wgCanonicalSpecialPageName == "Log" && (UrlParameters["type"] == "move" || location.href.substring(location.href.indexOf("title=") + 6).split("/")[1] == "move" || location.href.substring(location.href.indexOf("/wiki/") + 6).split("?")[0].split("/")[1] == "move") && (UrlParameters["user"] || location.href.substring(location.href.indexOf("user=") + 5))) {
mw.util.addPortletLink("p-cactions", "javascript:beginRectification()", "pagemove-severe", "ca-pagemoveSevere");
}
});