User:JJPMaster/massRollback.js

From RationalWiki
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
//Mass rollback function
//Written by John254 and modified/rewritten by Writ Keeper with modifications by TheDJ; 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) 
{
	{
		return false;
	}
	var userName = mw.config.get("wgRelevantUserName");
	var ipRange = (userName === null);
	var titleRegex = /title=([^&]+)/;
	var ipRangeRegex = /wiki\/User_talk:(.+)/;
	mw.loader.using( 'mediawiki.api' ).done( function()
	{
		var api = new mw.Api();
		
		$("a[href*='action=rollback']").each(function(ind, el)
		{
			//if we're in an anonymous IP range, we have to figure out each username on its own, since they might be different for each edit.
			if(ipRange)
			{
				//the not clause is probably not necessary, but I'm including it just to be sure.
				userName = $(el).parents("li:first").children("a.mw-anonuserlink").not(".mw-contributions-title").text();
			}
			var params = {};
			if( editSummary != '' )
			{
				params.summary = editSummary;
			}
			api.rollback( decodeURIComponent(titleRegex.exec(el.href)[1]), userName, params).done( function()
			{
				$(el).after("reverted");
				$(el).remove();
			} );
		} );
	} );
	return false;
}
$(document).ready(function()
{
	if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions" && $("span.mw-rollback-link").length > 0)
	{
		mw.loader.using("mediawiki.util").done( function ()
		{
			mw.util.addPortletLink('p-cactions', '#', "rollback all", "ca-rollbackeverything", "rollback all edits displayed here");
			$("#ca-rollbackeverything").click( function(event)
			{
				event.preventDefault();
				mw.loader.load( 'mediawiki.api' ); //start loading, while the user is in the prompt	
				return rollbackEverythingWKMR(prompt("Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)"));
			});
		});
	}
});