Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
},
"rules": {
// default rules we don't like
"array-bracket-spacing": "off",
"computed-property-spacing": "off",
"es-x/no-array-prototype-includes": "off",
"es-x/no-promise-prototype-finally": "off",
"indent": "off",
Expand All @@ -25,9 +23,13 @@
"no-jquery/no-global-selector": "off",
"no-shadow": "off",
"object-curly-spacing": "off",
"space-before-function-paren": "off",
"space-in-parens": "off",
"template-curly-spacing": "off",

// enforce no spaces in parens (https://github.com/wikimedia-gadgets/twinkle/issues/1827)
"array-bracket-spacing": ["error", "never"],
"computed-property-spacing": ["error", "never"],
"space-before-function-paren": ["error", "never"],
"space-in-parens": ["error", "never"],
"template-curly-spacing": ["error", "never"],

// non-default rules we do like
"no-nested-ternary": "error",
Expand Down
4 changes: 2 additions & 2 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ global.assert = assert;

// Node.js assert doesn't support these functions unlike Qunit assert,
// so temporarily monkey-patch them
assert.true = function (arg, message) {
assert.true = function(arg, message) {
if (arg !== true) {
throw new Error(message);
}
};
assert.false = function (arg, message) {
assert.false = function(arg, message) {
if (arg !== false) {
throw new Error(message);
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/twinklearv.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Twinkle.arv = function twinklearv() {
}, 'ARV', 'tw-arv', 'Report ' + userType + ' to administrators');
};

Twinkle.arv.callback = function (uid, isIP) {
Twinkle.arv.callback = function(uid, isIP) {
const Window = new Morebits.SimpleWindow(600, 500);
Window.setTitle('Advance Reporting and Vetting'); // Backronym
Window.setScriptName('Twinkle');
Expand Down Expand Up @@ -141,7 +141,7 @@ Twinkle.arv.callback = function (uid, isIP) {
result.category.dispatchEvent(evt);
};

Twinkle.arv.callback.changeCategory = function (e) {
Twinkle.arv.callback.changeCategory = function(e) {
const value = e.target.value;
const root = e.target.form;
const old_area = Morebits.QuickForm.getElements(root, 'work_area')[0];
Expand Down Expand Up @@ -714,7 +714,7 @@ Twinkle.arv.callback.getUsernameReportWikitext = function(input) {
if (input.arvtype.length <= 2) {
input.arvtype = input.arvtype.join(' and ');
} else {
input.arvtype = [ input.arvtype.slice(0, -1).join(', '), input.arvtype.slice(-1) ].join(' and ');
input.arvtype = [input.arvtype.slice(0, -1).join(', '), input.arvtype.slice(-1)].join(' and ');
}

// a or an?
Expand Down
4 changes: 2 additions & 2 deletions src/modules/twinkleblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ Twinkle.block.callback.change_action = function twinkleblockCallbackChangeAction
Twinkle.block.callback.preview($form[0]);
});
$previewlink.css({cursor: 'pointer'});
fieldTemplateOptions.append({ type: 'div', id: 'blockpreview', label: [ $previewlink[0] ] });
fieldTemplateOptions.append({ type: 'div', id: 'blockpreview', label: [$previewlink[0]] });
fieldTemplateOptions.append({ type: 'div', id: 'twinkleblock-previewbox', style: 'display: none' });
} else if (fieldPreset) {
// Only visible for arbitration enforcement, toggled in change_preset
Expand Down Expand Up @@ -2022,7 +2022,7 @@ Twinkle.block.callback.getBlockNoticeWikitext = function(params) {
// Building the template, however, takes a fair bit of logic
if (params.partial) {
if (params.pagerestrictions.length || params.namespacerestrictions.length) {
const makeSentence = function (array) {
const makeSentence = function(array) {
if (array.length < 3) {
return array.join(' and ');
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/twinkleconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ Twinkle.config.commonSets = {
}
};

Twinkle.config.commonSets.csdCriteriaDisplayOrder = Object.keys( Twinkle.config.commonSets.csdCriteria );
Twinkle.config.commonSets.csdCriteriaNotificationDisplayOrder = Object.keys( Twinkle.config.commonSets.csdCriteriaNotification );
Twinkle.config.commonSets.csdAndImageDeletionCriteriaDisplayOrder = Object.keys( Twinkle.config.commonSets.csdAndImageDeletionCriteria );
Twinkle.config.commonSets.csdCriteriaDisplayOrder = Object.keys(Twinkle.config.commonSets.csdCriteria);
Twinkle.config.commonSets.csdCriteriaNotificationDisplayOrder = Object.keys(Twinkle.config.commonSets.csdCriteriaNotification);
Twinkle.config.commonSets.csdAndImageDeletionCriteriaDisplayOrder = Object.keys(Twinkle.config.commonSets.csdAndImageDeletionCriteria);

/**
* Section entry format:
Expand Down
2 changes: 1 addition & 1 deletion src/modules/twinklediff.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Twinkle.diff.evaluate = function twinklediffEvaluate(me) {
action: 'query',
titles: mw.config.get('wgPageName'),
rvlimit: 1,
rvprop: [ 'ids', 'user' ],
rvprop: ['ids', 'user'],
rvstartid: mw.config.get('wgCurRevisionId') - 1, // i.e. not the current one
rvuser: user,
format: 'json'
Expand Down
4 changes: 2 additions & 2 deletions src/modules/twinkleimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Twinkle.image.callback.evaluate = function twinkleimageCallbackEvaluate(event) {
// No auto-notification, display what was going to be added.
const noteData = document.createElement('pre');
noteData.appendChild(document.createTextNode('{{subst:di-' + templatename + '-notice|1=' + mw.config.get('wgTitle') + '}} ~~~~'));
Morebits.Status.info('Notification', [ 'Following/similar data should be posted to the original uploader:', document.createElement('br'), noteData ]);
Morebits.Status.info('Notification', ['Following/similar data should be posted to the original uploader:', document.createElement('br'), noteData]);
}
};

Expand All @@ -249,7 +249,7 @@ Twinkle.image.callbacks = {
let text = pageobj.getPageText();
const params = pageobj.getCallbackParameters();

text = Twinkle.removeMoveToCommonsTagsFromWikicode( text );
text = Twinkle.removeMoveToCommonsTagsFromWikicode(text);

let tag = '{{di-' + params.templatename + '|date={{subst:#time:j F Y}}';
switch (params.type) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/twinkleprod.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,18 @@ Twinkle.prod.callback.evaluate = function twinkleprodCallbackEvaluate(e) {
tm.add(cbs.checkPriors, []);
tm.add(cbs.fetchCreationInfo, []);
// tag the page once we're clear of the pre-requisites
tm.add(cbs.taggingPage, [ cbs.checkPriors, cbs.fetchCreationInfo ]);
tm.add(cbs.taggingPage, [cbs.checkPriors, cbs.fetchCreationInfo]);
// notify the author once we know who's the author, and also wait for the
// taggingPage() as we don't need to notify if tagging was not done, such as
// there was already a tag and the user chose not to endorse.
tm.add(cbs.notifyAuthor, [ cbs.fetchCreationInfo, cbs.taggingPage ]);
tm.add(cbs.notifyAuthor, [cbs.fetchCreationInfo, cbs.taggingPage]);
// oldProd needs to be added only if there wasn't one before, so need to wait
// for checkPriors() to finish. Also don't add oldProd if tagging itself was
// aborted or unsuccessful
tm.add(cbs.addOldProd, [ cbs.taggingPage, cbs.checkPriors ]);
tm.add(cbs.addOldProd, [cbs.taggingPage, cbs.checkPriors]);
// add to log only after notifying author so that the logging can be adjusted if
// notification wasn't successful. Also, don't run if tagging was not done.
tm.add(cbs.addToLog, [ cbs.notifyAuthor, cbs.taggingPage ]);
tm.add(cbs.addToLog, [cbs.notifyAuthor, cbs.taggingPage]);
// All set, go!
tm.execute().then(() => {
Morebits.Status.actionCompleted('Tagging complete');
Expand Down
8 changes: 4 additions & 4 deletions src/modules/twinkleprotect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1521,13 +1521,13 @@ Twinkle.protect.callbacks = {
rppLink.appendChild(document.createTextNode('Wikipedia:Requests for page protection'));

if (tag) {
statusElement.error([ 'There is already a protection request for this page at ', rppLink, ', aborting.' ]);
statusElement.error(['There is already a protection request for this page at ', rppLink, ', aborting.']);
return;
}

let newtag = '=== [[:' + Morebits.pageNameNorm + ']] ===\n';
if (new RegExp('^' + mw.util.escapeRegExp(newtag).replace(/\s+/g, '\\s*'), 'm').test(text) || new RegExp('^' + mw.util.escapeRegExp(newtag).replace(/\s+/g, '\\s*'), 'm').test(text2)) {
statusElement.error([ 'There is already a protection request for this page at ', rppLink, ', aborting.' ]);
statusElement.error(['There is already a protection request for this page at ', rppLink, ', aborting.']);
return;
}
newtag += '* {{pagelinks|1=' + Morebits.pageNameNorm + '}}\n\n';
Expand Down Expand Up @@ -1590,7 +1590,7 @@ Twinkle.protect.callbacks = {
const linknode = document.createElement('a');
linknode.setAttribute('href', mw.util.getUrl('Wikipedia:Twinkle/Fixing RPP'));
linknode.appendChild(document.createTextNode('How to fix RPP'));
statusElement.error([ 'Could not find relevant heading on WP:RPP. To fix this problem, please see ', linknode, '.' ]);
statusElement.error(['Could not find relevant heading on WP:RPP. To fix this problem, please see ', linknode, '.']);
return;
}
statusElement.status('Adding new request...');
Expand Down Expand Up @@ -1626,7 +1626,7 @@ Twinkle.protect.callbacks = {
const linknode2 = document.createElement('a');
linknode2.setAttribute('href', mw.util.getUrl('Wikipedia:Twinkle/Fixing RPP'));
linknode2.appendChild(document.createTextNode('How to fix RPP'));
statusElement.error([ 'Could not find relevant heading on WP:RPP. To fix this problem, please see ', linknode2, '.' ]);
statusElement.error(['Could not find relevant heading on WP:RPP. To fix this problem, please see ', linknode2, '.']);
return;
}
statusElement.status('Adding new request...');
Expand Down
36 changes: 18 additions & 18 deletions src/modules/twinklerollback.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Twinkle.rollback.revert = function revertPage(type, vandal, rev, page) {
inprop: 'watched',
intestactions: 'edit',
rvlimit: Twinkle.getPref('revertMaxRevisions'),
rvprop: [ 'ids', 'timestamp', 'user' ],
rvprop: ['ids', 'timestamp', 'user'],
curtimestamp: '',
meta: 'tokens',
type: 'csrf',
Expand All @@ -429,7 +429,7 @@ Twinkle.rollback.revertToRevision = function revertToRevision(oldrev) {
inprop: 'watched',
rvlimit: 1,
rvstartid: oldrev,
rvprop: [ 'ids', 'user' ],
rvprop: ['ids', 'user'],
curtimestamp: '',
meta: 'tokens',
type: 'csrf',
Expand Down Expand Up @@ -535,39 +535,39 @@ Twinkle.rollback.callbacks = {
const lastuser = top.user;

if (lastrevid < params.revid) {
Morebits.Status.error('Error', [ 'The most recent revision ID received from the server, ', Morebits.htmlNode('strong', lastrevid), ', is less than the ID of the displayed revision. This could indicate that the current revision has been deleted, the server is lagging, or that bad data has been received. Stopping revert.' ]);
Morebits.Status.error('Error', ['The most recent revision ID received from the server, ', Morebits.htmlNode('strong', lastrevid), ', is less than the ID of the displayed revision. This could indicate that the current revision has been deleted, the server is lagging, or that bad data has been received. Stopping revert.']);
return;
}

// Used for user-facing alerts, messages, etc., not edits or summaries
let userNorm = params.user || Twinkle.rollback.hiddenName;
let index = 1;
if (params.revid !== lastrevid) {
Morebits.Status.warn('Warning', [ 'Latest revision ', Morebits.htmlNode('strong', lastrevid), ' doesn\'t equal our revision ', Morebits.htmlNode('strong', params.revid) ]);
Morebits.Status.warn('Warning', ['Latest revision ', Morebits.htmlNode('strong', lastrevid), ' doesn\'t equal our revision ', Morebits.htmlNode('strong', params.revid)]);
// Treat ipv6 users on same 64 block as the same
if (lastuser === params.user || (mw.util.isIPv6Address(params.user) && Morebits.ip.get64(lastuser) === Morebits.ip.get64(params.user))) {
switch (params.type) {
case 'vand':
var diffUser = lastuser !== params.user;
Morebits.Status.info('Info', [ 'Latest revision was ' + (diffUser ? '' : 'also ') + 'made by ', Morebits.htmlNode('strong', userNorm),
diffUser ? ', which is on the same /64 subnet' : '', '. As we assume vandalism, we will proceed to revert.' ]);
Morebits.Status.info('Info', ['Latest revision was ' + (diffUser ? '' : 'also ') + 'made by ', Morebits.htmlNode('strong', userNorm),
diffUser ? ', which is on the same /64 subnet' : '', '. As we assume vandalism, we will proceed to revert.']);
break;
case 'agf':
Morebits.Status.warn('Warning', [ 'Latest revision was made by ', Morebits.htmlNode('strong', userNorm), '. As we assume good faith, we will stop the revert, as the problem might have been fixed.' ]);
Morebits.Status.warn('Warning', ['Latest revision was made by ', Morebits.htmlNode('strong', userNorm), '. As we assume good faith, we will stop the revert, as the problem might have been fixed.']);
return;
default:
Morebits.Status.warn('Notice', [ 'Latest revision was made by ', Morebits.htmlNode('strong', userNorm), ', but we will stop the revert.' ]);
Morebits.Status.warn('Notice', ['Latest revision was made by ', Morebits.htmlNode('strong', userNorm), ', but we will stop the revert.']);
return;
}
} else if (params.type === 'vand' &&
// Okay to test on user since it will either fail or sysop will correctly access it
// Besides, none of the trusted bots are going to be revdel'd
Twinkle.rollback.trustedBots.includes(top.user) && revs.length > 1 &&
revs[1].revid === params.revid) {
Morebits.Status.info('Info', [ 'Latest revision was made by ', Morebits.htmlNode('strong', lastuser), ', a trusted bot, and the revision before was made by our vandal, so we will proceed with the revert.' ]);
Morebits.Status.info('Info', ['Latest revision was made by ', Morebits.htmlNode('strong', lastuser), ', a trusted bot, and the revision before was made by our vandal, so we will proceed with the revert.']);
index = 2;
} else {
Morebits.Status.error('Error', [ 'Latest revision was made by ', Morebits.htmlNode('strong', lastuser), ', so it might have already been reverted, we will stop the revert.']);
Morebits.Status.error('Error', ['Latest revision was made by ', Morebits.htmlNode('strong', lastuser), ', so it might have already been reverted, we will stop the revert.']);
return;
}

Expand All @@ -581,26 +581,26 @@ Twinkle.rollback.callbacks = {
if (Twinkle.rollback.trustedBots.includes(params.user)) {
switch (params.type) {
case 'vand':
Morebits.Status.info('Info', [ 'Vandalism revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. As this is a trusted bot, we assume you wanted to revert vandalism made by the previous user instead.' ]);
Morebits.Status.info('Info', ['Vandalism revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. As this is a trusted bot, we assume you wanted to revert vandalism made by the previous user instead.']);
index = 2;
params.user = revs[1].user;
params.userHidden = !!revs[1].userhidden;
break;
case 'agf':
Morebits.Status.warn('Notice', [ 'Good faith revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. This is a trusted bot and thus AGF rollback will not proceed.' ]);
Morebits.Status.warn('Notice', ['Good faith revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. This is a trusted bot and thus AGF rollback will not proceed.']);
return;
case 'norm':
/* falls through */
default:
var cont = confirm('Normal revert was chosen, but the most recent edit was made by a trusted bot (' + userNorm + '). Do you want to revert the revision before instead?');
if (cont) {
Morebits.Status.info('Info', [ 'Normal revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. This is a trusted bot, and per confirmation, we\'ll revert the previous revision instead.' ]);
Morebits.Status.info('Info', ['Normal revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. This is a trusted bot, and per confirmation, we\'ll revert the previous revision instead.']);
index = 2;
params.user = revs[1].user;
params.userHidden = !!revs[1].userhidden;
userNorm = params.user || Twinkle.rollback.hiddenName;
} else {
Morebits.Status.warn('Notice', [ 'Normal revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. This is a trusted bot, but per confirmation, revert on selected revision will proceed.' ]);
Morebits.Status.warn('Notice', ['Normal revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. This is a trusted bot, but per confirmation, revert on selected revision will proceed.']);
}
break;
}
Expand All @@ -626,7 +626,7 @@ Twinkle.rollback.callbacks = {
}

if (!found) {
statelem.error([ 'No previous revision found. Perhaps ', Morebits.htmlNode('strong', userNorm), ' is the only contributor, or they have made more than ' + mw.language.convertNumber(Twinkle.getPref('revertMaxRevisions')) + ' edits in a row.' ]);
statelem.error(['No previous revision found. Perhaps ', Morebits.htmlNode('strong', userNorm), ' is the only contributor, or they have made more than ' + mw.language.convertNumber(Twinkle.getPref('revertMaxRevisions')) + ' edits in a row.']);
return;
}

Expand All @@ -651,7 +651,7 @@ Twinkle.rollback.callbacks = {
params.gooduser = good_revision.user;
params.gooduserHidden = !!good_revision.userhidden;

statelem.status([ ' revision ', Morebits.htmlNode('strong', params.goodid), ' that was made ', Morebits.htmlNode('strong', mw.language.convertNumber(count)), ' revisions ago by ', Morebits.htmlNode('strong', params.gooduserHidden ? Twinkle.rollback.hiddenName : params.gooduser) ]);
statelem.status([' revision ', Morebits.htmlNode('strong', params.goodid), ' that was made ', Morebits.htmlNode('strong', mw.language.convertNumber(count)), ' revisions ago by ', Morebits.htmlNode('strong', params.gooduserHidden ? Twinkle.rollback.hiddenName : params.gooduser)]);

let summary, extra_summary;
switch (params.type) {
Expand Down Expand Up @@ -763,7 +763,7 @@ Twinkle.rollback.callbacks = {
wikipedia_api.post();

},
complete: function (apiobj) {
complete: function(apiobj) {
// TODO Most of this is copy-pasted from Morebits.wiki.Page#fnSaveSuccess. Unify it
const response = apiobj.getResponse();
const edit = response.edit;
Expand All @@ -777,7 +777,7 @@ Twinkle.rollback.callbacks = {
const params = apiobj.params;

if (params.notifyUser && !params.userHidden) { // notifyUser only from main, not from toRevision
Morebits.Status.info('Info', [ 'Opening user talk page edit form for user ', Morebits.htmlNode('strong', params.user) ]);
Morebits.Status.info('Info', ['Opening user talk page edit form for user ', Morebits.htmlNode('strong', params.user)]);

const url = mw.util.getUrl('User talk:' + params.user, {
action: 'edit',
Expand Down
Loading
Loading