User:PiRSquared17/Rollback.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:PiRSquared17/Rollback. |
// 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 --> [[User:username|username]] - (linked)
// -Also: $talk --> [[User talk:username|talk]] - (linked)
// -Also: $contribs --> [[Special:Contributions/username|contributions]] - (linked)
// -Also: $ip --> [[Special:Contributions/username|username]] - (linked). Used especially for IPs with no userpage.
// -Also: $rvuser --> [[User:User to revert to|user to revert to]] - (linked).
// -Also: $rvip --> [[Special:Contributions/user to revert to|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, "[[User:$2|$2]]");
var worksum1 = startsum.replace(/\$ip/g, "[[Special:Contributions/$2|$2]]");
var worksum2 = worksum1.replace(/\$rvuser/g, "[[User:$1|$1]]");
var worksum3 = worksum2.replace(/\$rvip/g, "[[Special:Contributions/$1|$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, "[[Special:Contributions/" + user + "|contributions]]");
finsum = "&summary=" + encodeURIComponent(finsum.replace(/\$talk/g, "[[User talk:$2|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 --> [[User:username|username]] - (linked)
// -Also: $talk --> [[User talk:username|talk]] - (linked)
// -Also: $contribs --> [[Special:Contributions/username|contributions]] - (linked)
// -Also: $ip --> [[Special:Contributions/username|username]] - (linked). Used especially for IPs with no userpage.
// -Also: $rvuser --> [[User:User to revert to|user to revert to]] - (linked).
// -Also: $rvip --> [[Special:Contributions/user to revert to|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:" + user + "|" + user + "]]");
var worksum1 = startsum.replace(/\$ip/g, "[[Special:Contributions/" + user + "|" + user + "]]");
var worksum2 = worksum1.replace(/\$rvuser/g, "[[User:$1|$1]]");
var worksum3 = worksum2.replace(/\$rvip/g, "[[Special:Contributions/$1|$1]]");
var finsum = worksum3.replace(/\$contribs/g, "[[Special:Contributions/" + user + "|contributions]]");
this.href += "&summary=" + encodeURIComponent(finsum.replace(/\$talk/g, "[[User talk:" + user + "|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