User:Nx/Scripts/Resurrect.js

/* A script that allows instant restoration of pages, bypassing Special:Undelete, but does not allow individually selecting revisions to be restored.

importScript('User:Nx/Scripts/Shared.js');

var resurrecting = false;

function getEditToken { var api = sajax_init_object; var starttime; var edittime; var token; if (!api) { return false; } api.open("GET",wgServer+wgScriptPath+"/api.php" +             "?format=json&action=query&prop=info|revisions&indexpageids=1&intoken=edit&titles=" +            urlencode(wgPageName), false); api.send(null); if (api.status == 200) {   var d = new Date; starttime = d.getUTCFullYear + pad0(d.getUTCMonth+1) + pad0(d.getUTCDate) + pad0(d.getUTCHours) + pad0(d.getUTCMinutes) + pad0(d.getUTCSeconds); var response = eval('(' + api.responseText + ')'); var pagei; if (response['query']['pageids'][0] == "-1") {     //HACK: page does not exist, get edit token from Talk:Main Page. api.open("GET",wgServer+wgScriptPath+"/api.php" +                    "?format=json&action=query&prop=info|revisions&indexpageids=1&intoken=edit&titles=Talk:Main_Page",                    false); api.send(null); response = eval('(' + api.responseText + ')'); edittime = starttime; } else { pagei = response['query']['pages'][response['query']['pageids'][0]]; edittime = remc(pagei['revisions'][0]['timestamp']); }   pagei = response['query']['pages'][response['query']['pageids'][0]]; token = urlencode(pagei['edittoken']); return {"token":token,"starttime":starttime,"edittime":edittime}; } else { return false; } }

function resurrect { if (resurrecting) return; resurrecting = true; var editinfo; if ((editinfo = getEditToken)) {   document.getElementById("bodyContent").innerHTML = " Resurrecting, please wait... "; params = "title=Special:Undelete&restore=1&wpComment=Resurrecting&action=submit&target=" + urlencode(wgPageName) + "&wpEditToken=" + editinfo["token"]; var req = sajax_init_object; req.open("POST",wgServer+wgScriptPath+"/index.php",true); req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); req.setRequestHeader('Connection', 'keep-alive'); req.setRequestHeader('Content-length', params.length); var self = this; req.onreadystatechange = function { if (req.readyState == 4) {       if (req.status == 200) {         var hackdiv = document.createElement("div"); hackdiv.innerHTML = req.responseText; var divs = hackdiv.getElementsByTagName("div"); for (var i=0;i<divs.length;++i) {           if (divs[i].id == "content") {             document.getElementById("content").innerHTML = divs[i].innerHTML; break; }         }          resurrecting = false; } else { document.getElementById("bodyContent").innerHTML = " Error " + req.status + " occurred while restoring the page. "; }     }    }    req.send(params); } }

function resurrect_setup { var ca_undelete = document.getElementById("ca-undelete"); if (ca_undelete) {   var ca_resurrect = document.createElement("li"); ca_resurrect.id = "ca-resurrect"; ca_resurrect.innerHTML = "Resurrect'; ca_undelete.parentNode.insertBefore(ca_resurrect,ca_undelete); } }

addOnloadHook(resurrect_setup);