User:PiRSquared17/Rollback.js

// the following scripts are from simple:User:PiRSquared17/MRBK.js and simple:User:Tholly/Rollback.js, respectively

//Mass rollback function //Written by John254 //Adapted from User:Mr.Z-man/rollbackSummary.js //Instructions: Selecting the "rollback all" tab when viewing a user's contributions history //will open all rollback links displayed there. (Use with caution) // //EdSum copied from User:Tholly/Rollback.js // // **The script below is an adaption of one from w:User:Gracenotes/rollback.js** //          **Please read that page for more details on the script.** // // The Differences: // -Instead of just being able to:  $user --> username // -Now there is:  $user --> username - (linked) // -Also: $talk     --> talk - (linked) // -Also: $contribs --> contributions - (linked) // -Also: $ip       --> username - (linked). Used especially for IPs with no userpage. // -Also: $rvuser   --> user to revert to - (linked). // -Also: $rvip     --> user to revert to - (linked). Used for IPs with no userpage. // // -Another change is that there is already text in the summary box, defaulting to: //  "Reverted edits by $ip ($talk) to last version by $rvuser." // -Finally, the link to click on next to rollback is "summary", not "sum" //  and there are spaces between "rollback", "|" and "summary" to match other formatting. // // // Added by PiRSquared17: // -If you want to open the user's talk page, put "$opentalk" at the end of the input box if (typeof(skin)!="undefined" && skin=="vector") (function {     var GET = document.getElementById;      document.getElementById = function(id) {          var g = GET.call(document, id);          if (g) {              return g;          } else {              return GET.call(document, { 'p-cactions': 'actions', 'p-personal': 'personal', 'p-search': 'p-navigation', // redirected to this for positioning, or to #search? 'p-logo': 'logo', 'column-one': 'panel', 'column-content': 'content', // since #content exists, is this ok? 'globalWrapper': 'content', // what should this be? 'lastmod': 'foot-info-lastmod' }[id]);         }      };  }); function _confirmRollback { var url = document.location.href; var user = url.match(/Special:Contributions\/([^&]*)/); if (!user || user == wgUserName) {       alert("error"); return; }   user = decodeURIComponent(user[1]);

var summary = prompt("Enter a summary to use for rollback. Leave blank to use the default.\n\n- '$user' will be replaced with the link to " + user + "'s userpage,\n- '$talk' to their talk page,\n- '$contribs' to their contributions page, and\n- '$ip' to their contributions page with the link text as '" + user + "'.\n\n- $rvuser links to userpage of user reverting back to, and \n- $rvip to the contribs page of user reverting back to (link text of username).", "Reverted edits by $ip ($talk) to last version by $rvuser (Mass reversion of changes by $ip)."); if (summary == undefined) { return false; }   else if (summary == "") { return true; }   var startsum = summary.replace(/\$user/g, "$2"); var worksum1 = startsum.replace(/\$ip/g, "$2"); var worksum2 = worksum1.replace(/\$rvuser/g, "$1"); var worksum3 = worksum2.replace(/\$rvip/g, "$1"); var worksum4 = worksum3.replace(/\$opentalk/g, ""); if (worksum3 != worksum4) { open(wgServer + (wgArticlePath.replace(/\$1/g, "")) + "User talk:" + user); }   var finsum = worksum4.replace(/\$contribs/g, "contributions"); finsum = "&summary=" + encodeURIComponent(finsum.replace(/\$talk/g, "talk")); return finsum; } function rollbackEverythingButton { var hasRollback = getElementsByClassName(document, "span", "mw-rollback-link"); if (hasRollback[0] && (document.title.indexOf("User contributions") != -1) ) { mw.util.addPortletLink('p-cactions', 'javascript:rollbackEverything', "rollback all", "ca-rollbackeverything", "rollback all edits displayed here"); if (typeof noMRBKL == "undefined" || !noMRBKL) { addRemoteRollbackLinks; } } } var qapi = sajax_init_object;  // will use later qapi.open('GET', wgServer + (wgArticlePath.replace(/\$1/g, 'wgPageName')), true); qapi.onreadystatechange = __getXML; qapi.overrideMimeType('text/xml'); qapi.send; // handle response function __getXML(_api) { if(_api.readyState==4) { if(_api.status==200) { return _api.responseXML; } else { alert('The query returned an error.'); }	} } function addRemoteRollbackLinks { var usertools = document.getElementsByClassName("mw-usertoollinks"); for (var i = 0; i < usertools.length; i++) {   var usertalk = usertools[i].getElementsByTagName("a")[0]; if (usertools[i].getElementsByTagName("a").length > 1) var contribs = usertools[i].getElementsByTagName("a")[1]; else var contribs = usertools[i].getElementsByTagName("a")[0]; var rollbackall = document.createElement("a"); rollbackall.setAttribute("href", encodeURI(wgScript + "?title=Special:Contributions/" + (document.getElementsByClassName("mw-usertoollinks")[i].getElementsByTagName("a")[0].href.match(/User_talk:([^&]*)/)[1]) + "&rollbackall=true")); var txtToAdd0 = document.createTextNode(" | "); var txtToAdd1 = document.createTextNode("rollback all"); rollbackall.appendChild(txtToAdd1); contribs.parentNode.insertBefore(txtToAdd0, contribs.nextSibling); txtToAdd0.parentNode.insertBefore(rollbackall, txtToAdd0.nextSibling); } } $(rollbackEverythingButton); $( function {	if( document.location.href.indexOf( 'rollbackall=true' ) != -1 ) {		rollbackEverything;		return;	} }); function rollbackEverything { var edsum = _confirmRollback; if (typeof edsum != "string") { return 0; }   for (var i in document.links) { if (document.links[i].href.indexOf('action=rollback') != -1) { window.open(document.links[i].href + edsum); }   } }

