Jump to content

User:Writ Keeper/Scripts/massRollback.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Writ Keeper (talk | contribs) at 04:42, 11 May 2016 (adding custom edit summary). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//Mass rollback function
//Written by John254 and modified/rewritten by Writ Keeper; original is at https://en.wikipedia.org/wiki/User:John254/mass_rollback.js
//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)
  
function rollbackEverythingWKMR(editSummary) 
{
	if(editSummary == null)
	{
		return false;
	}
	var userName = /Contributions\/(.+)/.exec(mw.config.get("wgTitle"))[1];
	var tokenRegex = /token=([^&]+)/;
	var titleRegex = /title=([^&]+)/;
	$("a[href*='action=rollback']").each(function(ind, el)
	{
		var regexResults = tokenRegex.exec(el.href);
		rollbackToken = decodeURIComponent(regexResults[1]);
		
		var postInfo = {action:"rollback",title:titleRegex.exec(el.href)[1],token:rollbackToken,user:userName};
		if(editSummary != "")
		{
			postInfo.summary = editSummary;
		}
		$.post("/w/api.php", postInfo, function()
		{
			$(el).after("reverted");
			$(el).remove();
		});
	});
	return false;
}
$(document).ready(function()
{
	if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions" && $("span.mw-rollback-link").length > 0)
	{
		addPortletLink('p-cactions', '#', "rollback all", "ca-rollbackeverything", "rollback all edits displayed here");
		$("#ca-rollbackeverything").click(rollbackEverythingWKMR(dialog("Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)")));
	}
});