MediaWiki:Gadget-morebits.js: Difference between revisions

Content deleted Content added
Repo at 001f236: simplify IIFEs (#2074); apply autofixes 3 (#2079); apply autofixes 2 (#2069)
Repo at ac3c1e3: replace es-x/no-array-prototype-includes with unicorn/prefer-includes (#2125)
 
(3 intermediate revisions by the same user not shown)
Line 132:
*/
Morebits.userIsInGroup = function (group) {
return mw.config.get('wgUserGroups').indexOfincludes(group) !== -1;
};
/**
Line 267:
namespaces = [namespaces];
}
letconst aliases = [],;
let regex;
$.each(mw.config.get('wgNamespaceIds'), (name, number) => {
if (namespaces.indexOfincludes(number) !== -1) {
// Namespaces are completely agnostic as to case,
// and a regex string is more useful/compatible than a RegExp object,
Line 602 ⟶ 603:
});
$.each(tmpgroup, (idx, el) => {
const newEl = Object$.assignextend({}, el);
if (!newEl.type) {
newEl.type = data.type;
Line 759 ⟶ 760:
 
data.inputs.forEach((subdata) => {
const cell = new Morebits.quickForm.element(Object$.assignextend(subdata, { type: '_dyninput_cell' }));
node.appendChild(cell.render());
});
Line 935 ⟶ 936:
*
* @memberof Morebits.quickForm.element
* @requires jqueryjQuery.ui
* @param {HTMLElement} node - The HTML element beside which a tooltip is to be generated.
* @param {Object} data - Tooltip-related configuration data.
Line 1,405 ⟶ 1,406:
ipv6 = Morebits.ip.sanitizeIPv6(ipv6);
const ip_re = /^((?:[0-9A-F]{1,4}:){4})(?:[0-9A-F]{1,4}:){3}[0-9A-F]{1,4}(?:\/\d{1,3})?$/;
// eslint-disable-next-line no-useless-concat
return ipv6.replace(ip_re, '$1' + '0:0:0:0/64');
}
Line 1,422 ⟶ 1,424:
toUpperCaseFirstChar: function(str) {
str = str.toString();
return str.substrslice(0, 1).toUpperCase() + str.substrslice(1);
},
/**
Line 1,430 ⟶ 1,432:
toLowerCaseFirstChar: function(str) {
str = str.toString();
return str.substrslice(0, 1).toLowerCase() + str.substrslice(1);
},
 
Line 1,501 ⟶ 1,503:
let reason = (str || '').toString().trim();
const unbinder = new Morebits.unbinder(reason);
// eslint-disable-next-line no-useless-concat
unbinder.unbind('<no' + 'wiki>', '</no' + 'wiki>');
unbinder.content = unbinder.content.replace(/\|/g, '{{subst:!}}');
Line 1,555 ⟶ 1,558:
*/
isInfinity: function morebitsStringIsInfinity(expiry) {
return ['indefinite', 'infinity', 'infinite', 'never'].indexOfincludes(expiry) !== -1;
},
 
Line 1,586 ⟶ 1,589:
uniq: function(arr) {
if (!Array.isArray(arr)) {
throw new Error('A non-array object passed to Morebits.array.uniq');
}
return arr.filter((item, idx) => arr.indexOf(item) === idx);
Line 1,601 ⟶ 1,604:
dups: function(arr) {
if (!Array.isArray(arr)) {
throw new Error('A non-array object passed to Morebits.array.dups');
}
return arr.filter((item, idx) => arr.indexOf(item) !== idx);
Line 1,616 ⟶ 1,619:
chunk: function(arr, size) {
if (!Array.isArray(arr)) {
throw new Error('A non-array object passed to Morebits.array.chunk');
}
if (typeof size !== 'number' || size <= 0) { // pretty impossible to do anything :)
Line 1,638 ⟶ 1,641:
* @namespace Morebits.select2
* @memberof Morebits
* @requires jqueryjQuery.select2
*/
Morebits.select2 = {
Line 1,651 ⟶ 1,654:
 
if (result && params.term &&
data.text.toUpperCase().indexOfincludes(params.term.toUpperCase()) !== -1) {
result.children = data.children;
}
Line 1,702 ⟶ 1,705:
return;
}
let $target = $(ev.target).closest('.select2-container');
if (!$target.length) {
return;
}
$target = $target.prev();
$target.select2('open');
const search = $target.data('select2').dropdown.$search ||
$target.data('select2').selection.$search;
// Use DOM .focus() to work around a jQuery 3.6.0 regression (https://github.com/select2/select2/issues/5993)
search[0].focus();
Line 1,812 ⟶ 1,815:
if (digitMatch) {
// ..... year ... month .. date ... hour .... minute ..... second
this._dprivateDate = new Date(Date.UTC.apply(null, [digitMatch[1], digitMatch[2] - 1, digitMatch[3], digitMatch[4], digitMatch[5], digitMatch[6]]));
}
} else if (typeof param === 'string') {
Line 1,818 ⟶ 1,821:
const dateParts = Morebits.l10n.signatureTimestampFormat(param);
if (dateParts) {
this._dprivateDate = new Date(Date.UTC.apply(null, dateParts));
}
}
}
 
if (!this._dprivateDate) {
// Try standard date
this._dprivateDate = new (Function.prototype.bind.apply(Date, [Date].concat(args)))();
}
 
Line 1,972 ⟶ 1,975:
// Probably can't be used for Julian->Gregorian changeovers, etc.
if (unitNorm === 'Week') {
unitNorm = 'Date', ;
num *= 7;
}
this['set' + unitNorm](this['get' + unitNorm]() + num);
Line 2,145 ⟶ 2,149:
Object.getOwnPropertyNames(Date.prototype).forEach((func) => {
Morebits.date.prototype[func] = function() {
return this._dprivateDate[func].apply(this._dprivateDate, Array.prototype.slice.call(arguments));
};
});
Line 2,281 ⟶ 2,285:
this.query.assert = 'user';
// Enforce newer error formats, preferring html
if (!query.errorformat || !['wikitext', 'plaintext'].indexOfincludes(query.errorformat) === -1) {
this.query.errorformat = 'html';
}
Line 2,302 ⟶ 2,306:
} else if (query.format === 'json' && !query.formatversion) {
this.query.formatversion = '2';
} else if (!['xml', 'json'].indexOfincludes(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'].indexOfincludes(query.action) !== -1) {
delete query.tags;
} else if (!query.tags && morebitsWikiChangeTag) {
Line 2,348 ⟶ 2,352:
* @param {Object} callerAjaxParameters - Do not specify a parameter unless you really
* really want to give jQuery some extra parameters.
* @return {promisejQuery.Promise} - A jQuery promise object that is resolved or rejected with the api object.
*/
post: function(callerAjaxParameters) {
Line 2,363 ⟶ 2,367:
// token should always be the last item in the query string (bug TW-B-0013)
 
const ajaxparams = Object$.assignextend({}, {
context: this,
type: this.query.action === 'query' ? 'GET' : 'POST',
Line 2,897 ⟶ 2,901:
}
 
if (['recreate', 'createonly', 'nocreate'].indexOfincludes(ctx.createOption) !== -1) {
query[ctx.createOption] = '';
}
Line 3,429 ⟶ 3,433:
/** @return {boolean} whether or not you can edit the page */
this.canEdit = function() {
return !!ctx.testActions && ctx.testActions.indexOfincludes('edit') !== -1;
};
 
Line 3,591 ⟶ 3,595:
this.triage = function() {
// Fall back to patrol if not a valid triage namespace
if (!mw.config.get('pageTriageNamespaces').indexOfincludes(new mw.Title(ctx.pageName).getNamespaceId()) === -1) {
this.patrol();
} else {
Line 3,775 ⟶ 3,779:
// so this neatly handles nonexistent pages
const editRestriction = mw.config.get('wgRestrictionEdit');
if (!editRestriction || editRestriction.indexOfincludes('sysop') !== -1) {
return false;
}
Line 3,831 ⟶ 3,835:
}
 
letconst page = response.pages[0], rev;
let rev;
ctx.pageExists = !page.missing;
if (ctx.pageExists) {
Line 4,227 ⟶ 4,232:
 
// No undelete as an existing page could have deleted revisions
const actionMissing = missing && ['delete', 'stabilize', 'move'].indexOfincludes(action) !== -1;
const protectMissing = action === 'protect' && missing && (ctx.protectEdit || ctx.protectMove);
const saltMissing = action === 'protect' && !missing && ctx.protectCreate;
Line 4,830 ⟶ 4,835:
// Nothing found yet, this must be the template name
if (count === -1) {
result.name = current.substringslice(2).trim();
++count;
} else {
Line 4,940 ⟶ 4,945:
// For most namespaces, unlink both [[User:Test]] and [[:User:Test]]
// For files and categories, only unlink [[:Category:Test]]. Do not unlink [[Category:Test]]
const isFileOrCategory = [6, 14].indexOfincludes(namespaceID) !== -1;
const colon = isFileOrCategory ? ':' : ':?';
 
Line 5,148 ⟶ 5,153:
* @param {string} logText - Doesn't include leading `#` or `*`.
* @param {string} summaryText - Edit summary.
* @return {JQueryjQuery.Promise}
*/
this.log = function(logText, summaryText) {
Line 5,231 ⟶ 5,236:
Morebits.status.errorEvent = handler;
} else {
throw new Error('Morebits.status.onError: handler is not a function');
}
};
Line 5,424 ⟶ 5,429:
const thisCb = this;
if (event.shiftKey && lastCheckbox !== null) {
const $cbs = $(jQuerySelector, jQueryContext); // can't cache them, obviously, if we want to support resortingre-sorting
let index = -1, lastIndex = -1, i;
for (i = 0; i < $cbs.length; i++) {
if ($cbs[i] === thisCb) {
index = i;
if (lastIndex > -1) {
Line 5,433 ⟶ 5,438:
}
}
if ($cbs[i] === lastCheckbox) {
lastIndex = i;
if (index > -1) {
Line 5,454 ⟶ 5,459:
 
for (i = start; i <= finish; i++) {
if ($cbs[i].checked !== endState) {
$cbs[i].click();
}
}
Line 5,765 ⟶ 5,770:
* @memberof Morebits
* @class
* @requires jqueryjQuery.ui.dialog
* @param {number} width
* @param {number} height - The maximum allowable height for the content area.
Line 6,078 ⟶ 6,083:
$('.morebits-dialog-buttons button').prop('disabled', !enabled);
};
 
// Create capital letter aliases for all Morebits @classes (functions that work with the `new` keyword), to follow the coding convention that classes should start with an uppercase letter. This will let us start fixing ESLint `new-cap` errors in other files.
Morebits.BatchOperation = Morebits.batchOperation;
Morebits.Date = Morebits.date;
Morebits.QuickForm = Morebits.quickForm;
Morebits.QuickForm.Element = Morebits.quickForm.element;
Morebits.SimpleWindow = Morebits.simpleWindow;
Morebits.Status = Morebits.status;
Morebits.TaskManager = Morebits.taskManager;
Morebits.Unbinder = Morebits.unbinder;
Morebits.UserspaceLogger = Morebits.userspaceLogger;
Morebits.wiki.Api = Morebits.wiki.api;
Morebits.wiki.Page = Morebits.wiki.page;
Morebits.wiki.Preview = Morebits.wiki.preview;
Morebits.wikitext.Page = Morebits.wikitext.page;
 
}());