MediaWiki:Gadget-morebits.js: Difference between revisions
Content deleted Content added
Repo at 3da72fd: apply autofixes 1 (#2058) |
Repo at ac3c1e3: replace es-x/no-array-prototype-includes with unicorn/prefer-includes (#2125) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 34:
*/
(function() {
/** @lends Morebits */
const Morebits = {};
window.Morebits = Morebits;
/**
Line 50 ⟶ 49:
* Examples:
* Use jquery-i18n:
*
* Use banana-i18n or orange-i18n:
*
*
*▼
* @param {Object} parser
*/
Line 64:
/**
* @private
* @
*/
getMessage: function () {
Line 89:
// shortcut
const msg = Morebits.i18n.getMessage;
/**
Line 106 ⟶ 105:
* in the format [year, month, date, hour, minute, second]
* which can be passed to Date.UTC()
*
* @param {string} str
* @
*/
signatureTimestampFormat: function (str) {
Line 124:
}
};
/**
Line 130 ⟶ 129:
*
* @param {string} group - e.g. `sysop`, `extendedconfirmed`, etc.
* @
*/
Morebits.userIsInGroup = function (group) {
return mw.config.get('wgUserGroups').
};
/**
*
* @type {boolean}
Line 151:
*
* @param {string} address - The IPv6 address, with or without CIDR.
* @
*/
Morebits.sanitizeIPv6 = function (address) {
Line 163:
* detect Module:RfD, with the same failure points.
*
* @
*/
Morebits.isPageRedirect = function() {
Line 176:
*/
Morebits.pageNameNorm = mw.config.get('wgPageName').replace(/_/g, ' ');
/**
Line 184 ⟶ 183:
*
* @param {string} pageName - Page name without namespace.
* @
*/
Morebits.pageNameRegex = function(pageName) {
Line 202 ⟶ 201:
* Wikilink syntax (`[[...]]`) is transformed into HTML anchor.
* Used in Morebits.quickForm and Morebits.status
*▼
* @internal
* @param {string|Node|(string|Node)[]} input
* @
*/
Morebits.createHtml = function(input) {
Line 228:
/**
* Converts wikilinks to HTML anchor tags.
*
* @param text
* @
*/
Morebits.createHtml.renderWikilinks = function (text) {
Line 260 ⟶ 261:
* // returns '(?:[Ff][Ii][Ll][Ee]|[Ii][Mm][Aa][Gg][Ee])'
* Morebits.namespaceRegex([6])
* @
*/
Morebits.namespaceRegex = function(namespaces) {
Line 266 ⟶ 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 288 ⟶ 290:
return regex;
};
/* **************** Morebits.quickForm **************** */
Line 308 ⟶ 309:
*
* @memberof Morebits.quickForm
* @
*/
Morebits.quickForm.prototype.render = function QuickFormRender() {
Line 322 ⟶ 323:
* @param {(object|Morebits.quickForm.element)} data - A quickform element, or the object with which
* a quickform element is constructed.
* @
*/
Morebits.quickForm.prototype.append = function QuickFormAppend(data) {
Line 374 ⟶ 375:
* @memberof Morebits.quickForm
* @class
* @param {
* specify one of the available types from the index above, as well as any
* relevant and available attributes.
Line 402 ⟶ 403:
* @param {Morebits.quickForm.element} data - A quickForm element or the object required to
* create the quickForm element.
* @
*/
Morebits.quickForm.element.prototype.append = function QuickFormElementAppend(data) {
Line 420 ⟶ 421:
*
* @memberof Morebits.quickForm.element
* @
*/
Morebits.quickForm.element.prototype.render = function QuickFormElementRender(internal_subgroup_id) {
Line 431 ⟶ 432:
return currentNode[0];
};
/** @memberof Morebits.quickForm.element */
Line 936:
*
* @memberof Morebits.quickForm.element
* @requires
* @param {HTMLElement} node - The HTML element beside which a tooltip is to be generated.
* @param {
*/
Morebits.quickForm.element.generateTooltip = function QuickFormElementGenerateTooltip(node, data) {
Line 951:
});
};
// Some utility methods for manipulating quickForms after their creation:
Line 962 ⟶ 961:
* @memberof Morebits.quickForm
* @param {HTMLFormElement} form
* @
*/
Morebits.quickForm.getInputData = function(form) {
Line 1,015 ⟶ 1,014:
return result;
};
/**
Line 1,023 ⟶ 1,021:
* @param {HTMLFormElement} form
* @param {string} fieldName - The name or id of the fields.
* @
*/
Morebits.quickForm.getElements = function QuickFormGetElements(form, fieldName) {
Line 1,043 ⟶ 1,041:
* @param {HTMLInputElement[]} elementArray - Array of checkbox or radio elements.
* @param {string} value - Value to search for.
* @
*/
Morebits.quickForm.getCheckboxOrRadio = function QuickFormGetCheckboxOrRadio(elementArray, value) {
Line 1,059 ⟶ 1,057:
* @memberof Morebits.quickForm
* @param {HTMLElement} element
* @
*/
Morebits.quickForm.getElementContainer = function QuickFormGetElementContainer(element) {
Line 1,078 ⟶ 1,076:
* @memberof Morebits.quickForm
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @
*/
Morebits.quickForm.getElementLabelObject = function QuickFormGetElementLabelObject(element) {
Line 1,101 ⟶ 1,099:
* @memberof Morebits.quickForm
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @
*/
Morebits.quickForm.getElementLabel = function QuickFormGetElementLabel(element) {
Line 1,118 ⟶ 1,116:
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @param {string} labelText
* @
*/
Morebits.quickForm.setElementLabel = function QuickFormSetElementLabel(element, labelText) {
Line 1,136 ⟶ 1,134:
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @param {string} temporaryLabelText
* @
*/
Morebits.quickForm.overrideElementLabel = function QuickFormOverrideElementLabel(element, temporaryLabelText) {
Line 1,150 ⟶ 1,148:
* @memberof Morebits.quickForm
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @
*/
Morebits.quickForm.resetElementLabel = function QuickFormResetElementLabel(element) {
Line 1,180 ⟶ 1,178:
$(Morebits.quickForm.getElementContainer(element)).find('.morebits-tooltipButton').toggle(visibility);
};
/**
Line 1,189 ⟶ 1,185:
* Get checked items in the form.
*
* @
* @param {string} name - Find checked property of elements (i.e. a checkbox
* or a radiobutton) with the given name, or select options that have selected
Line 1,195 ⟶ 1,191:
* @param {string} [type] - Optionally specify either radio or checkbox (for
* the event that both checkboxes and radiobuttons have the same name).
* @
* checked property set to true.
*/
Line 1,243 ⟶ 1,239:
* Does the same as {@link HTMLFormElement.getChecked|getChecked}, but with unchecked elements.
*
* @
* @param {string} name - Find checked property of elements (i.e. a checkbox
* or a radiobutton) with the given name, or select options that have selected
Line 1,249 ⟶ 1,245:
* @param {string} [type] - Optionally specify either radio or checkbox (for
* the event that both checkboxes and radiobuttons have the same name).
* @
* checked property set to true.
*/
Line 1,308 ⟶ 1,304:
*
* @param {string} address - The IPv6 address, with or without CIDR.
* @
*/
sanitizeIPv6: function (address) {
Line 1,361 ⟶ 1,357:
*
* @param {string} ip
* @
*/
isRange: function (ip) {
Line 1,372 ⟶ 1,368:
* for IPv4 and /32 for IPv6.
*
* @
* otherwise false (ranges outside the limit, single IPs, non-IPs).
*/
Line 1,397 ⟶ 1,393:
*
* @param {string} ipv6 - The IPv6 address, with or without a subnet.
* @
* otherwise the (sanitized) /64 address.
*/
Line 1,410 ⟶ 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,424 ⟶ 1,420:
/**
* @param {string} str
* @
*/
toUpperCaseFirstChar: function(str) {
str = str.toString();
return str.
},
/**
* @param {string} str
* @
*/
toLowerCaseFirstChar: function(str) {
str = str.toString();
return str.
},
Line 1,448 ⟶ 1,444:
* @param {string} end
* @param {(string[]|string)} [skiplist]
* @
* @throws If the `start` and `end` strings aren't of the same length.
* @throws If `skiplist` isn't an array or string
Line 1,502 ⟶ 1,498:
* @param {string} str
* @param {boolean} [addSig]
* @
*/
formatReasonText: function(str, addSig) {
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,525 ⟶ 1,522:
*
* @param {string} str
* @
*/
formatReasonForLog: function(str) {
Line 1,545 ⟶ 1,542:
* @param {(string|RegExp)} pattern
* @param {string} replacement
* @
*/
safeReplace: function morebitsStringSafeReplace(string, pattern, replacement) {
Line 1,558 ⟶ 1,555:
*
* @param {string} expiry
* @
*/
isInfinity: function morebitsStringIsInfinity(expiry) {
return ['indefinite', 'infinity', 'infinite', 'never'].
},
Line 1,569 ⟶ 1,566:
*
* @param {string} text - String to be escaped.
* @
*/
escapeRegExp: function(text) {
Line 1,575 ⟶ 1,572:
}
};
/**
Line 1,588 ⟶ 1,584:
*
* @param {Array} arr
* @
* @throws When provided a non-array.
*/
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,602 ⟶ 1,598:
*
* @param {Array} arr
* @
* removed; subsequent instances of those values (duplicates) remain.
* @throws When provided a non-array.
Line 1,608 ⟶ 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,619 ⟶ 1,614:
* @param {Array} arr
* @param {number} size - Size of each chunk (except the last, which could be different).
* @
* @throws When provided a non-array.
*/
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,646 ⟶ 1,641:
* @namespace Morebits.select2
* @memberof Morebits
* @requires
*/
Morebits.select2 = {
Line 1,659 ⟶ 1,654:
if (result && params.term &&
data.text.toUpperCase().
result.children = data.children;
}
Line 1,710 ⟶ 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,723 ⟶ 1,718:
};
/**
Line 1,770 ⟶ 1,764:
* Restore the hidden portion of the `content` string.
*
* @
*/
rebind: function UnbinderRebind() {
Line 1,797 ⟶ 1,791:
};
};
/* **************** Morebits.date **************** */
Line 1,823 ⟶ 1,815:
if (digitMatch) {
// ..... year ... month .. date ... hour .... minute ..... second
this.
}
} else if (typeof param === 'string') {
Line 1,829 ⟶ 1,821:
const dateParts = Morebits.l10n.signatureTimestampFormat(param);
if (dateParts) {
this.
}
}
}
if (!this.
// Try standard date
this.
}
Line 1,909 ⟶ 1,901:
Morebits.date.prototype = {
/** @
isValid: function() {
return !isNaN(this.getTime());
Line 1,916 ⟶ 1,908:
/**
* @param {(Date|Morebits.date)} date
* @
*/
isBefore: function(date) {
Line 1,923 ⟶ 1,915:
/**
* @param {(Date|Morebits.date)} date
* @
*/
isAfter: function(date) {
Line 1,929 ⟶ 1,921:
},
/** @
getUTCMonthName: function() {
return Morebits.date.localeData.months[this.getUTCMonth()];
},
/** @
getUTCMonthNameAbbrev: function() {
return Morebits.date.localeData.monthsShort[this.getUTCMonth()];
},
/** @
getMonthName: function() {
return Morebits.date.localeData.months[this.getMonth()];
},
/** @
getMonthNameAbbrev: function() {
return Morebits.date.localeData.monthsShort[this.getMonth()];
},
/** @
getUTCDayName: function() {
return Morebits.date.localeData.days[this.getUTCDay()];
},
/** @
getUTCDayNameAbbrev: function() {
return Morebits.date.localeData.daysShort[this.getUTCDay()];
},
/** @
getDayName: function() {
return Morebits.date.localeData.days[this.getDay()];
},
/** @
getDayNameAbbrev: function() {
return Morebits.date.localeData.daysShort[this.getDay()];
Line 1,969 ⟶ 1,961:
* @param {string} unit
* @throws If invalid or unsupported unit is given.
* @
*/
add: function(number, unit) {
Line 1,983 ⟶ 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 1,998 ⟶ 1,991:
* @param {string} unit
* @throws If invalid or unsupported unit is given.
* @
*/
subtract: function(number, unit) {
Line 2,038 ⟶ 2,031:
* @param {(string|number)} [zone=system] - `system` (for browser-default time zone),
* `utc`, or specify a time zone as number of minutes relative to UTC.
* @
*/
format: function(formatstr, zone) {
Line 2,095 ⟶ 2,088:
* @param {(string|number)} [zone=system] - 'system' (for browser-default time zone),
* 'utc' (for UTC), or specify a time zone as number of minutes past UTC.
* @
*/
calendar: function(zone) {
Line 2,122 ⟶ 2,115:
* as `==December 2019==` or `=== Jan 2018 ===`.
*
* @
*/
monthHeaderRegex: function() {
Line 2,134 ⟶ 2,127:
* @param {number} [level=2] - Header level. Pass 0 for just the text
* with no wikitext markers (==).
* @
*/
monthHeader: function(level) {
Line 2,156 ⟶ 2,149:
Object.getOwnPropertyNames(Date.prototype).forEach((func) => {
Morebits.date.prototype[func] = function() {
return this.
};
});
/* **************** Morebits.wiki **************** */
Line 2,174 ⟶ 2,166:
* @deprecated in favor of Morebits.isPageRedirect as of November 2020
* @memberof Morebits.wiki
* @
*/
Morebits.wiki.isPageRedirect = function wikipediaIsPageRedirect() {
Line 2,180 ⟶ 2,172:
return Morebits.isPageRedirect();
};
/* **************** Morebits.wiki.actionCompleted **************** */
Line 2,266 ⟶ 2,257:
}
};
/* **************** Morebits.wiki.api **************** */
Line 2,285 ⟶ 2,275:
* @class
* @param {string} currentAction - The current action (required).
* @param {
* @param {Function} [onSuccess] - The function to call when request is successful.
* @param {Morebits.status} [statusElement] - A Morebits.status object to use for status messages.
Line 2,295 ⟶ 2,285:
this.query.assert = 'user';
// Enforce newer error formats, preferring html
if (!query.errorformat || !['wikitext', 'plaintext'].
this.query.errorformat = 'html';
}
Line 2,316 ⟶ 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,332 ⟶ 2,322:
onSuccess: null,
onError: null,
parent: window,
query: null,
response: null,
responseXML: null,
statelem: null,
statusText: null, // result received from the API, normally "success" or "error"
errorCode: null, // short text error code, if any, as documented in the MediaWiki API
Line 2,360 ⟶ 2,350:
* Carry out the request.
*
* @param {
* really want to give jQuery some extra parameters.
* @
*/
post: function(callerAjaxParameters) {
Line 2,522 ⟶ 2,512:
morebitsWikiApiUserAgent = (ua ? ua + ' ' : '') + 'morebits.js ([[w:WT:TW]])';
};
/**
Line 2,534 ⟶ 2,522:
*/
var morebitsWikiChangeTag = '';
/**
Line 2,540 ⟶ 2,527:
*
* @memberof Morebits.wiki.api
* @
*/
Morebits.wiki.api.getToken = function() {
Line 2,551 ⟶ 2,538:
return tokenApi.post().then((apiobj) => apiobj.response.query.tokens.csrftoken);
};
/* **************** Morebits.wiki.page **************** */
Line 2,592 ⟶ 2,578:
* 2. The sequence for append/prepend/newSection could be slightly shortened,
* but it would require significant duplication of code for little benefit.
▲ *
*
* @memberof Morebits.wiki
Line 2,621 ⟶ 2,606:
editSummary: null,
changeTags: null,
testActions: null,
callbackParameters: null,
statusElement: status instanceof Morebits.status ? status : new Morebits.status(status),
Line 2,627 ⟶ 2,612:
// - edit
pageText: null,
editMode: 'all',
appendText: null,
prependText: null,
newSectionText: null,
newSectionTitle: null,
Line 2,760 ⟶ 2,745:
if (ctx.editMode === 'all') {
ctx.loadQuery.rvprop = 'content|timestamp';
} else if (ctx.editMode === 'revert') {
ctx.loadQuery.rvprop = 'timestamp';
Line 2,768 ⟶ 2,753:
if (ctx.followRedirect) {
ctx.loadQuery.redirects = '';
}
if (typeof ctx.pageSection === 'number') {
Line 2,823 ⟶ 2,808:
if (ctx.fullyProtected && !ctx.suppressProtectWarning &&
!confirm(
ctx.fullyProtected === 'infinity' ?
'You are about to make an edit to the fully protected page "' + ctx.pageName + '" (protected indefinitely). \n\nClick OK to proceed with the edit, or Cancel to skip this edit.'
) :
'You are about to make an edit to the fully protected page "' + ctx.pageName +
'" (protection expiring ' + new Morebits.date(ctx.fullyProtected).calendar('utc') + ' (UTC)). \n\nClick OK to proceed with the edit, or Cancel to skip this edit.'
Line 2,864 ⟶ 2,849:
query.minor = true;
} else {
query.notminor = true;
}
Line 2,879 ⟶ 2,864:
return;
}
query.appendtext = ctx.appendText;
break;
case 'prepend':
Line 2,887 ⟶ 2,872:
return;
}
query.prependtext = ctx.prependText;
break;
case 'new':
Line 2,896 ⟶ 2,881:
}
query.section = 'new';
query.text = ctx.newSectionText;
query.sectiontitle = ctx.newSectionTitle || ctx.editSummary; // done by the API, but non-'' values would get treated as text
break;
Line 2,916 ⟶ 2,901:
}
if (['recreate', 'createonly', 'nocreate'].
query[ctx.createOption] = '';
}
Line 2,992 ⟶ 2,977:
};
/** @
this.getPageName = function() {
return ctx.pageName;
};
/** @
this.getPageText = function() {
return ctx.pageText;
Line 3,034 ⟶ 3,019:
ctx.newSectionTitle = newSectionTitle;
};
// Edit-related setter methods:
Line 3,059 ⟶ 3,042:
ctx.changeTags = tags;
};
/**
Line 3,069 ⟶ 3,051:
* - `null`: create the page if it does not exist, unless it was deleted
* in the moment between loading the page and saving the edit (default).
▲ *
*/
this.setCreateOption = function(createOption) {
Line 3,332 ⟶ 3,313:
};
/** @
this.getCurrentID = function() {
return ctx.revertCurID;
};
/** @
this.getRevisionUser = function() {
return ctx.revertUser;
};
/** @
this.getLastEditTime = function() {
return ctx.lastEditTime;
Line 3,359 ⟶ 3,340:
* detected upon calling `save()`.
*
* @param {
*/
this.setCallbackParameters = function(callbackParameters) {
Line 3,366 ⟶ 3,347:
/**
* @
*/
this.getCallbackParameters = function() {
Line 3,380 ⟶ 3,361:
/**
* @
*/
this.getStatusElement = function() {
Line 3,396 ⟶ 3,377:
/**
* @
*/
this.exists = function() {
Line 3,403 ⟶ 3,384:
/**
* @
* exist.
*/
Line 3,411 ⟶ 3,392:
/**
* @
* include (but may not be limited to): `wikitext`, `javascript`,
* `css`, `json`, `Scribunto`, `sanitized-css`, `MassMessageListContent`.
Line 3,421 ⟶ 3,402:
/**
* @
* unless it's being watched temporarily, in which case returns the
* expiry string.
Line 3,430 ⟶ 3,411:
/**
* @
*/
this.getLoadTime = function() {
Line 3,437 ⟶ 3,418:
/**
* @
*/
this.getCreator = function() {
Line 3,444 ⟶ 3,425:
/**
* @
*/
this.getCreationTimestamp = function() {
Line 3,450 ⟶ 3,431:
};
/** @
this.canEdit = function() {
return !!ctx.testActions && ctx.testActions.
};
Line 3,497 ⟶ 3,478:
if (ctx.followRedirect) {
query.redirects = '';
}
Line 3,614 ⟶ 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,768 ⟶ 3,749:
* @param {string} [action=edit] - The action being undertaken, e.g.
* "edit" or "delete". In practice, only "edit" or "notedit" matters.
* @
*/
var fnCanUseMwUserToken = function(action = 'edit') {
Line 3,798 ⟶ 3,779:
// so this neatly handles nonexistent pages
const editRestriction = mw.config.get('wgRestrictionEdit');
if (!editRestriction || editRestriction.
return false;
}
Line 3,819 ⟶ 3,800:
* @param {string} action - The action being undertaken, e.g. "edit" or
* "delete".
* @
*/
var fnNeedTokenInfoQuery = function(action) {
Line 3,854 ⟶ 3,835:
}
let rev;
ctx.pageExists = !page.missing;
if (ctx.pageExists) {
Line 3,862 ⟶ 3,844:
ctx.pageID = page.pageid;
} else {
ctx.pageText = '';
ctx.pageID = 0; // nonexistent in response, matches wgArticleId
}
Line 3,911 ⟶ 3,893:
ctx.revertUser = rev && rev.user;
if (!ctx.revertUser) {
if (rev && rev.userhidden) {
ctx.revertUser = '<username hidden>';
} else {
Line 3,926 ⟶ 3,908:
// alert("Generate edit conflict now"); // for testing edit conflict recovery logic
ctx.onLoadSuccess(this);
};
Line 3,984 ⟶ 3,966:
* ensured of knowing the watch status by the use of this.
*
* @
*/
var fnApplyWatchlistExpiry = function() {
Line 4,019 ⟶ 4,001:
// callback from saveApi.post()
var fnSaveSuccess = function() {
ctx.editMode = 'all';
const response = ctx.saveApi.getResponse();
Line 4,032 ⟶ 4,014:
ctx.statusElement.info(['completed (', link, ')']);
if (ctx.onSaveSuccess) {
ctx.onSaveSuccess(this);
}
return;
Line 4,061 ⟶ 4,043:
const purgeQuery = {
action: 'purge',
titles: ctx.pageName
};
const purgeApi = new Morebits.wiki.api(msg('editconflict-purging', 'Edit conflict detected, purging server cache'), purgeQuery, (() => {
--Morebits.wiki.numberOfActionsLeft;
ctx.statusElement.info(msg('editconflict-retrying', 'Edit conflict detected, reapplying edit'));
Line 4,081 ⟶ 4,063:
// the error might be transient, so try again
ctx.statusElement.info(msg('save-failed-retrying', 2, 'Save failed, retrying in 2 seconds ...'));
--Morebits.wiki.numberOfActionsLeft;
// wait for sometime for client to regain connectivity
Line 4,121 ⟶ 4,103:
}
ctx.editMode = 'all';
if (ctx.onSaveFailure) {
ctx.onSaveFailure(this);
}
}
Line 4,219 ⟶ 4,201:
* @param {string} action - The action being checked.
* @param {string} onFailure - Failure callback.
* @
*/
var fnPreflightChecks = function(action, onFailure) {
Line 4,244 ⟶ 4,226:
* @param {string} onFailure - Failure callback.
* @param {string} response - The response document from the API call.
* @
*/
const fnProcessChecks = function(action, onFailure, response) {
Line 4,250 ⟶ 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,483 ⟶ 4,465:
if (errorCode === 'internal_api_error_DBQueryError' && ctx.retries++ < ctx.maxRetries) {
ctx.statusElement.info('Database query error, retrying');
--Morebits.wiki.numberOfActionsLeft;
ctx.deleteProcessApi.post(); // give it another go!
Line 4,489 ⟶ 4,471:
ctx.statusElement.error('Cannot delete the page, because it no longer exists');
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, ctx.deleteProcessApi);
}
// hard error, give up
Line 4,495 ⟶ 4,477:
ctx.statusElement.error('Failed to delete the page: ' + ctx.deleteProcessApi.getErrorText());
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, ctx.deleteProcessApi);
}
}
Line 4,552 ⟶ 4,534:
if (ctx.retries++ < ctx.maxRetries) {
ctx.statusElement.info('Database query error, retrying');
--Morebits.wiki.numberOfActionsLeft;
ctx.undeleteProcessApi.post(); // give it another go!
} else {
ctx.statusElement.error('Repeated database query error, please try again');
if (ctx.onUndeleteFailure) {
ctx.onUndeleteFailure.call(this, ctx.undeleteProcessApi);
}
}
Line 4,563 ⟶ 4,545:
ctx.statusElement.error('Cannot undelete the page, either because there are no revisions to undelete or because it has already been undeleted');
if (ctx.onUndeleteFailure) {
ctx.onUndeleteFailure.call(this, ctx.undeleteProcessApi);
}
// hard error, give up
Line 4,569 ⟶ 4,551:
ctx.statusElement.error('Failed to undelete the page: ' + ctx.undeleteProcessApi.getErrorText());
if (ctx.onUndeleteFailure) {
ctx.onUndeleteFailure.call(this, ctx.undeleteProcessApi);
}
}
Line 4,599 ⟶ 4,581:
}
});
// Fall back to current levels if not explicitly set
Line 4,737 ⟶ 4,718:
* - Need to reset all parameters once done (e.g. edit summary, move destination, etc.)
*/
/* **************** Morebits.wiki.preview **************** */
Line 4,765 ⟶ 4,745:
* @param {string} [pageTitle] - Optional parameter for the page this should be rendered as being on, if omitted it is taken as the current page.
* @param {string} [sectionTitle] - If provided, render the text as a new section using this as the title.
* @
*/
this.beginRender = function(wikitext, pageTitle, sectionTitle) {
Line 4,777 ⟶ 4,757:
action: 'parse',
prop: ['text', 'modules'],
pst: true,
preview: true,
text: wikitext,
Line 4,813 ⟶ 4,793:
};
};
/* **************** Morebits.wikitext **************** */
Line 4,831 ⟶ 4,810:
* @param {string} text - Wikitext containing a template.
* @param {number} [start=0] - Index noting where in the text the template begins.
* @
*/
Morebits.wikitext.parseTemplate = function(text, start) {
Line 4,837 ⟶ 4,816:
const level = []; // Track of how deep we are ({{, {{{, or [[)
let count = -1;
let unnamed = 0; // Keep track of what number an unnamed parameter should receive
let equals = -1; // After finding "=" before a parameter, the index; otherwise, -1
Line 4,856 ⟶ 4,835:
// Nothing found yet, this must be the template name
if (count === -1) {
result.name = current.
++count;
} else {
Line 4,951 ⟶ 4,930:
*
* @param {string} link_target
* @
*/
removeLink: function(link_target) {
Line 4,966 ⟶ 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 4,981 ⟶ 4,960:
* @param {string} image - Image name without `File:` prefix.
* @param {string} [reason] - Reason to be included in comment, alongside the commented-out image.
* @
*/
commentOutImage: function(image, reason) {
Line 5,026 ⟶ 5,005:
* @param {string} image - Image name without File: prefix.
* @param {string} data - The display options.
* @
*/
addToImageComment: function(image, data) {
Line 5,051 ⟶ 5,030:
* @param {string} template - Page name whose transclusions are to be removed,
* include namespace prefix only if not in template namespace.
* @
*/
removeTemplate: function(template) {
Line 5,077 ⟶ 5,056:
* @param {string|string[]} [preRegex] - Optional regex string or array to match
* before any template matches (i.e. before `{{`), such as html comments.
* @
*/
insertAfterTemplates: function(tag, regex, flags, preRegex) {
Line 5,101 ⟶ 5,080:
preRegex = preRegex.join('|');
}
// Regex is extra complicated to allow for templates with
Line 5,136 ⟶ 5,114:
* Get the manipulated wikitext.
*
* @
*/
getText: function() {
Line 5,142 ⟶ 5,120:
}
};
/* *********** Morebits.userspaceLogger ************ */
Line 5,176 ⟶ 5,153:
* @param {string} logText - Doesn't include leading `#` or `*`.
* @param {string} summaryText - Edit summary.
* @
*/
this.log = function(logText, summaryText) {
Line 5,204 ⟶ 5,181:
};
};
/* **************** Morebits.status **************** */
Line 5,260 ⟶ 5,236:
Morebits.status.errorEvent = handler;
} else {
throw new Error('Morebits.status.onError: handler is not a function');
}
};
Line 5,353 ⟶ 5,329:
* @param {string} text - Before colon
* @param {string} status - After colon
* @
*/
Morebits.status.status = function(text, status) {
Line 5,362 ⟶ 5,338:
* @param {string} text - Before colon
* @param {string} status - After colon
* @
*/
Morebits.status.info = function(text, status) {
Line 5,371 ⟶ 5,347:
* @param {string} text - Before colon
* @param {string} status - After colon
* @
*/
Morebits.status.warn = function(text, status) {
Line 5,380 ⟶ 5,356:
* @param {string} text - Before colon
* @param {string} status - After colon
* @
*/
Morebits.status.error = function(text, status) {
Line 5,421 ⟶ 5,397:
Morebits.status.root.appendChild(p);
};
/**
Line 5,430 ⟶ 5,404:
* @param {string} content - Text content.
* @param {string} [color] - Font color.
* @
*/
Morebits.htmlNode = function (type, content, color) {
Line 5,440 ⟶ 5,414:
return node;
};
/**
Line 5,457 ⟶ 5,429:
const thisCb = this;
if (event.shiftKey && lastCheckbox !== null) {
const $cbs = $(jQuerySelector, jQueryContext); // can't cache them, obviously, if we want to support
let index = -1, lastIndex = -1, i;
for (i = 0; i < $cbs.length; i++) {
if ($cbs[i] === thisCb) {
index = i;
if (lastIndex > -1) {
Line 5,466 ⟶ 5,438:
}
}
if ($cbs[i] === lastCheckbox) {
lastIndex = i;
if (index > -1) {
Line 5,487 ⟶ 5,459:
for (i = start; i <= finish; i++) {
if ($cbs[i].checked !== endState) {
$cbs[i].click();
}
}
Line 5,497 ⟶ 5,469:
}
$(jQuerySelector, jQueryContext).
};
/* **************** Morebits.batchOperation **************** */
Line 5,681 ⟶ 5,651:
const chunk = ctx.pageChunks[++ctx.currentChunkIndex];
if (!chunk) {
return;
}
Line 5,767 ⟶ 5,737:
* Run all the tasks. Multiple tasks may be run at once.
*
* @
*/
this.execute = function() {
Line 5,800 ⟶ 5,770:
* @memberof Morebits
* @class
* @requires
* @param {number} width
* @param {number} height - The maximum allowable height for the content area.
Line 5,816 ⟶ 5,786:
buttons: { 'Placeholder button': function() {} },
dialogClass: 'morebits-dialog',
width: Math.min(parseInt(window.innerWidth, 10), parseInt(width
// give jQuery the given height value (which represents the anticipated height of the dialog) here, so
// it can position the dialog appropriately
Line 5,873 ⟶ 5,843:
* Focuses the dialog. This might work, or on the contrary, it might not.
*
* @
*/
focus: function() {
Line 5,885 ⟶ 5,855:
*
* @param {event} [event]
* @
*/
close: function(event) {
Line 5,899 ⟶ 5,869:
* might work, but it is not guaranteed.
*
* @
*/
display: function() {
Line 5,907 ⟶ 5,877:
const scriptnamespan = document.createElement('span');
scriptnamespan.className = 'morebits-dialog-scriptname';
scriptnamespan.textContent = this.scriptName + ' \u00B7 ';
$widget.find('.ui-dialog-title').prepend(scriptnamespan);
}
const dialog = $(this.content).dialog('open');
if (window.setupTooltips && window.pg && window.pg.re && window.pg.re.diff) {
dialog.parent()[0].ranSetupTooltipsAlready = false;
window.setupTooltips(dialog.parent()[0]);
}
this.setHeight(this.height);
return this;
},
Line 5,924 ⟶ 5,894:
*
* @param {string} title
* @
*/
setTitle: function(title) {
Line 5,936 ⟶ 5,906:
*
* @param {string} name
* @
*/
setScriptName: function(name) {
Line 5,947 ⟶ 5,917:
*
* @param {number} width
* @
*/
setWidth: function(width) {
Line 5,959 ⟶ 5,929:
*
* @param {number} height
* @
*/
setHeight: function(height) {
Line 5,985 ⟶ 5,955:
*
* @param {HTMLElement} content
* @
*/
setContent: function(content) {
Line 5,997 ⟶ 5,967:
*
* @param {HTMLElement} content
* @
*/
addContent: function(content) {
Line 6,027 ⟶ 5,997:
$(this.content).dialog('widget').find('.morebits-dialog-buttons').empty().append(this.buttons)[0].removeAttribute('data-empty');
} else {
$(this.content).dialog('widget').find('.morebits-dialog-buttons')[0].setAttribute('data-empty', 'data-empty');
}
return this;
Line 6,035 ⟶ 6,005:
* Removes all contents from the dialog, barring any footer links.
*
* @
*/
purgeContent: function() {
Line 6,057 ⟶ 6,027:
* @param {string} wikiPage - Link target.
* @param {boolean} [prep=false] - Set true to prepend rather than append.
* @
*/
addFooterLink: function(text, wikiPage, prep) {
Line 6,063 ⟶ 6,033:
if (this.hasFooterLinks) {
const bullet = document.createElement('span');
bullet.textContent = msg('bullet-separator', ' \u2022 ');
if (prep) {
$footerlinks.prepend(bullet);
Line 6,091 ⟶ 6,061:
* @param {boolean} [modal=false] - If set to true, other items on the
* page will be disabled, i.e., cannot be interacted with.
* @
*/
setModality: function(modal) {
Line 6,114 ⟶ 6,084:
};
// 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;
}());
/**
Line 6,127 ⟶ 6,110:
*/
if (typeof arguments === 'undefined') {
/* global Morebits */
window.SimpleWindow = Morebits.simpleWindow;
|