User:Dragoniez/Selective Rollback

From Meta, a Wikimedia project coordination wiki
Other languages:
The Selective Rollback dialog (English)
The Selective Rollback dialog (Japanese)

Selective Rollback is a user script that provides a bunch of useful features for rollback (partially forked from User:Hoo man/smart rollback.js and en:User:DannyS712/AjaxRollback.js).

This script adds the following features:

  • In-situ rollback
Resolve rollback links without page transition.
  • Rollback summary
Specify a custom edit summary for rollback (see #Usage for special expressions).
  • Selective rollback
Resolve multiple rollback links of the user's choice at once.
  • Mass rollback
Resolve all rollback links on the page at once.
  • Mark bot
Mark rollbacks as bot edits, if the user has the rights to do so (configurable).
  • Watch page
Add the reverting pages to watchlist (configurable). The expiration time can also be specified.
  • Confirm rollback
Pop up a confirmation dialog before performing rollback (disabled by default; see #confirm for details).
Note that this script automatically disables the confirmation prompt that can be enabled in preferences.

Installation[edit]

Add the following to Special:MyPage/global.js for global use, or to Special:MyPage/common.js for use on meta, or to your common.js on the wiki you want to enable the script. (source code)

// Selective Rollback ([[User:Dragoniez/Selective_Rollback.js]])
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Dragoniez/Selective_Rollback.js&action=raw&ctype=text/javascript');

See #Usage below for how to use this script, and #Configurations for how to configure some options along with your installation.

Usage[edit]

Dialog[edit]

The position of the portlet link

This script adds a portlet link to open the Selective Rollback dialog in p-cactions (if the skin is vector; see image). The dialog can also be opened by clicking a rollback link with the CTRL key pressed down.

In-situ rollback[edit]

Just hit a rollback link.

Rollback summary[edit]

Select "Custom" on the dialog and type in a summary (or directly type your summary into the relevant textbox). This custom edit summary will be preserved after closing the dialog, and you can perform (in-situ) rollback with the specified edit summary when you hit rollback links on the page.


You can use the following special expressions in specifying summaries ($1-7 are mediawiki's built-in variables):

  • $0: The default rollback summary on the wiki
  • $1: Name of the user who made the last edit before the user whose edits are to be rolled back
  • $2: Name of the user whose edits are to be rolled back
  • $3: The revision number of $1's edit
  • $4: The timestamp of $1's edit
  • $5: The revision number of $2's edit
  • $6: The timestamp of $2's edit
  • $7: The number of revisions to revert (mw:MediaWiki 1.41/wmf.10; see the collapsed section below)

Assume that $1 is Example and $2 is Example2. Then, on meta,

  • Long-term abuse $0

for example, will be outputted as

  • Long-term abuse Reverted changes by Example2 (talk) to last version by Example

because the default rollback summary on meta is

  • Reverted changes by [[Special:Contributions/$2|$2]] ([[User talk:$2|talk]]) to last version by $1

The $0 replacement feature would be useful when you want to add a comment to your rollback and at the same time want to include the default rollback summary. The concept is that this feature makes it possible to perform rollback the way undo works.

You can also predefine edit summaries and prepare your own special expressions in your user JS (see #Configurations).

Update (task T165798)

The magic word {{PLURAL}} has been added to the default message of MediaWiki:Revertpage:

  • mw:MediaWiki 1.41/wmf.10
  • Diff
  • Reverted {{PLURAL:$7|edit|edits}} by [[Special:Contributions/$2|$2]] ([[User talk:$2|talk]]) to last revision by [[User:$1|$1]]

Currently, Selective Rollback parses the magic word in a rough way, and the last operand is always parsed out:

  • Reverted edits by [[Special:Contributions/$2|$2]] ([[User talk:$2|talk]]) to last revision by [[User:$1|$1]]

This is because there is no choice but to make an API request right after the relevant link is clicked in order to know how many revisions we're going to rollback. Simply, doing this would undermine why we have the functionality of rollback.

Selective rollback[edit]

If the current page has rollback links, "SR" checkboxes will be added to it. Check the boxes of the edits you want to rollback, open the dialog, and then hit "Rollback checked".

Note: This feature is disabled on Special:RecentChanges and Special:Watchlist.

Mass rollback[edit]

Open the dialog, hit "Check all", and then hit "Rollback checked".

Note: This feature is disabled on Special:RecentChanges and Special:Watchlist.

Mark bot[edit]

Check the relevant box on the dialog. You can configure the default checked state if you wish (see #Configurations).

Watch page[edit]

Check the relevant box on the dialog. You can configure the default checked state if you wish (see #Configurations).

Configurations[edit]

Selective Rollback has the following JavaScript object for personal settings.

window.selectiveRollbackConfig = {
    lang: '',
    editSummaries: {},
    showKeys: false,
    specialExpressions: {},
    markBot: true,
    watchPage: false,
    watchExpiry: 'indefinite',
    confirm: 'never',
    checkboxLabelColor: 'orange'
};

Basically, your installation should look like:

// Selective Rollback ([[User:Dragoniez/Selective_Rollback.js]])
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Dragoniez/Selective_Rollback.js&action=raw&ctype=text/javascript');
window.selectiveRollbackConfig = {}; // This declaration is necessary when you add configs (but NEVER repeat this)
// Add your configs here

lang[edit]

You can configure the default language of the script. When not configured, it's automatically set to the language specified in your preferences. Note that if the script doesn't have translations in the language, English messages will be used (see below for how to submit new translations).

By assigning a value to the lang config, you can explicitly tell the script to use that language, as below (the example sets the interface language to English):

window.selectiveRollbackConfig = {};
selectiveRollbackConfig.lang = 'en';

I would appreciate it if anyone could provide new translations. Take a look at the following, and post your translations on User talk:Dragoniez/Selective Rollback.

Texts for translation
{
	'portletlink-tooltip': 'Open the Selective Rollback dialog',
	'summary-label-primary': 'Edit summary',
	'summary-option-default': 'Default edit summary',
	'summary-option-custom': 'Custom',
	'summary-label-custom': 'Custom edit summary',
	'summary-tooltip-$0': '($0 will be replaced with the default rollback summary.)',
	'summary-tooltip-$0-error': '($0 will be replaced with the default rollback summary <b>in English</b>.)',
	'summary-tooltip-specialexpressions': 'Replacement expressions',
	'summary-label-preview': 'Summary preview', // v4.0.0
	'summary-tooltip-preview': '(Magic words will be replaced.)', // v4.0.0
	'markbot-label': 'Mark rollbacks as bot edits',
	'watchlist-label': 'Add the target pages to watchlist',
	'watchlist-expiry-label': 'Expiry',
	'watchlist-expiry-indefinite': 'Indefinite',
	'watchlist-expiry-1week': '1 week',
	'watchlist-expiry-1month': '1 month',
	'watchlist-expiry-3months': '3 months',
	'watchlist-expiry-6months': '6 months',
	'watchlist-expiry-1year': '1 year',
	'watchlist-expiry-3years': '3 years', // Not used
	'button-rollbackchecked': 'Rollback checked',
	'button-checkall': 'Check all',
	'button-close': 'Close',
	'msg-nonechecked': 'No checkbox is checked.',
	'msg-linksresolved': 'Rollback links on this page have all been resolved.',
	'msg-confirm': 'Are you sure you want to rollback this edit?',
	'rbstatus-reverted': 'reverted',
	'rbstatus-failed': 'rollback failed',
	'rbstatus-notify-success': 'Success', // v4.0.0
	'rbstatus-notify-failure': 'Failure' // v4.0.0
}

editSummaries & showKeys[edit]

To predefine edit summaries, include config lines like the following along with the script loader:

//<nowiki>
window.selectiveRollbackConfig = {};
selectiveRollbackConfig.editSummaries = {};
selectiveRollbackConfig.editSummaries[0] = 'Long-term abuse';
selectiveRollbackConfig.editSummaries[1] = 'Cross-wiki abuse';
selectiveRollbackConfig.editSummaries[2] = 'Spam';
selectiveRollbackConfig.editSummaries[3] = '[[WP:SOCK]]';
//</nowiki>

Then, the dropdown options will be:

  • Default edit summary
  • Long-term abuse
  • Cross-wiki abuse
  • Spam
  • [[WP:SOCK]]
  • Custom

Note that it's safer to include <nowiki/> for cases when your custom summaries include internal wikilinks.


You can also name each option and show them on the dialog instead of the whole edit summaries, if you specify selectiveRollbackConfig.showKeys = true.

For example, install the script with

//<nowiki>
window.selectiveRollbackConfig = {};
selectiveRollbackConfig.editSummaries = {};
selectiveRollbackConfig.editSummaries['LTA'] = 'Long-term abuse';
selectiveRollbackConfig.editSummaries['CWA'] = 'Cross-wiki abuse';
selectiveRollbackConfig.showKeys = true;
//</nowiki>

and the dropdown options will be:

  • Default edit summary
  • LTA
  • CWA
  • Custom

but if you choose "LTA" for instance, the output will be "Long-term abuse".

specialExpressions[edit]

In addition to $0 and the like, you can prepare your own special expressions to be replaced with certain texts.

//<nowiki>
window.selectiveRollbackConfig = {};
selectiveRollbackConfig.specialExpressions = {};
selectiveRollbackConfig.specialExpressions['$SLIME'] = '[[LTA:SLIME]]';
selectiveRollbackConfig.specialExpressions['$QCHM'] = '[[LTA:QCHM]]';
//</nowiki>

In this case, any occurrence of "$SLIME", for example, will be replaced with "[[LTA:SLIME]]". I recommend that you prefix your special expressions with $ or something similar, to avoid unintentional replacement of texts.

markBot[edit]

If you have the markbotedits right on the wiki where SR is loaded, the markBot checkbox is checked on the dialog by default (hence true; note that this box is always hidden and unchecked if you don't have the user right). If you want to have the box unchecked by default, use:

window.selectiveRollbackConfig = {};
selectiveRollbackConfig.markBot = false;

watchPage & watchExpiry[edit]

The watchPage checkbox is unchecked on the dialog by default (hence false), and the expiration time is set to indefinite. If you want to change these default settings, use e.g.:

window.selectiveRollbackConfig = {};
selectiveRollbackConfig.watchPage = true;
selectiveRollbackConfig.watchExpiry = '1 month';

This is an example to automatically add the reverting pages to your watchlist for 1 month. The accepted values for watchExpiry are indefinite, infinite, infinity, never, 1 week, 1 month, 3 months, 6 months, and 1 year. This script has a casual typo-checking functionality, so there's no need to worry about the presence of a space and a plural suffix, etc. Note that if an invalid value is specified, an error message will be shown in the browser console (or the more notable consequence is that the default value doesn't change on the dialog).

confirm[edit]

confirm is a config for rollback confirmation, defaulted to never. The accepted values are never, always, RCW, and nonRCW, where RCW is an abbreviation for RecentChanges and Watchlist. When this config is valued with never or always, the script never/always shows you a confirmation message before performing rollback, and when it's valued with RCW or nonRCW, the script shows you a confirmation message when you're (not) on either Special:RecentChanges or Special:Watchlist. Note that you can suppress the confirmation popup by clicking a rollback link with the SHIFT key pressed down.

window.selectiveRollbackConfig = {};
selectiveRollbackConfig.confirm = 'RCW';

checkboxLabelColor[edit]

checkboxLabelColor is a config to change the color of "SR" checkbox labels, which defaults to orange.

window.selectiveRollbackConfig = {};
selectiveRollbackConfig.checkboxLabelColor = 'pink';