Misplaced Pages

User:PhilKnight/monobook.js

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:PhilKnight

This is an old revision of this page, as edited by PhilKnight (talk | contribs) at 02:45, 17 August 2024 (mass rollback). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 02:45, 17 August 2024 by PhilKnight (talk | contribs) (mass rollback)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
The accompanying .css page for this skin can be added at User:PhilKnight/monobook.css.
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 Misplaced Pages:Bypass your cache.
importScript('Misplaced Pages:WikiProject User scripts/Scripts/Search links');
importScript('Misplaced Pages:WikiProject User scripts/Scripts/Dashboard');
importScript('Misplaced Pages:WikiProject User scripts/Scripts/Show last secure diff');
importScript('User:Gracenotes/rollback.js');
rollbackSummaryDefault = "] good faith edits by ] (]) - unsourced additions";
mw.loader.load( "https://meta.wikimedia.org/search/?title=User:Zhaofeng_Li/Reflinks.js&action=raw&ctype=text/javascript" );
//Mass rollback function
//Written by John254 and modified/rewritten by Writ Keeper with modifications by TheDJ; original is at https://en.wikipedia.org/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)
if(typeof wkContribsCheckboxInit === "undefined")
{
	wkContribsCheckboxInit = false;
}

if(typeof wkRollbackPortlet === "undefined")
{
	wkRollbackPortlet = "p-cactions";
}

function rollbackEverythingWKMR(editSummary) 
{
	if(editSummary === null)
	{
		return false;
	}
	if(mw.config.get("wgRelevantUserName") === mw.config.get("wgUserName"))
	{
		if(!(confirm("You are about to roll back *all* of *your own* edits. Please note that this will be very difficult to undo. Are you *ABSOLUTELY SURE* you want to do this?")))
		{
			return false;
		}
	}
	mw.loader.using( 'mediawiki.api' ).done( function()
	{
		var rbMetadata = {};
		rbMetadata.api = new mw.Api();
		rbMetadata.userName = mw.config.get("wgRelevantUserName");
		rbMetadata.ipRange = (rbMetadata.userName === null);
		rbMetadata.titleRegex = /title=(+)/;
		rbMetadata.editSummary = editSummary;
		$("a").each(function(ind, el)
		{
			rollbackOneThingWKMR(el, rbMetadata);
		} );
	} );
	return false;
}
function rollbackSomeThingsWKMR(editSummary)
{
	if(editSummary === null)
	{
		return false;
	}
	mw.loader.using( 'mediawiki.api' ).done( function()
	{
		var rbMetadata = {};
		rbMetadata.api = new mw.Api();
		rbMetadata.userName = mw.config.get("wgRelevantUserName");
		rbMetadata.titleRegex = /title=(+)/;
		rbMetadata.editSummary = editSummary;
		var rollbackList = $("input.revdelIds:checked").parents("li.mw-contributions-current").find("a");
		if(rollbackList.length <= 0)
		{
			mw.notify("You didn't select any edits that could be rolled back!");
			return;
		}
		$("input.revdelIds:checked").parents("li.mw-contributions-current").find("a").each(function(ind, el)
		{
			rollbackOneThingWKMR(el, rbMetadata);
		} );
	} );
}
function rollbackOneThingWKMR(edit, rbMetadata)
{
	var userName;
	//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(rbMetadata.userName === null)
	{
		//the not clause is probably not necessary, but I'm including it just to be sure.
		userName = $(edit).parents("li:first").children("a.mw-anonuserlink").not(".mw-contributions-title").text();
	}
	else
	{
		userName = rbMetadata.userName;
	}
	var params = {};
	if( rbMetadata.editSummary != '' )
	{
		params.summary = rbMetadata.editSummary;
	}
	rbMetadata.api.rollback( decodeURIComponent(rbMetadata.titleRegex.exec(edit.href)), userName, params).done( function()
	{
		$(edit).after("reverted");
		$(edit).remove();
	} );
}
$(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(wkRollbackPortlet, '#', "Rollback all", "ca-rollbackeverything", "rollback all edits displayed here");
			if(!wkContribsCheckboxInit)
			{
				if($("ul.mw-contributions-list .mw-revdelundel-link").length > 0)
				{
					$("ul.mw-contributions-list .mw-revdelundel-link").each(function(ind,el){
						if($(this).children("a").length > 0)
						{
							var revId = /ids=(\d+)/.exec($(this).children("a").attr("href"));
							var pageTitle = /target=(+)/.exec($(this).children("a").attr("href"));
							$(el).prepend("<input type='checkbox' name='"+decodeURIComponent(pageTitle)+"' class='revdelIds' value='"+revId+"'>&nbsp;");
							$(el).children(".revdelIds").data("index", ind);
						}
					});
				}
				else
				{
					$("ul.mw-contributions-list a.mw-changeslist-date").each(function(ind,el){
						$(el).before("<input type='checkbox' class='revdelIds'>&nbsp;");
					});
				}
				wkContribsCheckboxInit = true;
			}
			mw.util.addPortletLink(wkRollbackPortlet, '#', "Rollback selected", "ca-rollbacksome", "rollback selected edits");
			$("#ca-rollbackeverything").click( function(event)
			{
				event.preventDefault();
				mw.loader.load( 'mediawiki.api' ); //start loading, while the user is in the prompt	
				return rollbackEverythingWKMR(prompt("Rollback all edits: Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)"));
			});
			$("#ca-rollbacksome").click( function(event)
			{
				event.preventDefault();
				mw.loader.load( 'mediawiki.api' ); //start loading, while the user is in the prompt	
				return rollbackSomeThingsWKMR(prompt("Rollback selected edits: Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)"));
			});
			$("#ca-rollbacksome").data("lastSelectedIndex", -1);

			$("input.revdelIds").off("click").click(
				function(ev)
				{
					var lastSelectedRevdel = $("#ca-rollbacksome").data("lastSelectedIndex");
					var newIndex = $(this).data("index");
					if(ev.shiftKey && lastSelectedRevdel >= 0)
					{
						var checkboxArray = $("input.revdelIds");
						var start = lastSelectedRevdel;
						var stop = newIndex;
						if(start < stop)
						{
							for(var i = start; i < stop; i++)
							{
								if(i != lastSelectedRevdel)
								{
									$(checkboxArray).prop("checked", !($(checkboxArray).prop("checked")));
								}
							}
						}
						else
						{
							for(var i = start; i > stop; i--)
							{
								if(i != lastSelectedRevdel)
								{
									$(checkboxArray).prop("checked", !($(checkboxArray).prop("checked")));
								}
							}
						}
					}
					 $("#ca-rollbacksome").data("lastSelectedIndex", newIndex);
				});

		});
	}
});