MediaWiki:Gadget-morebits.js: Difference between revisions

Content deleted Content added
Repo at 3da72fd: apply autofixes 1 (#2058)
Repo at 001f236: simplify IIFEs (#2074); apply autofixes 3 (#2079); apply autofixes 2 (#2069)
Line 34:
*/
 
(function() {
 
(function (window, document, $) { // Wrap entire file with anonymous function
 
/** @lends Morebits */
const Morebits = {};
window.Morebits = Morebits; // allow global access
 
/**
Line 50 ⟶ 49:
* Examples:
* Use jquery-i18n:
* Morebits.i18n.setParser({ get: $.i18n });
* Use banana-i18n or orange-i18n:
* var banana = new Banana('en');
* Morebits.i18n.setParser({ get: banana.i18n });
*
* @param {Object} parser
*/
Line 64:
/**
* @private
* @returnsreturn {string}
*/
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
* @returnsreturn {number[] | null}
*/
signatureTimestampFormat: function (str) {
Line 124:
}
};
 
 
/**
Line 130 ⟶ 129:
*
* @param {string} group - e.g. `sysop`, `extendedconfirmed`, etc.
* @returnsreturn {boolean}
*/
Morebits.userIsInGroup = function (group) {
return mw.config.get('wgUserGroups').indexOf(group) !== -1;
};
/**
/* * Hardcodes whether the user is a sysop, used a lot.
*
* @type {boolean}
Line 151:
*
* @param {string} address - The IPv6 address, with or without CIDR.
* @returnsreturn {string}
*/
Morebits.sanitizeIPv6 = function (address) {
Line 163:
* detect Module:RfD, with the same failure points.
*
* @returnsreturn {boolean}
*/
Morebits.isPageRedirect = function() {
Line 176:
*/
Morebits.pageNameNorm = mw.config.get('wgPageName').replace(/_/g, ' ');
 
 
/**
Line 184 ⟶ 183:
*
* @param {string} pageName - Page name without namespace.
* @returnsreturn {string} - For a page name `Foo bar`, returns the string `[Ff]oo[_ ]bar`.
*/
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
* @returnsreturn {DocumentFragment}
*/
Morebits.createHtml = function(input) {
Line 228:
/**
* Converts wikilinks to HTML anchor tags.
*
* @param text
* @returnsreturn {*}
*/
Morebits.createHtml.renderWikilinks = function (text) {
Line 260 ⟶ 261:
* // returns '(?:[Ff][Ii][Ll][Ee]|[Ii][Mm][Aa][Gg][Ee])'
* Morebits.namespaceRegex([6])
* @returnsreturn {string} - Regex-suitable string of all namespace aliases.
*/
Morebits.namespaceRegex = function(namespaces) {
Line 288 ⟶ 289:
return regex;
};
 
 
/* **************** Morebits.quickForm **************** */
Line 308:
*
* @memberof Morebits.quickForm
* @returnsreturn {HTMLElement}
*/
Morebits.quickForm.prototype.render = function QuickFormRender() {
Line 322:
* @param {(object|Morebits.quickForm.element)} data - A quickform element, or the object with which
* a quickform element is constructed.
* @returnsreturn {Morebits.quickForm.element} - Same as what is passed to the function.
*/
Morebits.quickForm.prototype.append = function QuickFormAppend(data) {
Line 374:
* @memberof Morebits.quickForm
* @class
* @param {objectObject} data - Object representing the quickform element. Should
* specify one of the available types from the index above, as well as any
* relevant and available attributes.
Line 402:
* @param {Morebits.quickForm.element} data - A quickForm element or the object required to
* create the quickForm element.
* @returnsreturn {Morebits.quickForm.element} The same element passed in.
*/
Morebits.quickForm.element.prototype.append = function QuickFormElementAppend(data) {
Line 420:
*
* @memberof Morebits.quickForm.element
* @returnsreturn {HTMLElement}
*/
Morebits.quickForm.element.prototype.render = function QuickFormElementRender(internal_subgroup_id) {
Line 431:
return currentNode[0];
};
 
 
/** @memberof Morebits.quickForm.element */
Line 603 ⟶ 602:
});
$.each(tmpgroup, (idx, el) => {
const newEl = $Object.extendassign({}, el);
if (!newEl.type) {
newEl.type = data.type;
Line 760 ⟶ 759:
 
data.inputs.forEach((subdata) => {
const cell = new Morebits.quickForm.element($Object.extendassign(subdata, { type: '_dyninput_cell' }));
node.appendChild(cell.render());
});
Line 938 ⟶ 937:
* @requires jquery.ui
* @param {HTMLElement} node - The HTML element beside which a tooltip is to be generated.
* @param {objectObject} data - Tooltip-related configuration data.
*/
Morebits.quickForm.element.generateTooltip = function QuickFormElementGenerateTooltip(node, data) {
Line 951 ⟶ 950:
});
};
 
 
// Some utility methods for manipulating quickForms after their creation:
Line 962 ⟶ 960:
* @memberof Morebits.quickForm
* @param {HTMLFormElement} form
* @returnsreturn {objectObject} With field names as keys, input data as values.
*/
Morebits.quickForm.getInputData = function(form) {
Line 1,015 ⟶ 1,013:
return result;
};
 
 
/**
Line 1,023 ⟶ 1,020:
* @param {HTMLFormElement} form
* @param {string} fieldName - The name or id of the fields.
* @returnsreturn {HTMLElement[]} - Array of matching form elements.
*/
Morebits.quickForm.getElements = function QuickFormGetElements(form, fieldName) {
Line 1,043 ⟶ 1,040:
* @param {HTMLInputElement[]} elementArray - Array of checkbox or radio elements.
* @param {string} value - Value to search for.
* @returnsreturn {HTMLInputElement}
*/
Morebits.quickForm.getCheckboxOrRadio = function QuickFormGetCheckboxOrRadio(elementArray, value) {
Line 1,059 ⟶ 1,056:
* @memberof Morebits.quickForm
* @param {HTMLElement} element
* @returnsreturn {HTMLElement}
*/
Morebits.quickForm.getElementContainer = function QuickFormGetElementContainer(element) {
Line 1,078 ⟶ 1,075:
* @memberof Morebits.quickForm
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @returnsreturn {HTMLElement}
*/
Morebits.quickForm.getElementLabelObject = function QuickFormGetElementLabelObject(element) {
Line 1,101 ⟶ 1,098:
* @memberof Morebits.quickForm
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @returnsreturn {string}
*/
Morebits.quickForm.getElementLabel = function QuickFormGetElementLabel(element) {
Line 1,118 ⟶ 1,115:
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @param {string} labelText
* @returnsreturn {boolean} True if succeeded, false if the label element is unavailable.
*/
Morebits.quickForm.setElementLabel = function QuickFormSetElementLabel(element, labelText) {
Line 1,136 ⟶ 1,133:
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @param {string} temporaryLabelText
* @returnsreturn {boolean} `true` if succeeded, `false` if the label element is unavailable.
*/
Morebits.quickForm.overrideElementLabel = function QuickFormOverrideElementLabel(element, temporaryLabelText) {
Line 1,150 ⟶ 1,147:
* @memberof Morebits.quickForm
* @param {(HTMLElement|Morebits.quickForm.element)} element
* @returnsreturn {boolean} True if succeeded, false if the label element is unavailable.
*/
Morebits.quickForm.resetElementLabel = function QuickFormResetElementLabel(element) {
Line 1,180 ⟶ 1,177:
$(Morebits.quickForm.getElementContainer(element)).find('.morebits-tooltipButton').toggle(visibility);
};
 
 
 
/**
Line 1,189 ⟶ 1,184:
* Get checked items in the form.
*
* @functionmethod external:HTMLFormElement.getChecked
* @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,190:
* @param {string} [type] - Optionally specify either radio or checkbox (for
* the event that both checkboxes and radiobuttons have the same name).
* @returnsreturn {string[]} - Contains the values of elements with the given name
* checked property set to true.
*/
Line 1,243 ⟶ 1,238:
* Does the same as {@link HTMLFormElement.getChecked|getChecked}, but with unchecked elements.
*
* @functionmethod external:HTMLFormElement.getUnchecked
* @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,244:
* @param {string} [type] - Optionally specify either radio or checkbox (for
* the event that both checkboxes and radiobuttons have the same name).
* @returnsreturn {string[]} - Contains the values of elements with the given name
* checked property set to true.
*/
Line 1,308 ⟶ 1,303:
*
* @param {string} address - The IPv6 address, with or without CIDR.
* @returnsreturn {string}
*/
sanitizeIPv6: function (address) {
Line 1,361 ⟶ 1,356:
*
* @param {string} ip
* @returnsreturn {boolean} - True if given a valid IP address range, false otherwise.
*/
isRange: function (ip) {
Line 1,372 ⟶ 1,367:
* for IPv4 and /32 for IPv6.
*
* @returnsreturn {boolean} - True for valid ranges within the CIDR limits,
* otherwise false (ranges outside the limit, single IPs, non-IPs).
*/
Line 1,397 ⟶ 1,392:
*
* @param {string} ipv6 - The IPv6 address, with or without a subnet.
* @returnsreturn {boolean|string} - False if not IPv6 or bigger than a 64,
* otherwise the (sanitized) /64 address.
*/
Line 1,413 ⟶ 1,408:
}
};
 
 
/**
Line 1,424 ⟶ 1,418:
/**
* @param {string} str
* @returnsreturn {string}
*/
toUpperCaseFirstChar: function(str) {
Line 1,432 ⟶ 1,426:
/**
* @param {string} str
* @returnsreturn {string}
*/
toLowerCaseFirstChar: function(str) {
Line 1,448 ⟶ 1,442:
* @param {string} end
* @param {(string[]|string)} [skiplist]
* @returnsreturn {string[]}
* @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,496:
* @param {string} str
* @param {boolean} [addSig]
* @returnsreturn {string}
*/
formatReasonText: function(str, addSig) {
Line 1,525 ⟶ 1,519:
*
* @param {string} str
* @returnsreturn {string}
*/
formatReasonForLog: function(str) {
Line 1,545 ⟶ 1,539:
* @param {(string|RegExp)} pattern
* @param {string} replacement
* @returnsreturn {string}
*/
safeReplace: function morebitsStringSafeReplace(string, pattern, replacement) {
Line 1,558 ⟶ 1,552:
*
* @param {string} expiry
* @returnsreturn {boolean}
*/
isInfinity: function morebitsStringIsInfinity(expiry) {
Line 1,569 ⟶ 1,563:
*
* @param {string} text - String to be escaped.
* @returnsreturn {string} - The escaped text.
*/
escapeRegExp: function(text) {
Line 1,575 ⟶ 1,569:
}
};
 
 
/**
Line 1,588 ⟶ 1,581:
*
* @param {Array} arr
* @returnsreturn {Array} A copy of the array with duplicates removed.
* @throws When provided a non-array.
*/
Line 1,602 ⟶ 1,595:
*
* @param {Array} arr
* @returnsreturn {Array} A copy of the array with the first instance of each value
* removed; subsequent instances of those values (duplicates) remain.
* @throws When provided a non-array.
Line 1,612 ⟶ 1,605:
return arr.filter((item, idx) => arr.indexOf(item) !== idx);
},
 
 
/**
Line 1,619 ⟶ 1,611:
* @param {Array} arr
* @param {number} size - Size of each chunk (except the last, which could be different).
* @returnsreturn {Array[]} An array containing the smaller, chunked arrays.
* @throws When provided a non-array.
*/
Line 1,723 ⟶ 1,715:
 
};
 
 
/**
Line 1,770 ⟶ 1,761:
* Restore the hidden portion of the `content` string.
*
* @returnsreturn {string} The processed output.
*/
rebind: function UnbinderRebind() {
Line 1,797 ⟶ 1,788:
};
};
 
 
 
/* **************** Morebits.date **************** */
Line 1,836 ⟶ 1,825:
if (!this._d) {
// Try standard date
this._d = new (Function.prototype.bind.apply(Date, [Date].concat(args)))();
}
 
Line 1,909 ⟶ 1,898:
 
Morebits.date.prototype = {
/** @returnsreturn {boolean} */
isValid: function() {
return !isNaN(this.getTime());
Line 1,916 ⟶ 1,905:
/**
* @param {(Date|Morebits.date)} date
* @returnsreturn {boolean}
*/
isBefore: function(date) {
Line 1,923 ⟶ 1,912:
/**
* @param {(Date|Morebits.date)} date
* @returnsreturn {boolean}
*/
isAfter: function(date) {
Line 1,929 ⟶ 1,918:
},
 
/** @returnsreturn {string} */
getUTCMonthName: function() {
return Morebits.date.localeData.months[this.getUTCMonth()];
},
/** @returnsreturn {string} */
getUTCMonthNameAbbrev: function() {
return Morebits.date.localeData.monthsShort[this.getUTCMonth()];
},
/** @returnsreturn {string} */
getMonthName: function() {
return Morebits.date.localeData.months[this.getMonth()];
},
/** @returnsreturn {string} */
getMonthNameAbbrev: function() {
return Morebits.date.localeData.monthsShort[this.getMonth()];
},
/** @returnsreturn {string} */
getUTCDayName: function() {
return Morebits.date.localeData.days[this.getUTCDay()];
},
/** @returnsreturn {string} */
getUTCDayNameAbbrev: function() {
return Morebits.date.localeData.daysShort[this.getUTCDay()];
},
/** @returnsreturn {string} */
getDayName: function() {
return Morebits.date.localeData.days[this.getDay()];
},
/** @returnsreturn {string} */
getDayNameAbbrev: function() {
return Morebits.date.localeData.daysShort[this.getDay()];
Line 1,969 ⟶ 1,958:
* @param {string} unit
* @throws If invalid or unsupported unit is given.
* @returnsreturn {Morebits.date}
*/
add: function(number, unit) {
Line 1,998 ⟶ 1,987:
* @param {string} unit
* @throws If invalid or unsupported unit is given.
* @returnsreturn {Morebits.date}
*/
subtract: function(number, unit) {
Line 2,038 ⟶ 2,027:
* @param {(string|number)} [zone=system] - `system` (for browser-default time zone),
* `utc`, or specify a time zone as number of minutes relative to UTC.
* @returnsreturn {string}
*/
format: function(formatstr, zone) {
Line 2,095 ⟶ 2,084:
* @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.
* @returnsreturn {string}
*/
calendar: function(zone) {
Line 2,122 ⟶ 2,111:
* as `==December 2019==` or `=== Jan 2018 ===`.
*
* @returnsreturn {RegExp}
*/
monthHeaderRegex: function() {
Line 2,134 ⟶ 2,123:
* @param {number} [level=2] - Header level. Pass 0 for just the text
* with no wikitext markers (==).
* @returnsreturn {string}
*/
monthHeader: function(level) {
Line 2,159 ⟶ 2,148:
};
});
 
 
/* **************** Morebits.wiki **************** */
Line 2,174 ⟶ 2,162:
* @deprecated in favor of Morebits.isPageRedirect as of November 2020
* @memberof Morebits.wiki
* @returnsreturn {boolean}
*/
Morebits.wiki.isPageRedirect = function wikipediaIsPageRedirect() {
Line 2,180 ⟶ 2,168:
return Morebits.isPageRedirect();
};
 
 
/* **************** Morebits.wiki.actionCompleted **************** */
Line 2,266 ⟶ 2,253:
}
};
 
 
/* **************** Morebits.wiki.api **************** */
Line 2,285 ⟶ 2,271:
* @class
* @param {string} currentAction - The current action (required).
* @param {objectObject} query - The query (required).
* @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,332 ⟶ 2,318:
onSuccess: null,
onError: null,
parent: window, // use global context if there is no parent object
query: null,
response: null,
responseXML: null, // use `response` instead; retained for backwards compatibility
statelem: null, // this non-standard name kept for backwards compatibility
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,346:
* Carry out the request.
*
* @param {objectObject} callerAjaxParameters - Do not specify a parameter unless you really
* really want to give jQuery some extra parameters.
* @returnsreturn {promise} - A jQuery promise object that is resolved or rejected with the api object.
*/
post: function(callerAjaxParameters) {
Line 2,377 ⟶ 2,363:
// token should always be the last item in the query string (bug TW-B-0013)
 
const ajaxparams = $Object.extendassign({}, {
context: this,
type: this.query.action === 'query' ? 'GET' : 'POST',
Line 2,522 ⟶ 2,508:
morebitsWikiApiUserAgent = (ua ? ua + ' ' : '') + 'morebits.js ([[w:WT:TW]])';
};
 
 
 
/**
Line 2,534 ⟶ 2,518:
*/
var morebitsWikiChangeTag = '';
 
 
/**
Line 2,540 ⟶ 2,523:
*
* @memberof Morebits.wiki.api
* @returnsreturn {string} MediaWiki CSRF token.
*/
Morebits.wiki.api.getToken = function() {
Line 2,551 ⟶ 2,534:
return tokenApi.post().then((apiobj) => apiobj.response.query.tokens.csrftoken);
};
 
 
/* **************** Morebits.wiki.page **************** */
Line 2,592 ⟶ 2,574:
* 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,602:
editSummary: null,
changeTags: null,
testActions: null, // array if any valid actions
callbackParameters: null,
statusElement: status instanceof Morebits.status ? status : new Morebits.status(status),
Line 2,627 ⟶ 2,608:
// - edit
pageText: null,
editMode: 'all', // save() replaces entire contents of the page by default
appendText: null, // can't reuse pageText for this because pageText is needed to follow a redirect
prependText: null, // can't reuse pageText for this because pageText is needed to follow a redirect
newSectionText: null,
newSectionTitle: null,
Line 2,760 ⟶ 2,741:
 
if (ctx.editMode === 'all') {
ctx.loadQuery.rvprop = 'content|timestamp'; // get the page content at the same time, if needed
} else if (ctx.editMode === 'revert') {
ctx.loadQuery.rvprop = 'timestamp';
Line 2,768 ⟶ 2,749:
 
if (ctx.followRedirect) {
ctx.loadQuery.redirects = ''; // follow all redirects
}
if (typeof ctx.pageSection === 'number') {
Line 2,823 ⟶ 2,804:
if (ctx.fullyProtected && !ctx.suppressProtectWarning &&
!confirm(
ctx.fullyProtected === 'infinity' ?
? msg('protected-indef-edit-warning', ctx.pageName,
'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.'
) :
: msg('protected-edit-warning', ctx.pageName, ctx.fullyProtected,
'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,845:
query.minor = true;
} else {
query.notminor = true; // force Twinkle config to override user preference setting for "all edits are minor"
}
 
Line 2,879 ⟶ 2,860:
return;
}
query.appendtext = ctx.appendText; // use mode to append to current page contents
break;
case 'prepend':
Line 2,887 ⟶ 2,868:
return;
}
query.prependtext = ctx.prependText; // use mode to prepend to current page contents
break;
case 'new':
Line 2,896 ⟶ 2,877:
}
query.section = 'new';
query.text = ctx.newSectionText; // add a new section to current page
query.sectiontitle = ctx.newSectionTitle || ctx.editSummary; // done by the API, but non-'' values would get treated as text
break;
Line 2,992 ⟶ 2,973:
};
 
/** @returnsreturn {string} The name of the loaded page, including the namespace */
this.getPageName = function() {
return ctx.pageName;
};
 
/** @returnsreturn {string} The text of the page after a successful load() */
this.getPageText = function() {
return ctx.pageText;
Line 3,034 ⟶ 3,015:
ctx.newSectionTitle = newSectionTitle;
};
 
 
 
// Edit-related setter methods:
Line 3,059 ⟶ 3,038:
ctx.changeTags = tags;
};
 
 
/**
Line 3,069 ⟶ 3,047:
* - `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,309:
};
 
/** @returnsreturn {string} The current revision ID of the page */
this.getCurrentID = function() {
return ctx.revertCurID;
};
 
/** @returnsreturn {string} Last editor of the page */
this.getRevisionUser = function() {
return ctx.revertUser;
};
 
/** @returnsreturn {string} ISO 8601 timestamp at which the page was last edited. */
this.getLastEditTime = function() {
return ctx.lastEditTime;
Line 3,359 ⟶ 3,336:
* detected upon calling `save()`.
*
* @param {objectObject} callbackParameters
*/
this.setCallbackParameters = function(callbackParameters) {
Line 3,366 ⟶ 3,343:
 
/**
* @returnsreturn {objectObject} - The object previously set by `setCallbackParameters()`.
*/
this.getCallbackParameters = function() {
Line 3,380 ⟶ 3,357:
 
/**
* @returnsreturn {Morebits.status} Status element created by the constructor.
*/
this.getStatusElement = function() {
Line 3,396 ⟶ 3,373:
 
/**
* @returnsreturn {boolean} True if the page existed on the wiki when it was last loaded.
*/
this.exists = function() {
Line 3,403 ⟶ 3,380:
 
/**
* @returnsreturn {string} Page ID of the page loaded. 0 if the page doesn't
* exist.
*/
Line 3,411 ⟶ 3,388:
 
/**
* @returnsreturn {string} - Content model of the page. Possible values
* include (but may not be limited to): `wikitext`, `javascript`,
* `css`, `json`, `Scribunto`, `sanitized-css`, `MassMessageListContent`.
Line 3,421 ⟶ 3,398:
 
/**
* @returnsreturn {boolean|string} - Watched status of the page. Boolean
* unless it's being watched temporarily, in which case returns the
* expiry string.
Line 3,430 ⟶ 3,407:
 
/**
* @returnsreturn {string} ISO 8601 timestamp at which the page was last loaded.
*/
this.getLoadTime = function() {
Line 3,437 ⟶ 3,414:
 
/**
* @returnsreturn {string} The user who created the page following `lookupCreation()`.
*/
this.getCreator = function() {
Line 3,444 ⟶ 3,421:
 
/**
* @returnsreturn {string} The ISOString timestamp of page creation following `lookupCreation()`.
*/
this.getCreationTimestamp = function() {
Line 3,450 ⟶ 3,427:
};
 
/** @returnsreturn {boolean} whether or not you can edit the page */
this.canEdit = function() {
return !!ctx.testActions && ctx.testActions.indexOf('edit') !== -1;
Line 3,497 ⟶ 3,474:
 
if (ctx.followRedirect) {
query.redirects = ''; // follow all redirects
}
 
Line 3,768 ⟶ 3,745:
* @param {string} [action=edit] - The action being undertaken, e.g.
* "edit" or "delete". In practice, only "edit" or "notedit" matters.
* @returnsreturn {boolean}
*/
var fnCanUseMwUserToken = function(action = 'edit') {
Line 3,819 ⟶ 3,796:
* @param {string} action - The action being undertaken, e.g. "edit" or
* "delete".
* @returnsreturn {objectObject} Appropriate query.
*/
var fnNeedTokenInfoQuery = function(action) {
Line 3,862 ⟶ 3,839:
ctx.pageID = page.pageid;
} else {
ctx.pageText = ''; // allow for concatenation, etc.
ctx.pageID = 0; // nonexistent in response, matches wgArticleId
}
Line 3,911 ⟶ 3,888:
ctx.revertUser = rev && rev.user;
if (!ctx.revertUser) {
if (rev && rev.userhidden) { // username was RevDel'd or oversighted
ctx.revertUser = '<username hidden>';
} else {
Line 3,926 ⟶ 3,903:
 
// alert("Generate edit conflict now"); // for testing edit conflict recovery logic
ctx.onLoadSuccess(this); // invoke callback
};
 
Line 3,984 ⟶ 3,961:
* ensured of knowing the watch status by the use of this.
*
* @returnsreturn {boolean}
*/
var fnApplyWatchlistExpiry = function() {
Line 4,019 ⟶ 3,996:
// callback from saveApi.post()
var fnSaveSuccess = function() {
ctx.editMode = 'all'; // cancel append/prepend/newSection/revert modes
const response = ctx.saveApi.getResponse();
 
Line 4,032 ⟶ 4,009:
ctx.statusElement.info(['completed (', link, ')']);
if (ctx.onSaveSuccess) {
ctx.onSaveSuccess(this); // invoke callback
}
return;
Line 4,061 ⟶ 4,038:
const purgeQuery = {
action: 'purge',
titles: ctx.pageName // redirects are already resolved
};
 
const purgeApi = new Morebits.wiki.api(msg('editconflict-purging', 'Edit conflict detected, purging server cache'), purgeQuery, (() => {
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
 
ctx.statusElement.info(msg('editconflict-retrying', 'Edit conflict detected, reapplying edit'));
Line 4,081 ⟶ 4,058:
// 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; // allow for normal completion if retry succeeds
 
// wait for sometime for client to regain connectivity
Line 4,121 ⟶ 4,098:
}
 
ctx.editMode = 'all'; // cancel append/prepend/newSection/revert modes
if (ctx.onSaveFailure) {
ctx.onSaveFailure(this); // invoke callback
}
}
Line 4,219 ⟶ 4,196:
* @param {string} action - The action being checked.
* @param {string} onFailure - Failure callback.
* @returnsreturn {boolean}
*/
var fnPreflightChecks = function(action, onFailure) {
Line 4,244 ⟶ 4,221:
* @param {string} onFailure - Failure callback.
* @param {string} response - The response document from the API call.
* @returnsreturn {boolean}
*/
const fnProcessChecks = function(action, onFailure, response) {
Line 4,483 ⟶ 4,460:
if (errorCode === 'internal_api_error_DBQueryError' && ctx.retries++ < ctx.maxRetries) {
ctx.statusElement.info('Database query error, retrying');
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
ctx.deleteProcessApi.post(); // give it another go!
 
Line 4,489 ⟶ 4,466:
ctx.statusElement.error('Cannot delete the page, because it no longer exists');
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, ctx.deleteProcessApi); // invoke callback
}
// hard error, give up
Line 4,495 ⟶ 4,472:
ctx.statusElement.error('Failed to delete the page: ' + ctx.deleteProcessApi.getErrorText());
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, ctx.deleteProcessApi); // invoke callback
}
}
Line 4,552 ⟶ 4,529:
if (ctx.retries++ < ctx.maxRetries) {
ctx.statusElement.info('Database query error, retrying');
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
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); // invoke callback
}
}
Line 4,563 ⟶ 4,540:
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); // invoke callback
}
// hard error, give up
Line 4,569 ⟶ 4,546:
ctx.statusElement.error('Failed to undelete the page: ' + ctx.undeleteProcessApi.getErrorText());
if (ctx.onUndeleteFailure) {
ctx.onUndeleteFailure.call(this, ctx.undeleteProcessApi); // invoke callback
}
}
Line 4,599 ⟶ 4,576:
}
});
 
 
// Fall back to current levels if not explicitly set
Line 4,737 ⟶ 4,713:
* - Need to reset all parameters once done (e.g. edit summary, move destination, etc.)
*/
 
 
/* **************** Morebits.wiki.preview **************** */
Line 4,765 ⟶ 4,740:
* @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.
* @returnsreturn {jQuery.promise}
*/
this.beginRender = function(wikitext, pageTitle, sectionTitle) {
Line 4,777 ⟶ 4,752:
action: 'parse',
prop: ['text', 'modules'],
pst: true, // PST = pre-save transform; this makes substitution work properly
preview: true,
text: wikitext,
Line 4,813 ⟶ 4,788:
};
};
 
 
/* **************** Morebits.wikitext **************** */
Line 4,831 ⟶ 4,805:
* @param {string} text - Wikitext containing a template.
* @param {number} [start=0] - Index noting where in the text the template begins.
* @returnsreturn {objectObject} `{name: templateName, parameters: {key: value}}`.
*/
Morebits.wikitext.parseTemplate = function(text, start) {
Line 4,837 ⟶ 4,811:
 
const level = []; // Track of how deep we are ({{, {{{, or [[)
let count = -1; // Number of parameters found
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,951 ⟶ 4,925:
*
* @param {string} link_target
* @returnsreturn {Morebits.wikitext.page}
*/
removeLink: function(link_target) {
Line 4,981 ⟶ 4,955:
* @param {string} image - Image name without `File:` prefix.
* @param {string} [reason] - Reason to be included in comment, alongside the commented-out image.
* @returnsreturn {Morebits.wikitext.page}
*/
commentOutImage: function(image, reason) {
Line 5,026 ⟶ 5,000:
* @param {string} image - Image name without File: prefix.
* @param {string} data - The display options.
* @returnsreturn {Morebits.wikitext.page}
*/
addToImageComment: function(image, data) {
Line 5,051 ⟶ 5,025:
* @param {string} template - Page name whose transclusions are to be removed,
* include namespace prefix only if not in template namespace.
* @returnsreturn {Morebits.wikitext.page}
*/
removeTemplate: function(template) {
Line 5,077 ⟶ 5,051:
* @param {string|string[]} [preRegex] - Optional regex string or array to match
* before any template matches (i.e. before `{{`), such as html comments.
* @returnsreturn {Morebits.wikitext.page}
*/
insertAfterTemplates: function(tag, regex, flags, preRegex) {
Line 5,101 ⟶ 5,075:
preRegex = preRegex.join('|');
}
 
 
// Regex is extra complicated to allow for templates with
Line 5,136 ⟶ 5,109:
* Get the manipulated wikitext.
*
* @returnsreturn {string}
*/
getText: function() {
Line 5,142 ⟶ 5,115:
}
};
 
 
/* *********** Morebits.userspaceLogger ************ */
Line 5,176 ⟶ 5,148:
* @param {string} logText - Doesn't include leading `#` or `*`.
* @param {string} summaryText - Edit summary.
* @returnsreturn {JQuery.Promise}
*/
this.log = function(logText, summaryText) {
Line 5,204 ⟶ 5,176:
};
};
 
 
/* **************** Morebits.status **************** */
Line 5,353 ⟶ 5,324:
* @param {string} text - Before colon
* @param {string} status - After colon
* @returnsreturn {Morebits.status} - `status`-type (blue)
*/
Morebits.status.status = function(text, status) {
Line 5,362 ⟶ 5,333:
* @param {string} text - Before colon
* @param {string} status - After colon
* @returnsreturn {Morebits.status} - `info`-type (green)
*/
Morebits.status.info = function(text, status) {
Line 5,371 ⟶ 5,342:
* @param {string} text - Before colon
* @param {string} status - After colon
* @returnsreturn {Morebits.status} - `warn`-type (red)
*/
Morebits.status.warn = function(text, status) {
Line 5,380 ⟶ 5,351:
* @param {string} text - Before colon
* @param {string} status - After colon
* @returnsreturn {Morebits.status} - `error`-type (bold red)
*/
Morebits.status.error = function(text, status) {
Line 5,421 ⟶ 5,392:
Morebits.status.root.appendChild(p);
};
 
 
 
/**
Line 5,430 ⟶ 5,399:
* @param {string} content - Text content.
* @param {string} [color] - Font color.
* @returnsreturn {HTMLElement}
*/
Morebits.htmlNode = function (type, content, color) {
Line 5,440 ⟶ 5,409:
return node;
};
 
 
 
/**
Line 5,497 ⟶ 5,464:
}
 
$(jQuerySelector, jQueryContext).clickon('click', clickHandler);
};
 
 
 
/* **************** Morebits.batchOperation **************** */
Line 5,681 ⟶ 5,646:
const chunk = ctx.pageChunks[++ctx.currentChunkIndex];
if (!chunk) {
return; // done! yay
}
 
Line 5,767 ⟶ 5,732:
* Run all the tasks. Multiple tasks may be run at once.
*
* @returnsreturn {jQuery.Promise} - Resolved if all tasks succeed, rejected otherwise.
*/
this.execute = function() {
Line 5,816 ⟶ 5,781:
buttons: { 'Placeholder button': function() {} },
dialogClass: 'morebits-dialog',
width: Math.min(parseInt(window.innerWidth, 10), parseInt(width ? width :|| 800, 10)),
// 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,838:
* Focuses the dialog. This might work, or on the contrary, it might not.
*
* @returnsreturn {Morebits.simpleWindow}
*/
focus: function() {
Line 5,885 ⟶ 5,850:
*
* @param {event} [event]
* @returnsreturn {Morebits.simpleWindow}
*/
close: function(event) {
Line 5,899 ⟶ 5,864:
* might work, but it is not guaranteed.
*
* @returnsreturn {Morebits.simpleWindow}
*/
display: function() {
Line 5,907 ⟶ 5,872:
const scriptnamespan = document.createElement('span');
scriptnamespan.className = 'morebits-dialog-scriptname';
scriptnamespan.textContent = this.scriptName + ' \u00B7 '; // U+00B7 MIDDLE DOT = &middot;
$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) { // tie in with NAVPOP
dialog.parent()[0].ranSetupTooltipsAlready = false;
window.setupTooltips(dialog.parent()[0]);
}
this.setHeight(this.height); // init height algorithm
return this;
},
Line 5,924 ⟶ 5,889:
*
* @param {string} title
* @returnsreturn {Morebits.simpleWindow}
*/
setTitle: function(title) {
Line 5,936 ⟶ 5,901:
*
* @param {string} name
* @returnsreturn {Morebits.simpleWindow}
*/
setScriptName: function(name) {
Line 5,947 ⟶ 5,912:
*
* @param {number} width
* @returnsreturn {Morebits.simpleWindow}
*/
setWidth: function(width) {
Line 5,959 ⟶ 5,924:
*
* @param {number} height
* @returnsreturn {Morebits.simpleWindow}
*/
setHeight: function(height) {
Line 5,985 ⟶ 5,950:
*
* @param {HTMLElement} content
* @returnsreturn {Morebits.simpleWindow}
*/
setContent: function(content) {
Line 5,997 ⟶ 5,962:
*
* @param {HTMLElement} content
* @returnsreturn {Morebits.simpleWindow}
*/
addContent: function(content) {
Line 6,027 ⟶ 5,992:
$(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'); // used by CSS
}
return this;
Line 6,035 ⟶ 6,000:
* Removes all contents from the dialog, barring any footer links.
*
* @returnsreturn {Morebits.simpleWindow}
*/
purgeContent: function() {
Line 6,057 ⟶ 6,022:
* @param {string} wikiPage - Link target.
* @param {boolean} [prep=false] - Set true to prepend rather than append.
* @returnsreturn {Morebits.simpleWindow}
*/
addFooterLink: function(text, wikiPage, prep) {
Line 6,063 ⟶ 6,028:
if (this.hasFooterLinks) {
const bullet = document.createElement('span');
bullet.textContent = msg('bullet-separator', ' \u2022 '); // U+2022 BULLET
if (prep) {
$footerlinks.prepend(bullet);
Line 6,091 ⟶ 6,056:
* @param {boolean} [modal=false] - If set to true, other items on the
* page will be disabled, i.e., cannot be interacted with.
* @returnsreturn {Morebits.simpleWindow}
*/
setModality: function(modal) {
Line 6,114 ⟶ 6,079:
};
 
}());
 
}(window, document, jQuery)); // End wrap with anonymous function
 
 
/**
Line 6,127 ⟶ 6,090:
*/
 
if (typeof arguments === 'undefined') { // typeof is here for a reason...
/* global Morebits */
window.SimpleWindow = Morebits.simpleWindow;