User:Prodego/moverevert.js

var wgPageName = mw.config.get('wgPageName'); if (mw.config.get('wgPageName') == "Special:Log") {

function addmoveRevertTab { mw.util.addPortletLink('p-cactions', 'javascript:moverevert2_main', "Revert moves", "ca-moverevert", "Revert"); } $(addmoveRevertTab);

function moverevert2_main { jsMsg(' '); if (wgPageName == "Special:Log" && document.URL.indexOf('&page=') != -1) { var user = document.URL.substring(document.URL.indexOf('&user=')+6,document.URL.indexOf('&page=')); } else if (wgPageName == "Special:Log"){ var user = document.URL.substring(document.URL.indexOf('&user=')+6); } else { var user = encodeURIComponent(wgTitle); } btoken = gwp_getBlockToken(user); if(user != "Prodego") { gwp_blockUser(user, btoken); } token = gwp_getToken; moves = gwp_getMoveLog(user); for (var i=0; iDone'; }

function gwp_getToken { document.getElementById('movervinfo').innerHTML += 'Getting token'; var req = sajax_init_object; req.open("GET", wgScriptPath + "/api.php?action=query&prop=info&indexpageids=1&intoken=edit&format=json&titles=Foo", false); req.send(null); var response = eval('(' + req.responseText + ')'); pageid = response['query']['pageids'][0]; token = response['query']['pages'][pageid]['edittoken']; delete req; document.getElementById('Gwp_gettoken').innerHTML = 'Got token'; return token; } function gwp_getMoveLog(user) { document.getElementById('movervinfo').innerHTML += 'Getting moves from user ' + user +''; var url = wgScriptPath + "/api.php?action=query&list=logevents&leuser="+user+"&letype=move&lelimit=50&leprop=title|details&format=json" var req = sajax_init_object; req.open("GET", url, false); req.send(null); var response = eval('(' + req.responseText + ')'); var moves = new Array; for (var i=0; iMoving '+movefrom+' to '+moveto+''; var req = sajax_init_object; var params = "action=move&from="+encodeURIComponent(movefrom)+"&to="+encodeURIComponent(moveto)+"&token="+encodeURIComponent(token)+"&reason=Pagemove%20vandalism%20cleanup&noredirect=1&format=json"; url = wgScriptPath + "/api.php"; req.open("POST", url, false); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); req.onreadystatechange = function { if(req.readyState == 4 && req.status == 200) { response = eval('(' + req.responseText + ')'); try { if (response['move']['to']) { document.getElementById('Gwp_move'+escape(movefrom)).innerHTML = 'Moved '+movefrom+' to '+moveto; }     } catch(err) { document.getElementById('Gwp_move'+escape(movefrom)).innerHTML = 'Move from '+movefrom+' to '+moveto+' failed. Error info:' +response['error']['code'] + ' : ' + response['error']['info']; }   }  }  req.send(params) } function gwp_getBlockToken(user) { document.getElementById('movervinfo').innerHTML += 'Getting block token'; var req = sajax_init_object; var params = "action=block&user=" + encodeURIComponent(user) + "&gettoken=1&format=json"; req.open("POST", wgScriptPath + "/api.php?", false); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); req.send(params); response = eval('(' + req.responseText + ')'); token = response['block']['blocktoken']; delete req; document.getElementById('Gwp_btoken').innerHTML = 'Got block token'; return token; }

function gwp_blockUser(user, token) { document.getElementById('movervinfo').innerHTML+= "Blocking " + user + ""; var req = sajax_init_object; var params = "action=block&format=json&token="+encodeURIComponent(token)+"&user="+user+"&expiry=never&reason=abuse&nocreate=1&autoblock=1&noemail=1"; url = wgScriptPath + "/api.php"; req.open("POST", url, true); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); req.onreadystatechange = function { if(req.readyState == 4 && req.status == 200) { response = eval('(' + req.responseText + ')'); try { document.getElementById('blocking').innerHTML+= response['block']['user']+" has been blocked"; } catch(err) { document.getElementById('blocking').innerHTML+= " - Error " + response['error']['info']; }     delete req; } }  req.send(params) } }