Skip to content

Commit

Permalink
morebits: Add support for change/revisions tags, remove customization…
Browse files Browse the repository at this point in the history
… of summaryAd

Defines `Twinkle.changeTags = 'twinkle'` in twinkle.js and applies that across the board.

There are a lot of actions, only some of which support applying tags.  For a full list, search for `ApiBase::PARAM_TYPE => 'tags'` (in core; for extensions use something like that e.g. `::PARAM_TYPE => 'tags'`).  The fullish list is:

* block
* changecontentmodel
* delete
* edit
* import
* managetags
* move
* patrol
* protect
* revisiondelete
* rollback
* setlanguagepage
* tag
* unblock
* undelete
* upload
* userrights

Basically the majority of the "write modules."  Others that support `tags`: globaluserrights, the Wiki Love extension, and various WikiBase APIs; notable exceptions for our purposes are PageTriage (T252980) and FlaggedRevs (T247721).  This implementation weeds out the most common/likely for our purposes: checking against the full supported list is unwieldy, and largely unnecessary as the error message is harmless.  If we did want to check everything, we'd just dump that list into an object and verify the relevant action.

This also deprecates the `summaryAd` preferences.  `summaryAd`, `deletionSummaryAd`, and `protectionSummaryAd` have been retained in twinkle.js' `defaultConfig` as backups when a tag isn't used (e.g. add-on scripts, installations that don't want to use a tag), but this also formally removes them as preferences to be selected from `twinkleconfig.js`.  `deletionSummaryAd` and `protectionSummaryAd` should be removed entirely IMO, in favor of just one "ad" that could itself be better integrated.

----

At first blush it would seem to be simpler to just do something like we do for the useragent, that is:

```
Morebits.wiki.api.setActionTag = function(tag) {
	morebitsWikiActionTag = ...
};
```

But doing that would mean the tag would be applied to any actions made using the Twinkle structure, such as addons like https://en.wikipedia.org/wiki/User:Bellezzasolo/Scripts/arb.js.  Moreover, given the likely coincidence between 1. scripts using the morebits library, and 2. users of Twinkle, that would effectively make this a "morebits" tag rather than "twinkle."  Having the invocation on a per module basis rather than `twinkle.js` only solves the issue if one and only one action is opened and then successfully performed, which is likewise unreliable.  Instead, the structure used here means setting the tag manually and individually, using either the `tags` parameter for `Morebits.wiki.api` actions or `.setChangesTags` for `Morebits.wiki.page` (or by setting `this.changeTags` for `Morebits.userspacelogger`, done to avoid adding another parameter).

Morebits (the library) maintains its ability to set its own tag for non-twinkle actions, although that might be undesirable and is turned off.
  • Loading branch information
Amorymeltzer committed Aug 13, 2020
1 parent 2fcf267 commit c581923
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 35 deletions.
29 changes: 0 additions & 29 deletions modules/twinkleconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,35 +152,6 @@ Twinkle.config.sections = [
{
title: 'General',
preferences: [
// TwinkleConfig.summaryAd (string)
// Text to be appended to the edit summary of edits made using Twinkle
{
name: 'summaryAd',
label: "\"Ad\" to be appended to Twinkle's edit summaries",
helptip: 'The summary ad should start with a space, and be kept short.',
type: 'string'
},

// TwinkleConfig.deletionSummaryAd (string)
// Text to be appended to the edit summary of deletions made using Twinkle
{
name: 'deletionSummaryAd',
label: 'Summary ad to use for deletion summaries',
helptip: 'Normally the same as the edit summary ad above.',
adminOnly: true,
type: 'string'
},

// TwinkleConfig.protectionSummaryAd (string)
// Text to be appended to the edit summary of page protections made using Twinkle
{
name: 'protectionSummaryAd',
label: 'Summary ad to use for page protections',
helptip: 'Normally the same as the edit summary ad above.',
adminOnly: true,
type: 'string'
},

// TwinkleConfig.userTalkPageMode may take arguments:
// 'window': open a new window, remember the opened window
// 'tab': opens in a new tab, if possible.
Expand Down
55 changes: 55 additions & 0 deletions morebits.js
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,13 @@ Morebits.wiki.api = function(currentAction, query, onSuccess, statusElement, onE
} else if (['xml', 'json'].indexOf(query.format) === -1) {
this.statelem.error('Invalid API format: only xml and json are supported.');
}

// Ignore tags for queries and most common unsupported actions, produces warnings
if (query.action && ['query', 'review', 'stabilize', 'pagetriageaction', 'watch'].indexOf(query.action) !== -1) {
delete query.tags;
} else if (!query.tags && morebitsWikiChangeTag) {
query.tags = morebitsWikiChangeTag;
}
};

Morebits.wiki.api.prototype = {
Expand Down Expand Up @@ -1882,6 +1889,11 @@ Morebits.wiki.api.setApiUserAgent = function(ua) {
morebitsWikiApiUserAgent = (ua ? ua + ' ' : '') + 'morebits.js ([[w:WT:TW]])';
};

// Default change/revision tag applied to Morebits actions when no other tags are specified
// Off by default per [[Special:Permalink/970618849#Adding tags to Twinkle edits and actions]]
var morebitsWikiChangeTag = '';


/** Get a new CSRF token on encountering token errors */
Morebits.wiki.api.getToken = function() {
var tokenApi = new Morebits.wiki.api('Getting token', {
Expand Down Expand Up @@ -2037,6 +2049,7 @@ Morebits.wiki.page = function(pageName, currentAction) {
pageName: pageName,
pageExists: false,
editSummary: null,
changeTags: null,
callbackParameters: null,
statusElement: new Morebits.status(currentAction),

Expand Down Expand Up @@ -2231,6 +2244,10 @@ Morebits.wiki.page = function(pageName, currentAction) {
watchlist: ctx.watchlistOption
};

if (ctx.changeTags) {
query.tags = ctx.changeTags;
}

if (typeof ctx.pageSection === 'number') {
query.section = ctx.pageSection;
}
Expand Down Expand Up @@ -2366,6 +2383,18 @@ Morebits.wiki.page = function(pageName, currentAction) {
ctx.editSummary = summary;
};

/**
* Set any custom tag(s) to be applied to the API action
* A number of actions don't support it, most notably watch, review
* and stabilize (T247721), and pagetriageaction (T252980)
*
* @param {string|string[]} tags - String or array of tag(s)
*/
this.setChangeTags = function(tags) {
ctx.changeTags = tags;
};


/**
* @param {string} createOption - can take the following four values:
* `recreate` - create the page if it does not exist, or edit it if it exists.
Expand Down Expand Up @@ -3344,6 +3373,10 @@ Morebits.wiki.page = function(pageName, currentAction) {
'reason': ctx.editSummary,
'watchlist': ctx.watchlistOption
};
if (ctx.changeTags) {
query.tags = ctx.changeTags;
}

if (ctx.moveTalkPage) {
query.movetalk = 'true';
}
Expand Down Expand Up @@ -3389,6 +3422,9 @@ Morebits.wiki.page = function(pageName, currentAction) {

query.token = token;
}
if (ctx.changeTags) {
query.tags = ctx.changeTags;
}

var patrolStat = new Morebits.status('Marking page as patrolled');

Expand Down Expand Up @@ -3421,6 +3457,9 @@ Morebits.wiki.page = function(pageName, currentAction) {
action: 'pagetriageaction',
pageid: pageID,
reviewed: 1,
// tags: ctx.changeTags, // pagetriage tag support: [[phab:T252980]]
// Could use an adder to modify/create note:
// summaryAd, but that seems overwrought
token: token
};

Expand Down Expand Up @@ -3482,6 +3521,10 @@ Morebits.wiki.page = function(pageName, currentAction) {
'reason': ctx.editSummary,
'watchlist': ctx.watchlistOption
};
if (ctx.changeTags) {
query.tags = ctx.changeTags;
}


ctx.deleteProcessApi = new Morebits.wiki.api('deleting page...', query, ctx.onDeleteSuccess, ctx.statusElement, fnProcessDeleteError);
ctx.deleteProcessApi.setParent(this);
Expand Down Expand Up @@ -3556,6 +3599,10 @@ Morebits.wiki.page = function(pageName, currentAction) {
'reason': ctx.editSummary,
'watchlist': ctx.watchlistOption
};
if (ctx.changeTags) {
query.tags = ctx.changeTags;
}


ctx.undeleteProcessApi = new Morebits.wiki.api('undeleting page...', query, ctx.onUndeleteSuccess, ctx.statusElement, fnProcessUndeleteError);
ctx.undeleteProcessApi.setParent(this);
Expand Down Expand Up @@ -3654,6 +3701,11 @@ Morebits.wiki.page = function(pageName, currentAction) {
reason: ctx.editSummary,
watchlist: ctx.watchlistOption
};
// Only shows up in logs, not page history [[phab:T259983]]
if (ctx.changeTags) {
query.tags = ctx.changeTags;
}

if (ctx.protectCascade) {
query.cascade = 'true';
}
Expand Down Expand Up @@ -3695,6 +3747,7 @@ Morebits.wiki.page = function(pageName, currentAction) {
token: token,
protectlevel: ctx.flaggedRevs.level,
expiry: ctx.flaggedRevs.expiry,
// tags: ctx.changeTags, // flaggedrevs tag support: [[phab:T247721]]
reason: ctx.editSummary
};
// [[phab:T247915]]
Expand Down Expand Up @@ -4091,6 +4144,7 @@ Morebits.userspaceLogger = function(logPageName) {
}
this.initialText = '';
this.headerLevel = 3;
this.changeTags = '';

this.log = function(logText, summaryText) {
if (!logText) {
Expand All @@ -4110,6 +4164,7 @@ Morebits.userspaceLogger = function(logPageName) {

pageobj.setPageText(text + '\n' + logText);
pageobj.setEditSummary(summaryText);
pageobj.setChangeTags(this.changeTags);
pageobj.setCreateOption('recreate');
pageobj.save();
}.bind(this));
Expand Down
18 changes: 12 additions & 6 deletions twinkle.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ window.Twinkle = Twinkle; // allow global access
* Twinkle-specific data shared by multiple modules
* Likely customized per installation
*/
// Various hatnote templates, used when tagging (csd/xfd/tag/prod/protect) to
// ensure MOS:ORDER
// Custom change tag(s) to be applied to all Twinkle actions, create at Special:Tags
Twinkle.changeTags = 'twinkle';
// Available for actions that don't (yet) support tags
// currently: FlaggedRevs and PageTriage
Twinkle.summaryAd = ' ([[WP:TW|TW]])';

// Various hatnote templates, used when tagging (csd/xfd/tag/prod/protect) to ensure [[w:en:MOS:ORDER]]
Twinkle.hatnoteRegex = 'short description|hatnote|main|correct title|dablink|distinguish|for|further|selfref|year dab|similar names|highway detail hatnote|broader|about(?:-distinguish| other people)?|other\\s?(?:hurricane(?: use)?s|people|persons|places|ships|uses(?: of)?)|redirect(?:-(?:distinguish|synonym|multi))?|see\\s?(?:wiktionary|also(?: if exists)?)';


Expand All @@ -58,9 +63,6 @@ Twinkle.defaultConfig = {};
*/
Twinkle.defaultConfig = {
// General
summaryAd: ' ([[WP:TW|TW]])',
deletionSummaryAd: ' ([[WP:TW|TW]])',
protectionSummaryAd: ' ([[WP:TW|TW]])',
userTalkPageMode: 'tab',
dialogLargeFont: false,
disabledModules: [],
Expand Down Expand Up @@ -143,8 +145,12 @@ Twinkle.defaultConfig = {
batchMax: 5000,
batchChunks: 50,

// Formerly defaultConfig.friendly:
// Deprecated options, as a fallback for add-on scripts/modules
summaryAd: ' ([[WP:TW|TW]])',
deletionSummaryAd: ' ([[WP:TW|TW]])',
protectionSummaryAd: ' ([[WP:TW|TW]])',

// Formerly defaultConfig.friendly:
// Tag
groupByDefault: true,
watchTaggedPages: true,
Expand Down

0 comments on commit c581923

Please sign in to comment.