MediaWiki:Gadget-morebits.js: Difference between revisions

Content deleted Content added
Repo at e7d4c6c: fix some no-jquery/no-extend autofixes (#2088); create capitalized aliases for classes (#2086); fix linter error no-sequences (#2083); fix linter error jsdoc/no-undefined-types (#2082); fix linter error no-jquery/variable-pattern (#2081)
Repo at ac3c1e3: replace es-x/no-array-prototype-includes with unicorn/prefer-includes (#2125)
 
(2 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 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,651 ⟶ 1,654:
 
if (result && params.term &&
data.text.toUpperCase().indexOfincludes(params.term.toUpperCase()) !== -1) {
result.children = data.children;
}
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 2,146 ⟶ 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,282 ⟶ 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,303 ⟶ 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,364 ⟶ 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,898 ⟶ 2,901:
}
 
if (['recreate', 'createonly', 'nocreate'].indexOfincludes(ctx.createOption) !== -1) {
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.indexOfincludes('edit') !== -1;
};
 
Line 3,592 ⟶ 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,776 ⟶ 3,779:
// so this neatly handles nonexistent pages
const editRestriction = mw.config.get('wgRestrictionEdit');
if (!editRestriction || editRestriction.indexOfincludes('sysop') !== -1) {
return false;
}
Line 3,832 ⟶ 3,835:
}
 
letconst page = response.pages[0], rev;
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'].indexOfincludes(action) !== -1;
const protectMissing = action === 'protect' && missing && (ctx.protectEdit || ctx.protectMove);
const saltMissing = action === 'protect' && !missing && ctx.protectCreate;
Line 4,831 ⟶ 4,835:
// Nothing found yet, this must be the template name
if (count === -1) {
result.name = current.substringslice(2).trim();
++count;
} else {
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].indexOfincludes(namespaceID) !== -1;
const colon = isFileOrCategory ? ':' : ':?';
 
Line 5,232 ⟶ 5,236:
Morebits.status.errorEvent = handler;
} else {
throw new Error('Morebits.status.onError: handler is not a function');
}
};