MediaWiki:Gadget-morebits.js: Difference between revisions
Content deleted Content added
Repo at 5152750: revert $.extend autofixes (#2107); autofix some eslint unicorn/prefer-string-slice (#2089) |
Repo at ac3c1e3: replace es-x/no-array-prototype-includes with unicorn/prefer-includes (#2125) |
||
(One intermediate revision by the same user not shown) | |||
Line 132:
*/
Morebits.userIsInGroup = function (group) {
return mw.config.get('wgUserGroups').
};
/**
Line 267:
namespaces = [namespaces];
}
let regex; $.each(mw.config.get('wgNamespaceIds'), (name, number) => {
if (namespaces.
// Namespaces are completely agnostic as to case,
// and a regex string is more useful/compatible than a RegExp object,
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,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'].
},
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,651 ⟶ 1,654:
if (result && params.term &&
data.text.toUpperCase().
result.children = data.children;
}
Line 1,812 ⟶ 1,815:
if (digitMatch) {
// ..... year ... month .. date ... hour .... minute ..... second
this.
}
} else if (typeof param === 'string') {
Line 1,818 ⟶ 1,821:
const dateParts = Morebits.l10n.signatureTimestampFormat(param);
if (dateParts) {
this.
}
}
}
if (!this.
// Try standard date
this.
}
Line 2,146 ⟶ 2,149:
Object.getOwnPropertyNames(Date.prototype).forEach((func) => {
Morebits.date.prototype[func] = function() {
return this.
};
});
Line 2,282 ⟶ 2,285:
this.query.assert = 'user';
// Enforce newer error formats, preferring html
if (!query.errorformat || !['wikitext', 'plaintext'].
this.query.errorformat = 'html';
}
Line 2,303 ⟶ 2,306:
} else if (query.format === 'json' && !query.formatversion) {
this.query.formatversion = '2';
} else if (!['xml', 'json'].
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'].
delete query.tags;
} else if (!query.tags && morebitsWikiChangeTag) {
Line 2,898 ⟶ 2,901:
}
if (['recreate', 'createonly', 'nocreate'].
query[ctx.createOption] = '';
}
Line 3,430 ⟶ 3,433:
/** @return {boolean} whether or not you can edit the page */
this.canEdit = function() {
return !!ctx.testActions && ctx.testActions.
};
Line 3,592 ⟶ 3,595:
this.triage = function() {
// Fall back to patrol if not a valid triage namespace
if (!mw.config.get('pageTriageNamespaces').
this.patrol();
} else {
Line 3,776 ⟶ 3,779:
// so this neatly handles nonexistent pages
const editRestriction = mw.config.get('wgRestrictionEdit');
if (!editRestriction || editRestriction.
return false;
}
Line 3,832 ⟶ 3,835:
}
let rev;
ctx.pageExists = !page.missing;
if (ctx.pageExists) {
Line 4,228 ⟶ 4,232:
// No undelete as an existing page could have deleted revisions
const actionMissing = missing && ['delete', 'stabilize', 'move'].
const protectMissing = action === 'protect' && missing && (ctx.protectEdit || ctx.protectMove);
const saltMissing = action === 'protect' && !missing && ctx.protectCreate;
Line 4,941 ⟶ 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].
const colon = isFileOrCategory ? ':' : ':?';
Line 5,232 ⟶ 5,236:
Morebits.status.errorEvent = handler;
} else {
throw new Error('Morebits.status.onError: handler is not a function');
}
};
|