// end script 1

//

// **The script below is an adaption of one from w:User:Gracenotes/rollback.js**

//          **Please read that page for more details on the script.**

//

// The Differences:

// -Instead of just being able to:  $user --> username

// -Now there is:  $user --> username - (linked)

// -Also: $talk     --> talk - (linked)

// -Also: $contribs --> contributions - (linked)

// -Also: $ip       --> username - (linked). Used especially for IPs with no userpage.

// -Also: $rvuser   --> user to revert to - (linked).

// -Also: $rvip     --> user to revert to - (linked). Used for IPs with no userpage.

//

// -Another change is that there is already text in the summary box, defaulting to:

//  "Reverted edits by $ip ($talk) to last version by $rvuser."

// -Finally, the link to click on next to rollback is "summary", not "sum"

//  and there are spaces between "rollback", "|" and "summary" to match other formatting.

//

function addSumLink {

var ntitle2 = document.getElementById("mw-diff-ntitle2")

if (!ntitle2) return;

var rbnode = getElementsByClassName(document.getElementById("mw-diff-ntitle2"), "span", "mw-rollback-link");

if (rbnode.length != 0)

addRollbackSummaryLink(rbnode[0]);

}

function confirmRollback {

var url = this.href;

var user = url.match(/[?&]from=([^&]*)/);

if (!user) return;

var user = decodeURIComponent(user[1].replace("+", " "));

var summary = prompt("Enter a summary to use for rollback. Leave blank to use the default.\n\n- '$user' will be replaced with the link to " + user + "'s userpage,\n- '$talk' to their talk page,\n- '$contribs' to their contributions page, and\n- '$ip' to their contributions page with the link text as '" + user + "'.\n\n- $rvuser links to userpage of user reverting back to, and \n- $rvip to the contribs page of user reverting back to (link text of username).", "Reverted edits by $ip ($talk) to last version by $rvuser.")

if (summary == undefined)

return false;

else if (summary == "")

return true;

var startsum = summary.replace(/\$user/g, "" + user + "");

var worksum1 = startsum.replace(/\$ip/g, "" + user + "");

var worksum2 = worksum1.replace(/\$rvuser/g, "$1");

var worksum3 = worksum2.replace(/\$rvip/g, "$1");

var finsum = worksum3.replace(/\$contribs/g, "contributions");

this.href += "&summary=" + encodeURIComponent(finsum.replace(/\$talk/g, "talk"));

return true;

};

function addRollbackSummaryLink(rbnode) {

var rblink = rbnode.getElementsByTagName("a")[0]

var alink = rblink.cloneNode(true);

alink.className = "";

alink.firstChild.nodeValue = "summary";

alink.onclick = confirmRollback;

rbnode.insertBefore(alink, rblink.nextSibling);

rbnode.insertBefore(document.createTextNode(" | "), alink);

}

$(addSumLink);

// End of script