Jump to content

User:Home Lander/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Home Lander (talk | contribs) at 17:06, 1 March 2017 (Created page with 'function rollbackEverythingWKMR(editSummary) { if(editSummary == null) { return false; } var userName = mw.config.get("wgRelevantUserName"); var titleReg...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
function rollbackEverythingWKMR(editSummary) 
{
	if(editSummary == null)
	{
		return false;
	}
	var userName = mw.config.get("wgRelevantUserName");
	var titleRegex = /title=([^&]+)/;
	
	$.post("/w/api.php",{action:"query",meta:"tokens",type:"rollback",format:"json"}, function(data)
	{
		rollbackToken = data.query.tokens.rollbacktoken;
		$("a[href*='action=rollback']").each(function(ind, el)
		{
			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)
	{
		mw.loader.using("mediawiki.util").then(function ()
		{
			mw.util.addPortletLink('p-cactions', '#', "rollback all", "ca-rollbackeverything", "rollback all edits displayed here");
			$("#ca-rollbackeverything").click(function()
			{
				return rollbackEverythingWKMR(prompt("Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)"));
			});
		});
	}
});