User:Animum/moveRV-movefunc.js

//This is only here so I don't have to update two individual scripts that use it, moveRV.js and moveRV-severe.js

function revertmoves { //A _HEAVILY_ modified version of Voice of All's move-reversion script. document.getElementById("contentSub").innerHTML += " Working... (this may take a while)"; var l = document.getElementById('bodyContent').getElementsByTagName('li'); var NEXT_INDEX = 0; var completedMoves = 0; var completedDeletions = 0; for (var i=NEXT_INDEX;i<l.length;i++) { var li_a = l[i].getElementsByTagName('a'); for(k=0;k<li_a.length;k++) { //Here to look good. var article = li_a[(isSysop ? 4 : 3)].href.split("title=")[1].split("&")[0]; var article2 = li_a[(isSysop ? 5 : 4)].href.replace(/.*?(\/wiki\/|\/index\.php\?title\=)/g, "").split("&")[0]; var req = sajax_init_object; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=revisions&titles=" + article + "&rvprop=comment&limit=1", false); req.send(null); var pageInfo = formatResponse(eval("(" + req.responseText + ")")); if(pageInfo.revisions != undefined) { if(pageInfo.revisions[0].comment) { if(pageInfo.revisions[0].comment.indexOf("moved " + article2.replace(/_/g, " ") + " to " + article.replace(/_/g, " ") + "") != -1) { var shouldAbort = true; //Has already been reverted. } else { shouldAbort = false; }               } else { shouldAbort = false; //No comment means no move has been made. }           } else { shouldAbort = false; //If page doesn't exist, we don't want to move it. }           var req = sajax_init_object; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=revisions&titles=" + article2 + "&rvprop=comment&limit=1", false); req.send(null); var pageInfo = formatResponse(eval("(" + req.responseText + ")")); if(pageInfo.revisions == undefined) { shouldAbort = true; //Page to move doesn't exist. }           var req = sajax_init_object; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=info&intoken=move|delete&titles=" + article2, false); req.send(null); var summary = "Script-assisted page-move revert."; var info = formatResponse(eval("(" + req.responseText + ")")); var edittoken = info.movetoken; var deletetoken = info.deletetoken; var postdata = "action=move" + "&from=" + article2 + "&to=" + article + "&reason=" + encodeURIComponent(summary) + "&token=" + encodeURIComponent(edittoken) + "&noredirect"; var req = sajax_init_object; req.open("POST", mw.config.get('wgScriptPath') + "/api.php", false); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", postdata.length); if(shouldAbort == false) { //If nobody else has already reverted, we do                                  req.send(postdata); var dt = new Date; var timestamp = dt.getUTCFullYear + zeroPad(dt.getUTCMonth + 1) + zeroPad(dt.getUTCDate) + zeroPad(dt.getUTCHours) + zeroPad(dt.getUTCMinutes) + zeroPad(dt.getUTCSeconds); var div = document.createElement("div"); div.id = "completedMoveCount"; document.getElementById("contentSub").appendChild(div); var req = sajax_init_object; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&list=logevents&letype=move&leuser=" + mw.config.get('wgUserName') + "&letitle=" + unescape(article2) + "&lelimit=1&ledir=newer&lestart=" + timestamp, false); req.send(null); var text = eval("(" + req.responseText + ")").query.logevents; if(text[0]) { text = text[0]; if(text.user == mw.config.get('wgUserName') && text.comment.indexOf(summary) != -1) { if(isSysop) { var delsummary = "Automated deletion of redirects created from the reversion of moves (in some cases, this could be covered by criterion G3)"; var postdata = "title=" + article2 + "&reason=" + encodeURIComponent(delsummary) + "&token=" + encodeURIComponent(deletetoken); var req = sajax_init_object; req.open("POST", mw.config.get('wgScriptPath') + "/api.php", false); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", postdata.length); req.send(postdata); }                       completedMoves = completedMoves+1; document.getElementById("completedMoveCount").innerHTML = "'''" + completedMoves + (completedMoves == 1 ? " move " + (isSysop ? "and deletion has" : "has") : " moves " + (isSysop ? "and deletions have" : "have")) + " been completed.'''"; }               }            }            NEXT_INDEX = NEXT_INDEX+1; break; }   }    document.getElementById("contentSub").getElementsByTagName("span")[0].style.textDecoration = "none"; document.getElementById("contentSub").innerHTML += " Cleanup finished."; //Done. }