-
Notifications
You must be signed in to change notification settings - Fork 151
morebits
A library full of lots of goodness for user scripts on MediaWiki wikis, including Wikipedia.
The highlights include:
- api - make calls to the MediaWiki API
- page - modify pages on the wiki (edit, revert, delete, etc.)
- date - enhanced date object processing, sort of a light moment.js
- quickForm - generate quick HTML forms on the fly
- simpleWindow - a wrapper for jQuery UI Dialog with a custom look and extra features
- status - a rough-and-ready status message displayer, used by the Morebits.wiki classes
- wikitext - utilities for dealing with wikitext
- string - utilities for manipulating strings
- array - utilities for manipulating arrays
- ip - utilities to help process IP addresses
Dependencies:
- The whole thing relies on jQuery. But most wikis should provide this by default.
- quickForm, simpleWindow, and status rely on the "morebits.css" file for their styling.
- simpleWindow and quickForm tooltips rely on jQuery UI Dialog (from ResourceLoader module name 'jquery.ui').
- To create a gadget based on morebits.js, use this syntax in MediaWiki:Gadgets-definition:
*GadgetName[ResourceLoader|dependencies=mediawiki.user,mediawiki.util,mediawiki.Title,jquery.ui]|morebits.js|morebits.css|GadgetName.js
- Alternatively, you can configure morebits.js as a hidden gadget in MediaWiki:Gadgets-definition:
-
*morebits[ResourceLoader|dependencies=mediawiki.user,mediawiki.util,mediawiki.Title,jquery.ui|hidden]|morebits.js|morebits.css
and then load ext.gadget.morebits as one of the dependencies for the new gadget.
-
All the stuff here works on all browsers for which MediaWiki provides JavaScript support.
This library is maintained by the maintainers of Twinkle. For queries, suggestions, help, etc., head to Wikipedia talk:Twinkle on English Wikipedia. The latest development source is available at GitHub.
Kind: global namespace
-
Morebits :
object
-
.quickForm
- new quickForm(event, [eventType])
-
instance
-
.render() ⇒
HTMLElement
-
.append(data) ⇒
element
-
.render() ⇒
-
static
-
.element
- new Morebits.quickForm.element(data)
-
instance
-
.append(data) ⇒
element
-
.render() ⇒
HTMLElement
- .compute()
-
.append(data) ⇒
-
static
-
.id :
number
- .generateTooltip(node, data)
-
.id :
-
.getInputData(form) ⇒
object
-
.getElements(form, fieldName) ⇒
Array.<HTMLElement>
-
.getCheckboxOrRadio(elementArray, value) ⇒
HTMLInputElement
-
.getElementContainer(element) ⇒
HTMLElement
-
.getElementLabelObject(element) ⇒
HTMLElement
-
.getElementLabel(element) ⇒
string
-
.setElementLabel(element, labelText) ⇒
boolean
-
.overrideElementLabel(element, temporaryLabelText) ⇒
boolean
-
.resetElementLabel(element) ⇒
boolean
- .setElementVisibility(element, [visibility])
- .setElementTooltipVisibility(element, [visibility])
-
.element
-
.unbinder
- new Morebits.unbinder(string)
-
instance
- .content
- .unbind(prefix, postfix)
-
.rebind() ⇒
string
- static
-
.date
- new Morebits.date()
-
instance
-
.isValid() ⇒
boolean
-
.isBefore(date) ⇒
boolean
-
.isAfter(date) ⇒
boolean
-
.getUTCMonthName() ⇒
string
-
.getUTCMonthNameAbbrev() ⇒
string
-
.getMonthName() ⇒
string
-
.getMonthNameAbbrev() ⇒
string
-
.getUTCDayName() ⇒
string
-
.getUTCDayNameAbbrev() ⇒
string
-
.getDayName() ⇒
string
-
.getDayNameAbbrev() ⇒
string
-
.add(number, unit) ⇒
date
-
.subtract(number, unit) ⇒
date
-
.format(formatstr, [zone]) ⇒
string
-
.calendar([zone]) ⇒
string
-
.monthHeaderRegex() ⇒
RegExp
-
.monthHeader([level]) ⇒
string
-
.isValid() ⇒
-
static
-
.unitMap :
object.<string, string>
-
.unitMap :
-
.userspaceLogger
- new Morebits.userspaceLogger(logPageName)
-
.initialText :
string
-
.headerLevel :
number
-
.log(logText, summaryText) ⇒
JQuery.Promise
-
.status
- new Morebits.status(text, stat, [type])
-
instance
- .link()
- .unlink()
-
.codify(obj) ⇒
DocumentFragment
- .update(status, type)
- .generate()
- .render()
- static
- .batchOperation
- .taskManager
-
.simpleWindow
- new Morebits.simpleWindow(width, height)
-
instance
-
.focus() ⇒
simpleWindow
-
.close([event]) ⇒
simpleWindow
-
.display() ⇒
simpleWindow
-
.setTitle(title) ⇒
simpleWindow
-
.setScriptName(name) ⇒
simpleWindow
-
.setWidth(width) ⇒
simpleWindow
-
.setHeight(height) ⇒
simpleWindow
-
.setContent(content) ⇒
simpleWindow
-
.addContent(content) ⇒
simpleWindow
-
.purgeContent() ⇒
simpleWindow
-
.addFooterLink(text, wikiPage, [prep]) ⇒
simpleWindow
-
.setModality([modal]) ⇒
simpleWindow
-
.focus() ⇒
- static
-
.userIsSysop :
boolean
-
.pageNameNorm :
string
-
.ip :
object
-
.sanitizeIPv6(address) ⇒
string
-
.isRange(ip) ⇒
boolean
-
.validCIDR() ⇒
boolean
-
.get64(ipv6) ⇒
boolean
|string
-
.sanitizeIPv6(address) ⇒
-
.string :
object
-
.toUpperCaseFirstChar(str) ⇒
string
-
.toLowerCaseFirstChar(str) ⇒
string
-
.splitWeightedByKeys(str, start, end, [skiplist]) ⇒
Array.<string>
-
.formatReasonText(str, [addSig]) ⇒
string
-
.formatReasonForLog(str) ⇒
string
-
.safeReplace(string, pattern, replacement) ⇒
string
-
.isInfinity(expiry) ⇒
boolean
-
.escapeRegExp(text) ⇒
string
-
.toUpperCaseFirstChar(str) ⇒
-
.array :
object
-
.uniq(arr) ⇒
Array
-
.dups(arr) ⇒
Array
-
.chunk(arr, size) ⇒
Array.<Array>
-
.uniq(arr) ⇒
-
.select2 :
object
-
.wiki :
object
- .api
-
.page
- new Morebits.wiki.page(pageName, [status])
-
instance
- .load(onSuccess, [onFailure])
- .save([onSuccess], [onFailure])
- .append([onSuccess], [onFailure])
- .prepend([onSuccess], [onFailure])
- .newSection([onSuccess], [onFailure])
-
.getPageName() ⇒
string
-
.getPageText() ⇒
string
- .setPageText(pageText)
- .setAppendText(appendText)
- .setPrependText(prependText)
- .setNewSectionText(newSectionText)
- .setNewSectionTitle(newSectionTitle)
- .setEditSummary(summary)
- .setChangeTags(tags)
- .setCreateOption([createOption])
- .setMinorEdit(minorEdit)
- .setBotEdit(botEdit)
- .setPageSection(pageSection)
- .setMaxConflictRetries(maxConflictRetries)
- .setMaxRetries(maxRetries)
- .setWatchlist([watchlistOption])
- .setWatchlistExpiry(watchlistExpiry)
.setWatchlistFromPreferences([watchlistOption])- .setFollowRedirect([followRedirect], [followCrossNsRedirect])
- .setLookupNonRedirectCreator(flag)
- .setMoveDestination(destination)
- .setMoveTalkPage(flag)
- .setMoveSubpages(flag)
- .setMoveSuppressRedirect(flag)
- .setEditProtection(level, [expiry])
-
.getCurrentID() ⇒
string
-
.getRevisionUser() ⇒
string
-
.getLastEditTime() ⇒
string
- .setCallbackParameters(callbackParameters)
-
.getCallbackParameters() ⇒
object
- .setStatusElement(statusElement)
-
.getStatusElement() ⇒
status
- .setFlaggedRevs(level, [expiry])
-
.exists() ⇒
boolean
-
.getPageID() ⇒
string
-
.getContentModel() ⇒
string
-
.getWatched() ⇒
boolean
|string
-
.getLoadTime() ⇒
string
-
.getCreator() ⇒
string
-
.getCreationTimestamp() ⇒
string
-
.canEdit() ⇒
boolean
- .lookupCreation(onSuccess)
- .revert([onSuccess], [onFailure])
- .move([onSuccess], [onFailure])
- .patrol()
- .triage()
- .deletePage([onSuccess], [onFailure])
- .undeletePage([onSuccess], [onFailure])
- .protect([onSuccess], [onFailure])
- .stabilize([onSuccess], [onFailure])
-
inner
-
~fnCanUseMwUserToken([action]) ⇒
boolean
-
~fnNeedTokenInfoQuery(action) ⇒
object
-
~fnPreflightChecks(action, onFailure) ⇒
boolean
-
~fnProcessChecks(action, onFailure, response) ⇒
boolean
-
~fnCanUseMwUserToken([action]) ⇒
- .preview
-
.numberOfActionsLeft :
number
-
.nbrOfCheckpointsLeft :
number
.isPageRedirect() ⇒boolean
- .actionCompleted()
- .addCheckpoint()
- .removeCheckpoint()
-
.wikitext :
object
- .page
-
.parseTemplate(text, [start]) ⇒
object
-
.userIsInGroup(group) ⇒
boolean
.sanitizeIPv6(address) ⇒string
-
.isPageRedirect() ⇒
boolean
-
.pageNameRegex(pageName) ⇒
string
-
.namespaceRegex(namespaces) ⇒
string
-
.htmlNode(type, content, [color]) ⇒
HTMLElement
- .checkboxShiftClickSupport(jQuerySelector, jQueryContext)
-
.quickForm
Kind: static class of Morebits
-
.quickForm
- new quickForm(event, [eventType])
-
instance
-
.render() ⇒
HTMLElement
-
.append(data) ⇒
element
-
.render() ⇒
-
static
-
.element
- new Morebits.quickForm.element(data)
-
instance
-
.append(data) ⇒
element
-
.render() ⇒
HTMLElement
- .compute()
-
.append(data) ⇒
-
static
-
.id :
number
- .generateTooltip(node, data)
-
.id :
-
.getInputData(form) ⇒
object
-
.getElements(form, fieldName) ⇒
Array.<HTMLElement>
-
.getCheckboxOrRadio(elementArray, value) ⇒
HTMLInputElement
-
.getElementContainer(element) ⇒
HTMLElement
-
.getElementLabelObject(element) ⇒
HTMLElement
-
.getElementLabel(element) ⇒
string
-
.setElementLabel(element, labelText) ⇒
boolean
-
.overrideElementLabel(element, temporaryLabelText) ⇒
boolean
-
.resetElementLabel(element) ⇒
boolean
- .setElementVisibility(element, [visibility])
- .setElementTooltipVisibility(element, [visibility])
-
.element
Creation of simple and standard forms without much specific coding.
Param | Type | Default | Description |
---|---|---|---|
event | event |
Function to execute when form is submitted. |
|
[eventType] | string |
"submit" |
Type of the event. |
Renders the HTML output of the quickForm.
Kind: instance method of quickForm
quickForm.append(data) ⇒ element
Append element to the form.
Kind: instance method of quickForm
Returns: element
- - Same as what is passed to the function.
Param | Type | Description |
---|---|---|
data |
object | element
|
A quickform element, or the object with which a quickform element is constructed. |
Kind: static class of quickForm
-
.element
- new Morebits.quickForm.element(data)
-
instance
-
.append(data) ⇒
element
-
.render() ⇒
HTMLElement
- .compute()
-
.append(data) ⇒
-
static
-
.id :
number
- .generateTooltip(node, data)
-
.id :
Create a new element for the the form.
Index to Morebits.quickForm.element types:
- Global attributes: id, className, style, tooltip, extra, adminonly
-
select
: A combo box (aka drop-down).- Attributes: name, label, multiple, size, list, event, disabled
-
option
: An element for a combo box.- Attributes: value, label, selected, disabled
-
optgroup
: A group of "option"s.- Attributes: label, list
-
field
: A fieldset (aka group box).- Attributes: name, label, disabled
-
checkbox
: A checkbox. Must use "list" parameter.- Attributes: name, list, event
- Attributes (within list): name, label, value, checked, disabled, event, subgroup
-
radio
: A radio button. Must use "list" parameter.- Attributes: name, list, event
- Attributes (within list): name, label, value, checked, disabled, event, subgroup
-
input
: A text box.- Attributes: name, label, value, size, disabled, required, readonly, maxlength, event
-
dyninput
: A set of text boxes with "Remove" buttons and an "Add" button.- Attributes: name, label, min, max, sublabel, value, size, maxlength, event
-
hidden
: An invisible form field.- Attributes: name, value
-
header
: A level 5 header.- Attributes: label
-
div
: A generic placeholder element or label.- Attributes: name, label
-
submit
: A submit button. Morebits.simpleWindow moves these to the footer of the dialog.- Attributes: name, label, disabled
-
button
: A generic button.- Attributes: name, label, disabled, event
-
textarea
: A big, multi-line text box.- Attributes: name, label, value, cols, rows, disabled, required, readonly
-
fragment
: A DocumentFragment object.- No attributes, and no global attributes except adminonly.
Param | Type | Description |
---|---|---|
data | object |
Object representing the quickform element. Should specify one of the available types from the index above, as well as any relevant and available attributes. |
Example
new Morebits.quickForm.element({
name: 'target',
type: 'input',
label: 'Your target:',
tooltip: 'Enter your target. Required.',
required: true
});
element.append(data) ⇒ element
Appends an element to current element.
Kind: instance method of element
Returns: element
- The same element passed in.
Param | Type | Description |
---|---|---|
data | element |
A quickForm element or the object required to create the quickForm element. |
Renders the HTML output for the quickForm element. This should be called
without parameters: form.render()
.
Kind: instance method of element
Kind: instance method of element
Kind: static property of element
Create a jQuery UI-based tooltip.
Kind: static method of element
Requires: module:jquery.ui
Param | Type | Description |
---|---|---|
node | HTMLElement |
The HTML element beside which a tooltip is to be generated. |
data | object |
Tooltip-related configuration data. |
Returns an object containing all filled form data entered by the user, with the object keys being the form element names. Disabled fields will be ignored, but not hidden fields.
Kind: static method of quickForm
Returns: object
- With field names as keys, input data as values.
Param | Type |
---|---|
form | HTMLFormElement |
Returns all form elements with a given field name or ID.
Kind: static method of quickForm
Returns: Array.<HTMLElement>
- - Array of matching form elements.
Param | Type | Description |
---|---|---|
form | HTMLFormElement |
|
fieldName | string |
The name or id of the fields. |
Searches the array of elements for a checkbox or radio button with a certain
value
attribute, and returns the first such element. Returns null if not found.
Kind: static method of quickForm
Param | Type | Description |
---|---|---|
elementArray | Array.<HTMLInputElement> |
Array of checkbox or radio elements. |
value | string |
Value to search for. |
Returns the <div> containing the form element, or the form element itself May not work as expected on checkboxes or radios.
Kind: static method of quickForm
Param | Type |
---|---|
element | HTMLElement |
Gets the HTML element that contains the label of the given form element (mainly for internal use).
Kind: static method of quickForm
Param | Type |
---|---|
element |
HTMLElement | element
|
Gets the label text of the element.
Kind: static method of quickForm
Param | Type |
---|---|
element |
HTMLElement | element
|
Sets the label of the element to the given text.
Kind: static method of quickForm
Returns: boolean
- True if succeeded, false if the label element is unavailable.
Param | Type |
---|---|
element |
HTMLElement | element
|
labelText | string |
Stores the element's current label, and temporarily sets the label to the given text.
Kind: static method of quickForm
Returns: boolean
- true
if succeeded, false
if the label element is unavailable.
Param | Type |
---|---|
element |
HTMLElement | element
|
temporaryLabelText | string |
Restores the label stored by overrideElementLabel.
Kind: static method of quickForm
Returns: boolean
- True if succeeded, false if the label element is unavailable.
Param | Type |
---|---|
element |
HTMLElement | element
|
Shows or hides a form element plus its label and tooltip.
Kind: static method of quickForm
Param | Type | Description |
---|---|---|
element |
HTMLElement | jQuery | string
|
HTML/jQuery element, or jQuery selector string. |
[visibility] | boolean |
Skip this to toggle visibility. |
Shows or hides the question mark icon (which displays the tooltip) next to a form element.
Kind: static method of quickForm
Param | Type | Description |
---|---|---|
element |
HTMLElement | jQuery
|
|
[visibility] | boolean |
Skip this to toggle visibility. |
Kind: static class of Morebits
-
.unbinder
- new Morebits.unbinder(string)
-
instance
- .content
- .unbind(prefix, postfix)
-
.rebind() ⇒
string
- static
Temporarily hide a part of a string while processing the rest of it. Used by Morebits.wikitext.page.commentOutImage.
Param | Type | Description |
---|---|---|
string | string |
The initial text to process. |
Example
var u = new Morebits.unbinder('Hello world <!-- world --> world');
u.unbind('<!--', '-->'); // text inside comment remains intact
u.content = u.content.replace(/world/g, 'earth');
u.rebind(); // gives 'Hello earth <!-- world --> earth'
The text being processed.
Kind: instance property of unbinder
Hide the region encapsulated by the prefix
and postfix
from
string processing. prefix
and postfix
will be used in a
RegExp, so items that need escaping should be use \\
.
Kind: instance method of unbinder
Throws:
- If either
prefix
orpostfix
is missing.
Param | Type |
---|---|
prefix | string |
postfix | string |
Restore the hidden portion of the content
string.
Kind: instance method of unbinder
Returns: string
- The processed output.
Kind: static method of unbinder
Kind: static class of Morebits
-
.date
- new Morebits.date()
-
instance
-
.isValid() ⇒
boolean
-
.isBefore(date) ⇒
boolean
-
.isAfter(date) ⇒
boolean
-
.getUTCMonthName() ⇒
string
-
.getUTCMonthNameAbbrev() ⇒
string
-
.getMonthName() ⇒
string
-
.getMonthNameAbbrev() ⇒
string
-
.getUTCDayName() ⇒
string
-
.getUTCDayNameAbbrev() ⇒
string
-
.getDayName() ⇒
string
-
.getDayNameAbbrev() ⇒
string
-
.add(number, unit) ⇒
date
-
.subtract(number, unit) ⇒
date
-
.format(formatstr, [zone]) ⇒
string
-
.calendar([zone]) ⇒
string
-
.monthHeaderRegex() ⇒
RegExp
-
.monthHeader([level]) ⇒
string
-
.isValid() ⇒
-
static
-
.unitMap :
object.<string, string>
-
.unitMap :
Create a date object with enhanced processing capabilities, a la moment.js. MediaWiki timestamp format is also acceptable, in addition to everything that JS Date() accepts.
Kind: instance method of date
Kind: instance method of date
Param | Type |
---|---|
date |
Date | date
|
Kind: instance method of date
Param | Type |
---|---|
date |
Date | date
|
Kind: instance method of date
Kind: instance method of date
Kind: instance method of date
Kind: instance method of date
Kind: instance method of date
Kind: instance method of date
Kind: instance method of date
Kind: instance method of date
date.add(number, unit) ⇒ date
Add a given number of minutes, hours, days, months or years to the date. This is done in-place. The modified date object is also returned, allowing chaining.
Kind: instance method of date
Throws:
- If invalid or unsupported unit is given.
Param | Type | Description |
---|---|---|
number | number |
Should be an integer. |
unit | string |
date.subtract(number, unit) ⇒ date
Subtracts a given number of minutes, hours, days, months or years to the date. This is done in-place. The modified date object is also returned, allowing chaining.
Kind: instance method of date
Throws:
- If invalid or unsupported unit is given.
Param | Type | Description |
---|---|---|
number | number |
Should be an integer. |
unit | string |
Format the date into a string per the given format string. Replacement syntax is a subset of that in moment.js:
Syntax | Output |
---|---|
H | Hours (24-hour) |
HH | Hours (24-hour, padded) |
h | Hours (12-hour) |
hh | Hours (12-hour, padded) |
A | AM or PM |
m | Minutes |
mm | Minutes (padded) |
s | Seconds |
ss | Seconds (padded) |
SSS | Milliseconds fragment, padded |
d | Day number of the week (Sun=0) |
ddd | Abbreviated day name |
dddd | Full day name |
D | Date |
DD | Date (padded) |
M | Month number (0-indexed) |
MM | Month number (0-indexed, padded) |
MMM | Abbreviated month name |
MMMM | Full month name |
Y | Year |
YY | Final two digits of year (20 for 2020, 42 for 1942) |
YYYY | Year (same as Y ) |
Kind: instance method of date
Param | Type | Default | Description |
---|---|---|---|
formatstr | string |
Format the date into a string, using
the replacement syntax. Use |
|
[zone] |
string | number
|
"system" |
|
Gives a readable relative time string such as "Yesterday at 6:43 PM" or "Last Thursday at 11:45 AM".
Similar to calendar
in moment.js, but with time zone support.
Kind: instance method of date
Param | Type | Default | Description |
---|---|---|---|
[zone] |
string | number
|
"system" |
'system' (for browser-default time zone), 'utc' (for UTC), or specify a time zone as number of minutes past UTC. |
Get a regular expression that matches wikitext section titles, such
as ==December 2019==
or === Jan 2018 ===
.
Kind: instance method of date
Creates a wikitext section header with the month and year.
Kind: instance method of date
Param | Type | Default | Description |
---|---|---|---|
[level] | number |
2 |
Header level. Pass 0 for just the text with no wikitext markers (==). |
Map units with getter/setter function names, for add
and subtract
methods.
Kind: static property of date
Kind: static class of Morebits
-
.userspaceLogger
- new Morebits.userspaceLogger(logPageName)
-
.initialText :
string
-
.headerLevel :
number
-
.log(logText, summaryText) ⇒
JQuery.Promise
Handles logging actions to a userspace log. Used in CSD, PROD, and XFD.
Param | Type | Description |
---|---|---|
logPageName | string |
Title of the subpage of the current user's log. |
The text to prefix the log with upon creation, defaults to empty.
Kind: instance property of userspaceLogger
The header level to use for months, defaults to 3 (===
).
Kind: instance property of userspaceLogger
Log the entry.
Kind: instance method of userspaceLogger
Param | Type | Description |
---|---|---|
logText | string |
Doesn't include leading |
summaryText | string |
Edit summary. |
Kind: static class of Morebits
-
.status
- new Morebits.status(text, stat, [type])
-
instance
- .link()
- .unlink()
-
.codify(obj) ⇒
DocumentFragment
- .update(status, type)
- .generate()
- .render()
- static
Create and show status messages of varying urgency. Morebits.status.init() must be called before any status object is created, otherwise those statuses won't be visible.
Param | Type | Default | Description |
---|---|---|---|
text | string |
Text before the the colon |
|
stat | string |
Text after the colon |
|
[type] | string |
"status" |
Determine the font color of the status
line, allowable values are: |
Add the status element node to the DOM.
Kind: instance method of status
Remove the status element node from the DOM.
Kind: instance method of status
Create a document fragment with the status text, parsing as HTML. Runs upon construction for text (part before colon) and upon render/update for status (part after colon).
Kind: instance method of status
Param | Type |
---|---|
obj |
string | Element | Array
|
Update the status.
Kind: instance method of status
Param | Type | Description |
---|---|---|
status | string |
Part of status message after colon. |
type | string |
'status' (blue), 'info' (green), 'warn' (red), or 'error' (bold red). |
Produce the html for first part of the status message.
Kind: instance method of status
Complete the html, for the second part of the status message.
Kind: instance method of status
Specify an area for status message elements to be added to.
Kind: static method of status
Throws:
- If
root
is not anHTMLElement
.
Param | Type | Description |
---|---|---|
root | HTMLElement |
Usually a div element. |
Kind: static method of status
Throws:
- When
handler
is not a function.
Param | Type | Description |
---|---|---|
handler | function |
Function to execute on error. |
status.status(text, status) ⇒ status
Kind: static method of status
Returns: status
- - status
-type (blue)
Param | Type | Description |
---|---|---|
text | string |
Before colon |
status | string |
After colon |
status.info(text, status) ⇒ status
Kind: static method of status
Returns: status
- - info
-type (green)
Param | Type | Description |
---|---|---|
text | string |
Before colon |
status | string |
After colon |
status.warn(text, status) ⇒ status
Kind: static method of status
Returns: status
- - warn
-type (red)
Param | Type | Description |
---|---|---|
text | string |
Before colon |
status | string |
After colon |
status.error(text, status) ⇒ status
Kind: static method of status
Returns: status
- - error
-type (bold red)
Param | Type | Description |
---|---|---|
text | string |
Before colon |
status | string |
After colon |
For the action complete message at the end, create a status line without a colon separator.
Kind: static method of status
Param | Type |
---|---|
text | string |
Display the user's rationale, comments, etc. Back to them after a failure, so that they may re-use it.
Kind: static method of status
Param | Type |
---|---|
comments | string |
message | string |
Kind: static class of Morebits
Iterates over a group of pages (or arbitrary objects) and executes a worker function for each.
setPageList(pageList)
: Sets the list of pages to work on. It should be an
array of page names strings.
setOption(optionName, optionValue)
: Sets a known option:
-
chunkSize
(integer): The size of chunks to break the array into (default 50). Setting this to a small value (<5) can cause problems. -
preserveIndividualStatusLines
(boolean): Keep each page's status element visible when worker is complete? See note below.
run(worker, postFinish)
: Runs the callback worker
for each page in the
list. The callback must call workerSuccess
when succeeding, or
workerFailure
when failing. If using api or
page, this is easily done by passing these two
functions as parameters to the methods on those objects: for instance,
page.save(batchOp.workerSuccess, batchOp.workerFailure)
. Make sure the
methods are called directly if special success/failure cases arise. If you
omit to call these methods, the batch operation will stall after the first
chunk! Also ensure that either workerSuccess or workerFailure is called no
more than once. The second callback postFinish
is executed when the
entire batch has been processed.
If using preserveIndividualStatusLines
, you should try to ensure that the
workerSuccess
callback has access to the page title. This is no problem for
page objects. But when using the API, please set the
|pageName| property on the api object.
There are sample batchOperation implementations using Morebits.wiki.page in twinklebatchdelete.js, twinklebatchundelete.js, and twinklebatchprotect.js.
Param | Type |
---|---|
[currentAction] | string |
Sets the list of pages to work on.
Kind: instance method of batchOperation
Param | Type | Description |
---|---|---|
pageList | Array |
Array of objects over which you wish to execute the worker function This is usually the list of page names (strings). |
Sets a known option.
Kind: instance method of batchOperation
Param | Type | Description |
---|---|---|
optionName | string |
Name of the option:
|
optionValue |
number | boolean
|
Value to which the option is to be set. Should be an integer for chunkSize and a boolean for preserveIndividualStatusLines. |
Runs the first callback for each page in the list. The callback must call workerSuccess when succeeding, or workerFailure when failing. Runs the optional second callback when the whole batch has been processed.
Kind: instance method of batchOperation
Param | Type |
---|---|
worker | function |
[postFinish] | function |
To be called by worker before it terminates succesfully.
Kind: instance method of batchOperation
Param | Type | Description |
---|---|---|
arg |
page | api | string
|
This should be the |
Kind: static class of Morebits
Given a set of asynchronous functions to run along with their dependencies, figure out an efficient sequence of running them so that multiple functions that don't depend on each other are triggered simultaneously. Where dependencies exist, it ensures that the dependency functions finish running before the dependent function runs. The values resolved by the dependencies are made available to the dependant as arguments.
Register a task along with its dependencies (tasks which should have finished execution before we can begin this one). Each task is a function that must return a promise. The function will get the values resolved by the dependency functions as arguments.
Kind: instance method of taskManager
Param | Type | Description |
---|---|---|
func | function |
A task. |
deps | Array.<function()> |
Its dependencies. |
Run all the tasks. Multiple tasks may be run at once.
Kind: instance method of taskManager
Returns: promise
- - A jQuery promise object that is resolved or rejected with the api object.
Kind: static class of Morebits
Requires: module:jquery.ui.dialog
-
.simpleWindow
- new Morebits.simpleWindow(width, height)
-
instance
-
.focus() ⇒
simpleWindow
-
.close([event]) ⇒
simpleWindow
-
.display() ⇒
simpleWindow
-
.setTitle(title) ⇒
simpleWindow
-
.setScriptName(name) ⇒
simpleWindow
-
.setWidth(width) ⇒
simpleWindow
-
.setHeight(height) ⇒
simpleWindow
-
.setContent(content) ⇒
simpleWindow
-
.addContent(content) ⇒
simpleWindow
-
.purgeContent() ⇒
simpleWindow
-
.addFooterLink(text, wikiPage, [prep]) ⇒
simpleWindow
-
.setModality([modal]) ⇒
simpleWindow
-
.focus() ⇒
- static
A simple draggable window, now a wrapper for jQuery UI's dialog feature.
Param | Type | Description |
---|---|---|
width | number |
|
height | number |
The maximum allowable height for the content area. |
simpleWindow.focus() ⇒ simpleWindow
Focuses the dialog. This might work, or on the contrary, it might not.
Kind: instance method of simpleWindow
simpleWindow.close([event]) ⇒ simpleWindow
Closes the dialog. If this is set as an event handler, it will stop the event from doing anything more.
Kind: instance method of simpleWindow
Param | Type |
---|---|
[event] | event |
simpleWindow.display() ⇒ simpleWindow
Shows the dialog. Calling display() on a dialog that has previously been closed might work, but it is not guaranteed.
Kind: instance method of simpleWindow
simpleWindow.setTitle(title) ⇒ simpleWindow
Sets the dialog title.
Kind: instance method of simpleWindow
Param | Type |
---|---|
title | string |
simpleWindow.setScriptName(name) ⇒ simpleWindow
Sets the script name, appearing as a prefix to the title to help users determine which user script is producing which dialog. For instance, Twinkle modules set this to "Twinkle".
Kind: instance method of simpleWindow
Param | Type |
---|---|
name | string |
simpleWindow.setWidth(width) ⇒ simpleWindow
Sets the dialog width.
Kind: instance method of simpleWindow
Param | Type |
---|---|
width | number |
simpleWindow.setHeight(height) ⇒ simpleWindow
Sets the dialog's maximum height. The dialog will auto-size to fit its contents, but the content area will grow no larger than the height given here.
Kind: instance method of simpleWindow
Param | Type |
---|---|
height | number |
simpleWindow.setContent(content) ⇒ simpleWindow
Sets the content of the dialog to the given element node, usually from rendering a quickForm. Re-enumerates the footer buttons, but leaves the footer links as they are. Be sure to call this at least once before the dialog is displayed...
Kind: instance method of simpleWindow
Param | Type |
---|---|
content | HTMLElement |
simpleWindow.addContent(content) ⇒ simpleWindow
Adds the given element node to the dialog content.
Kind: instance method of simpleWindow
Param | Type |
---|---|
content | HTMLElement |
simpleWindow.purgeContent() ⇒ simpleWindow
Removes all contents from the dialog, barring any footer links.
Kind: instance method of simpleWindow
simpleWindow.addFooterLink(text, wikiPage, [prep]) ⇒ simpleWindow
Adds a link in the bottom-right corner of the dialog. This can be used to provide help or policy links. For example, Twinkle's CSD module adds a link to the CSD policy page, as well as a link to Twinkle's documentation.
Kind: instance method of simpleWindow
Param | Type | Default | Description |
---|---|---|---|
text | string |
Display text. |
|
wikiPage | string |
Link target. |
|
[prep] | boolean |
false |
Set true to prepend rather than append. |
simpleWindow.setModality([modal]) ⇒ simpleWindow
Sets whether the window should be modal or not. Modal dialogs create an overlay below the dialog but above other page elements. This must be used (if necessary) before calling display().
Kind: instance method of simpleWindow
Param | Type | Default | Description |
---|---|---|---|
[modal] | boolean |
false |
If set to true, other items on the page will be disabled, i.e., cannot be interacted with. |
Enables or disables all footer buttons on all simpleWindows in the current page.
This should be called with false
when the button(s) become irrelevant (e.g. just before
init is called).
This is not an instance method so that consumers don't have to keep a reference to the
original Morebits.simpleWindow
object sitting around somewhere. Anyway, most of the time
there will only be one Morebits.simpleWindow
open, so this shouldn't matter.
Kind: static method of simpleWindow
Param | Type |
---|---|
enabled | boolean |
Hardcodes whether the user is a sysop, used a lot.
Kind: static property of Morebits
Stores a normalized (underscores converted to spaces) version of the
wgPageName
variable.
Kind: static property of Morebits
Utilities to help process IP addresses.
Kind: static namespace of Morebits
-
.ip :
object
-
.sanitizeIPv6(address) ⇒
string
-
.isRange(ip) ⇒
boolean
-
.validCIDR() ⇒
boolean
-
.get64(ipv6) ⇒
boolean
|string
-
.sanitizeIPv6(address) ⇒
Converts an IPv6 address to the canonical form stored and used by MediaWiki.
JavaScript translation of the IP::sanitizeIP()
function from the IPUtils library. Adddresses are verbose, uppercase,
normalized, and expanded to 8 words.
Kind: static method of ip
Param | Type | Description |
---|---|---|
address | string |
The IPv6 address, with or without CIDR. |
Determine if the given IP address is a range. Just conjoins
mw.util.isIPAddress
with and without the allowBlock
option.
Kind: static method of ip
Returns: boolean
- - True if given a valid IP address range, false otherwise.
Param | Type |
---|---|
ip | string |
Check that an IP range is within the CIDR limits. Most likely to be useful
in conjunction with wgRelevantUserName
. CIDR limits are harcoded as /16
for IPv4 and /32 for IPv6.
Kind: static method of ip
Returns: boolean
- - True for valid ranges within the CIDR limits,
otherwise false (ranges outside the limit, single IPs, non-IPs).
Get the /64 subnet for an IPv6 address.
Kind: static method of ip
Returns: boolean
| string
- - False if not IPv6 or bigger than a 64,
otherwise the (sanitized) /64 address.
Param | Type | Description |
---|---|---|
ipv6 | string |
The IPv6 address, with or without a subnet. |
Helper functions to manipulate strings.
Kind: static namespace of Morebits
-
.string :
object
-
.toUpperCaseFirstChar(str) ⇒
string
-
.toLowerCaseFirstChar(str) ⇒
string
-
.splitWeightedByKeys(str, start, end, [skiplist]) ⇒
Array.<string>
-
.formatReasonText(str, [addSig]) ⇒
string
-
.formatReasonForLog(str) ⇒
string
-
.safeReplace(string, pattern, replacement) ⇒
string
-
.isInfinity(expiry) ⇒
boolean
-
.escapeRegExp(text) ⇒
string
-
.toUpperCaseFirstChar(str) ⇒
Kind: static method of string
Param | Type |
---|---|
str | string |
Kind: static method of string
Param | Type |
---|---|
str | string |
Gives an array of substrings of str
- starting with start
and
ending with end
- which is not in skiplist
. Intended for use
on wikitext with templates or links.
Kind: static method of string
Throws:
- If the
start
andend
strings aren't of the same length. - If
skiplist
isn't an array or string
Param | Type |
---|---|
str | string |
start | string |
end | string |
[skiplist] |
Array.<string> | string
|
Formats freeform "reason" (from a textarea) for deletion/other
templates that are going to be substituted, (e.g. PROD, XFD, RPP).
Handles |
outside a nowiki tag.
Optionally, also adds a signature if not present already.
Kind: static method of string
Param | Type |
---|---|
str | string |
[addSig] | boolean |
Formats a "reason" (from a textarea) for inclusion in a userspace
log. Replaces newlines with {{Pb}}, and adds an extra #
before
list items for proper formatting.
Kind: static method of string
Param | Type |
---|---|
str | string |
Like String.prototype.replace()
, but escapes any dollar signs in
the replacement string. Useful when the the replacement string is
arbitrary, such as a username or freeform user input, and could
contain dollar signs.
Kind: static method of string
Param | Type | Description |
---|---|---|
string | string |
Text in which to replace. |
pattern |
string | RegExp
|
|
replacement | string |
Determine if the user-provided expiration will be considered an infinite-length by MW.
Kind: static method of string
See: https://phabricator.wikimedia.org/T68646
Param | Type |
---|---|
expiry | string |
Escapes a string to be used in a RegExp, replacing spaces and
underscores with [_ ]
as they are often equivalent.
Replaced RegExp.escape September 2020.
Kind: static method of string
Returns: string
- - The escaped text.
Param | Type | Description |
---|---|---|
text | string |
String to be escaped. |
Helper functions to manipulate arrays.
Kind: static namespace of Morebits
-
.array :
object
-
.uniq(arr) ⇒
Array
-
.dups(arr) ⇒
Array
-
.chunk(arr, size) ⇒
Array.<Array>
-
.uniq(arr) ⇒
Remove duplicated items from an array.
Kind: static method of array
Returns: Array
- A copy of the array with duplicates removed.
Throws:
- When provided a non-array.
Param | Type |
---|---|
arr | Array |
Remove non-duplicated items from an array.
Kind: static method of array
Returns: 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.
Param | Type |
---|---|
arr | Array |
Break up an array into smaller arrays.
Kind: static method of array
Returns: Array.<Array>
- An array containing the smaller, chunked arrays.
Throws:
- When provided a non-array.
Param | Type | Description |
---|---|---|
arr | Array |
|
size | number |
Size of each chunk (except the last, which could be different). |
Utilities to enhance select2 menus. See twinklewarn, twinklexfd, twinkleblock for sample usages.
Kind: static namespace of Morebits
Requires: module:jquery.select2
See: https://select2.org/
Underline matched part of options.
Kind: static method of select2
Intercept query as it is happening, for use in highlightSearchMatches.
Kind: static method of select2
Open dropdown and begin search when the .select2-selection
has
focus and a key is pressed.
Kind: static method of select2
See: https://github.com/select2/select2/issues/3279#issuecomment-442524147
Various objects for wiki editing and API access, including api and page.
Kind: static namespace of Morebits
-
.wiki :
object
- .api
-
.page
- new Morebits.wiki.page(pageName, [status])
-
instance
- .load(onSuccess, [onFailure])
- .save([onSuccess], [onFailure])
- .append([onSuccess], [onFailure])
- .prepend([onSuccess], [onFailure])
- .newSection([onSuccess], [onFailure])
-
.getPageName() ⇒
string
-
.getPageText() ⇒
string
- .setPageText(pageText)
- .setAppendText(appendText)
- .setPrependText(prependText)
- .setNewSectionText(newSectionText)
- .setNewSectionTitle(newSectionTitle)
- .setEditSummary(summary)
- .setChangeTags(tags)
- .setCreateOption([createOption])
- .setMinorEdit(minorEdit)
- .setBotEdit(botEdit)
- .setPageSection(pageSection)
- .setMaxConflictRetries(maxConflictRetries)
- .setMaxRetries(maxRetries)
- .setWatchlist([watchlistOption])
- .setWatchlistExpiry(watchlistExpiry)
.setWatchlistFromPreferences([watchlistOption])- .setFollowRedirect([followRedirect], [followCrossNsRedirect])
- .setLookupNonRedirectCreator(flag)
- .setMoveDestination(destination)
- .setMoveTalkPage(flag)
- .setMoveSubpages(flag)
- .setMoveSuppressRedirect(flag)
- .setEditProtection(level, [expiry])
-
.getCurrentID() ⇒
string
-
.getRevisionUser() ⇒
string
-
.getLastEditTime() ⇒
string
- .setCallbackParameters(callbackParameters)
-
.getCallbackParameters() ⇒
object
- .setStatusElement(statusElement)
-
.getStatusElement() ⇒
status
- .setFlaggedRevs(level, [expiry])
-
.exists() ⇒
boolean
-
.getPageID() ⇒
string
-
.getContentModel() ⇒
string
-
.getWatched() ⇒
boolean
|string
-
.getLoadTime() ⇒
string
-
.getCreator() ⇒
string
-
.getCreationTimestamp() ⇒
string
-
.canEdit() ⇒
boolean
- .lookupCreation(onSuccess)
- .revert([onSuccess], [onFailure])
- .move([onSuccess], [onFailure])
- .patrol()
- .triage()
- .deletePage([onSuccess], [onFailure])
- .undeletePage([onSuccess], [onFailure])
- .protect([onSuccess], [onFailure])
- .stabilize([onSuccess], [onFailure])
-
inner
-
~fnCanUseMwUserToken([action]) ⇒
boolean
-
~fnNeedTokenInfoQuery(action) ⇒
object
-
~fnPreflightChecks(action, onFailure) ⇒
boolean
-
~fnProcessChecks(action, onFailure, response) ⇒
boolean
-
~fnCanUseMwUserToken([action]) ⇒
- .preview
-
.numberOfActionsLeft :
number
-
.nbrOfCheckpointsLeft :
number
.isPageRedirect() ⇒boolean
- .actionCompleted()
- .addCheckpoint()
- .removeCheckpoint()
Kind: static class of wiki
An easy way to talk to the MediaWiki API. Accepts either json or xml
(default) formats; if json is selected, will default to formatversion=2
unless otherwise specified. Similarly, enforces newer errorformat
s,
defaulting to html
if unspecified. uselang
enforced to the wiki's
content language.
In new code, the use of the last 3 parameters should be avoided, instead
use setStatusElement() to bind
the status element (if needed) and use .then()
or .catch()
on the
promise returned by post()
, rather than specify the onSuccess
or
onFailure
callbacks.
Param | Type | Description |
---|---|---|
currentAction | string |
The current action (required). |
query | object |
The query (required). |
[onSuccess] | function |
The function to call when request is successful. |
[statusElement] | status |
A Morebits.status object to use for status messages. |
[onError] | function |
The function to call if an error occurs. |
Keep track of parent object for callbacks.
Kind: instance method of api
Param | Type |
---|---|
parent | * |
Kind: instance method of api
Param | Type |
---|---|
statusElement | status |
Carry out the request.
Kind: instance method of api
Returns: promise
- - A jQuery promise object that is resolved or rejected with the api object.
Param | Type | Description |
---|---|---|
callerAjaxParameters | object |
Do not specify a parameter unless you really really want to give jQuery some extra parameters. |
Change/revision tag applied to Morebits actions when no other tags are specified. Unused by default per EnWiki consensus.
Kind: static constant of api
Set the custom user agent header, which is used for server-side logging.
Note that doing so will set the useragent for every Morebits.wiki.api
process performed thereafter.
Kind: static method of api
See: https://lists.wikimedia.org/pipermail/mediawiki-api-announce/2014-November/000075.html
for original announcement.
Param | Type | Default | Description |
---|---|---|---|
[ua] | string |
"morebits.js ([[w:WT:TW]])" |
User agent. The default
value of |
Get a new CSRF token on encountering token errors.
Kind: static method of api
Returns: string
- MediaWiki CSRF token.
Kind: static class of wiki
-
.page
- new Morebits.wiki.page(pageName, [status])
-
instance
- .load(onSuccess, [onFailure])
- .save([onSuccess], [onFailure])
- .append([onSuccess], [onFailure])
- .prepend([onSuccess], [onFailure])
- .newSection([onSuccess], [onFailure])
-
.getPageName() ⇒
string
-
.getPageText() ⇒
string
- .setPageText(pageText)
- .setAppendText(appendText)
- .setPrependText(prependText)
- .setNewSectionText(newSectionText)
- .setNewSectionTitle(newSectionTitle)
- .setEditSummary(summary)
- .setChangeTags(tags)
- .setCreateOption([createOption])
- .setMinorEdit(minorEdit)
- .setBotEdit(botEdit)
- .setPageSection(pageSection)
- .setMaxConflictRetries(maxConflictRetries)
- .setMaxRetries(maxRetries)
- .setWatchlist([watchlistOption])
- .setWatchlistExpiry(watchlistExpiry)
.setWatchlistFromPreferences([watchlistOption])- .setFollowRedirect([followRedirect], [followCrossNsRedirect])
- .setLookupNonRedirectCreator(flag)
- .setMoveDestination(destination)
- .setMoveTalkPage(flag)
- .setMoveSubpages(flag)
- .setMoveSuppressRedirect(flag)
- .setEditProtection(level, [expiry])
-
.getCurrentID() ⇒
string
-
.getRevisionUser() ⇒
string
-
.getLastEditTime() ⇒
string
- .setCallbackParameters(callbackParameters)
-
.getCallbackParameters() ⇒
object
- .setStatusElement(statusElement)
-
.getStatusElement() ⇒
status
- .setFlaggedRevs(level, [expiry])
-
.exists() ⇒
boolean
-
.getPageID() ⇒
string
-
.getContentModel() ⇒
string
-
.getWatched() ⇒
boolean
|string
-
.getLoadTime() ⇒
string
-
.getCreator() ⇒
string
-
.getCreationTimestamp() ⇒
string
-
.canEdit() ⇒
boolean
- .lookupCreation(onSuccess)
- .revert([onSuccess], [onFailure])
- .move([onSuccess], [onFailure])
- .patrol()
- .triage()
- .deletePage([onSuccess], [onFailure])
- .undeletePage([onSuccess], [onFailure])
- .protect([onSuccess], [onFailure])
- .stabilize([onSuccess], [onFailure])
-
inner
-
~fnCanUseMwUserToken([action]) ⇒
boolean
-
~fnNeedTokenInfoQuery(action) ⇒
object
-
~fnPreflightChecks(action, onFailure) ⇒
boolean
-
~fnProcessChecks(action, onFailure, response) ⇒
boolean
-
~fnCanUseMwUserToken([action]) ⇒
Use the MediaWiki API to load a page and optionally edit it, move it, etc.
Callers are not permitted to directly access the properties of this class! All property access is through the appropriate get___() or set___() method.
Callers should set notice and redirect before the first call to Morebits.wiki.page.load().
Each of the callback functions takes one parameter, which is a reference to the Morebits.wiki.page object that registered the callback. Callback functions may invoke any Morebits.wiki.page prototype method using this reference.
Call sequence for common operations (optional final user callbacks not shown):
-
Edit current contents of a page (no edit conflict):
.load(userTextEditCallback) -> ctx.loadApi.post() -> ctx.loadApi.post.success() -> ctx.fnLoadSuccess() -> userTextEditCallback() -> .save() -> ctx.saveApi.post() -> ctx.loadApi.post.success() -> ctx.fnSaveSuccess()
-
Edit current contents of a page (with edit conflict):
.load(userTextEditCallback) -> ctx.loadApi.post() -> ctx.loadApi.post.success() -> ctx.fnLoadSuccess() -> userTextEditCallback() -> .save() -> ctx.saveApi.post() -> ctx.loadApi.post.success() -> ctx.fnSaveError() -> ctx.loadApi.post() -> ctx.loadApi.post.success() -> ctx.fnLoadSuccess() -> userTextEditCallback() -> .save() -> ctx.saveApi.post() -> ctx.loadApi.post.success() -> ctx.fnSaveSuccess()
-
Append to a page (similar for prepend and newSection):
.append() -> ctx.loadApi.post() -> ctx.loadApi.post.success() -> ctx.fnLoadSuccess() -> ctx.fnAutoSave() -> .save() -> ctx.saveApi.post() -> ctx.loadApi.post.success() -> ctx.fnSaveSuccess()
Notes:
- All functions following Morebits.wiki.api.post() are invoked asynchronously from the jQuery AJAX library.
- The sequence for append/prepend/newSection could be slightly shortened, but it would require significant duplication of code for little benefit.
Param | Type | Description |
---|---|---|
pageName | string |
The name of the page, prefixed by the namespace (if any).
For the current page, use |
[status] |
string | status
|
A string describing the action about to be undertaken, or a Morebits.status object |
Loads the text for the page.
Kind: instance method of page
Param | Type | Description |
---|---|---|
onSuccess | function |
Callback function which is called when the load has succeeded. |
[onFailure] | function |
Callback function which is called when the load fails. |
Saves the text for the page to Wikipedia.
Must be preceded by successfully calling load()
.
Warning: Calling save()
can result in additional calls to the
previous load()
callbacks to recover from edit conflicts! In this
case, callers must make the same edit to the new pageText and
reinvoke save()
. This behavior can be disabled with
setMaxConflictRetries(0)
.
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function which is called when the save has succeeded. |
[onFailure] | function |
Callback function which is called when the save fails. |
Adds the text provided via setAppendText()
to the end of the
page. Does not require calling load()
first, unless a watchlist
expiry is used.
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function which is called when the method has succeeded. |
[onFailure] | function |
Callback function which is called when the method fails. |
Adds the text provided via setPrependText()
to the start of the
page. Does not require calling load()
first, unless a watchlist
expiry is used.
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function which is called when the method has succeeded. |
[onFailure] | function |
Callback function which is called when the method fails. |
Creates a new section with the text provided by setNewSectionText()
and section title from setNewSectionTitle()
.
If editSummary
is provided, that will be used instead of the
autogenerated "->Title (new section" edit summary.
Does not require calling load()
first, unless a watchlist expiry
is used.
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function which is called when the method has succeeded. |
[onFailure] | function |
Callback function which is called when the method fails. |
Kind: instance method of page
Returns: string
- The name of the loaded page, including the namespace
Kind: instance method of page
Returns: string
- The text of the page after a successful load()
Kind: instance method of page
Param | Type | Description |
---|---|---|
pageText | string |
Updated page text that will be saved when |
Kind: instance method of page
Param | Type | Description |
---|---|---|
appendText | string |
Text that will be appended to the page when |
Kind: instance method of page
Param | Type | Description |
---|---|---|
prependText | string |
Text that will be prepended to the page when |
Kind: instance method of page
Param | Type | Description |
---|---|---|
newSectionText | string |
Text that will be added in a new section on the page when |
Kind: instance method of page
Param | Type | Description |
---|---|---|
newSectionTitle | string |
Title for the new section created when |
Set the edit summary that will be used when save()
is called.
Unnecessary if editMode is 'new' and newSectionTitle is provided.
Kind: instance method of page
Param | Type |
---|---|
summary | string |
Set any custom tag(s) to be applied to the API action. A number of actions don't support it, most notably watch, review, and stabilize (T247721), and pagetriageaction (T252980).
Kind: instance method of page
Param | Type | Description |
---|---|---|
tags |
string | Array.<string>
|
String or array of tag(s). |
Kind: instance method of page
Param | Type | Default | Description |
---|---|---|---|
[createOption] | string |
null |
Can take the following four values:
|
Kind: instance method of page
Param | Type | Description |
---|---|---|
minorEdit | boolean |
Set true to mark the edit as a minor edit. |
Kind: instance method of page
Param | Type | Description |
---|---|---|
botEdit | boolean |
Set true to mark the edit as a bot edit |
Kind: instance method of page
Param | Type | Description |
---|---|---|
pageSection | number |
Integer specifying the section number to load or save.
If specified as |
Kind: instance method of page
Param | Type | Description |
---|---|---|
maxConflictRetries | number |
Number of retries for save errors involving an edit conflict or loss of token. Default: 2. |
Kind: instance method of page
Param | Type | Description |
---|---|---|
maxRetries | number |
Number of retries for save errors not involving an edit conflict or loss of token. Default: 2. |
Kind: instance method of page
Param | Type | Default | Description |
---|---|---|---|
[watchlistOption] |
boolean | string
|
false |
Basically a mix of MW API and Twinkley options available pre-expiry:
|
Set an expiry. setWatchlist can handle this by itself if passed a string, so this is here largely for completeness and compatibility.
Kind: instance method of page
Param | Type | Description |
---|---|---|
watchlistExpiry | string |
A date-like string or array of strings
Can be relative (2 weeks) or other similarly date-like (i.e. NOT "potato"):
ISO 8601: 2038-01-09T03:14:07Z
MediaWiki: 20380109031407
UNIX: 2147483647
SQL: 2038-01-09 03:14:07
Can also be |
Deprecated
Kind: instance method of page
Param | Type | Default | Description |
---|---|---|---|
[watchlistOption] | boolean |
false |
Watchlist notes:
|
Kind: instance method of page
Param | Type | Default | Description |
---|---|---|---|
[followRedirect] | boolean |
false |
|
[followCrossNsRedirect] | boolean |
true |
Not applicable if
|
Kind: instance method of page
Param | Type | Description |
---|---|---|
flag | boolean |
If set true, the author and timestamp of the first non-redirect version of the page is retrieved. Warning:
|
Kind: instance method of page
Param | Type |
---|---|
destination | string |
Kind: instance method of page
Param | Type |
---|---|
flag | boolean |
Kind: instance method of page
Param | Type |
---|---|
flag | boolean |
Kind: instance method of page
Param | Type |
---|---|
flag | boolean |
Kind: instance method of page
Param | Type | Default | Description |
---|---|---|---|
level | string |
The right required for the specific action e.g. autoconfirmed, sysop, templateeditor, extendedconfirmed (enWiki-only). |
|
[expiry] | string |
"infinity" |
Kind: instance method of page
Returns: string
- The current revision ID of the page
Kind: instance method of page
Returns: string
- Last editor of the page
Kind: instance method of page
Returns: string
- ISO 8601 timestamp at which the page was last edited.
Define an object for use in a callback function.
callbackParameters
is for use by the caller only. The parameters
allow a caller to pass the proper context into its callback
function. Callers must ensure that any changes to the
callbackParameters object within a load()
callback still permit a
proper re-entry into the load()
callback if an edit conflict is
detected upon calling save()
.
Kind: instance method of page
Param | Type |
---|---|
callbackParameters | object |
Kind: instance method of page
Returns: object
- - The object previously set by setCallbackParameters()
.
Kind: instance method of page
Param | Type |
---|---|
statusElement | status |
page.getStatusElement() ⇒ status
Kind: instance method of page
Returns: status
- Status element created by the constructor.
Kind: instance method of page
Param | Type | Default | Description |
---|---|---|---|
level | string |
The right required for edits not to require review. Possible options: none, autoconfirmed, review (not on enWiki). |
|
[expiry] | string |
"infinity" |
Kind: instance method of page
Returns: boolean
- True if the page existed on the wiki when it was last loaded.
Kind: instance method of page
Returns: string
- Page ID of the page loaded. 0 if the page doesn't
exist.
Kind: instance method of page
Returns: string
- - Content model of the page. Possible values
include (but may not be limited to): wikitext
, javascript
,
css
, json
, Scribunto
, sanitized-css
, MassMessageListContent
.
Also gettable via mw.config.get('wgPageContentModel')
.
Kind: instance method of page
Returns: boolean
| string
- - Watched status of the page. Boolean
unless it's being watched temporarily, in which case returns the
expiry string.
Kind: instance method of page
Returns: string
- ISO 8601 timestamp at which the page was last loaded.
Kind: instance method of page
Returns: string
- The user who created the page following lookupCreation()
.
Kind: instance method of page
Returns: string
- The ISOString timestamp of page creation following lookupCreation()
.
Kind: instance method of page
Returns: boolean
- whether or not you can edit the page
Retrieves the username of the user who created the page as well as
the timestamp of creation. The username can be retrieved using the
getCreator()
function; the timestamp can be retrieved using the
getCreationTimestamp()
function.
Prior to June 2019 known as lookupCreator()
.
Kind: instance method of page
Param | Type | Description |
---|---|---|
onSuccess | function |
Callback function to be called when the username and timestamp are found within the callback. |
Reverts a page to revertOldID
set by setOldID
.
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function to run on success. |
[onFailure] | function |
Callback function to run on failure. |
Moves a page to another title.
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function to run on success. |
[onFailure] | function |
Callback function to run on failure. |
Marks the page as patrolled, using rcid
(if available) or revid
.
Patrolling as such doesn't need to rely on loading the page in question; simply passing a revid to the API is sufficient, so in those cases just using api is probably preferable.
No error handling since we don't actually care about the errors.
Kind: instance method of page
Marks the page as reviewed by the PageTriage extension.
Will, by it's nature, mark as patrolled as well. Falls back to patrolling if not in an appropriate namespace.
Doesn't inherently rely on loading the page in question; simply
passing a pageid
to the API is sufficient, so in those cases just
using api is probably preferable.
Will first check if the page is queued via fnProcessTriageList.
No error handling since we don't actually care about the errors.
Kind: instance method of page
See: https://www.mediawiki.org/wiki/Extension:PageTriage Referred to as "review" on-wiki.
Deletes a page (for admins only).
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function to run on success. |
[onFailure] | function |
Callback function to run on failure. |
Undeletes a page (for admins only).
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function to run on success. |
[onFailure] | function |
Callback function to run on failure. |
Protects a page (for admins only).
Kind: instance method of page
Param | Type | Description |
---|---|---|
[onSuccess] | function |
Callback function to run on success. |
[onFailure] | function |
Callback function to run on failure. |
Apply FlaggedRevs protection settings. Only works on wikis where
the extension is installed ($wgFlaggedRevsProtection = true
i.e. where FlaggedRevs settings appear on the "protect" tab).
Kind: instance method of page
See: https://www.mediawiki.org/wiki/Extension:FlaggedRevs
Referred to as "pending changes" on-wiki.
Param | Type |
---|---|
[onSuccess] | function |
[onFailure] | function |
Determines whether we can save an API call by using the csrf token sent with the page HTML, or whether we need to ask the server for more info (e.g. protection or watchlist expiry).
Currently used for append
, prepend
, newSection
, move
,
stabilize
, deletePage
, and undeletePage
. Not used for
protect
since it always needs to request protection status.
Kind: inner method of page
Param | Type | Default | Description |
---|---|---|---|
[action] | string |
"edit" |
The action being undertaken, e.g. "edit" or "delete". In practice, only "edit" or "notedit" matters. |
When functions can't use fnCanUseMwUserToken or require checking protection or watched status, maintain the query in one place. Used for delete, undelete, {@link* Morebits.wiki.page#protect|protect}, stabilize, and move (basically, just not load).
Kind: inner method of page
Returns: object
- Appropriate query.
Param | Type | Description |
---|---|---|
action | string |
The action being undertaken, e.g. "edit" or "delete". |
Common checks for action methods. Used for move, undelete, delete, protect, stabilize.
Kind: inner method of page
Param | Type | Description |
---|---|---|
action | string |
The action being checked. |
onFailure | string |
Failure callback. |
Common checks for fnProcess functions (fnProcessDelete
, fnProcessMove
, etc.
Used for move, undelete, delete, protect, stabilize.
Kind: inner method of page
Param | Type | Description |
---|---|---|
action | string |
The action being checked. |
onFailure | string |
Failure callback. |
response | string |
The response document from the API call. |
Kind: static class of wiki
Use the API to parse a fragment of wikitext and render it as HTML.
The suggested implementation pattern (in simpleWindow and
quickForm situations) is to construct a
Morebits.wiki.preview
object after rendering a Morebits.quickForm
, and
bind the object to an arbitrary property of the form (e.g. |previewer|).
For an example, see twinklewarn.js.
Param | Type | Description |
---|---|---|
previewbox | HTMLElement |
The element that will contain the rendered HTML, usually a element.
|
Displays the preview box, and begins an asynchronous attempt to render the specified wikitext.
Kind: instance method of preview
Param | Type | Description |
---|---|---|
wikitext | string |
Wikitext to render; most things should work, including |
[pageTitle] | string |
Optional parameter for the page this should be rendered as being on, if omitted it is taken as the current page. |
[sectionTitle] | string |
If provided, render the text as a new section using this as the title. |
Hides the preview box and clears it.
Kind: instance method of preview
Kind: static property of wiki
Kind: static property of wiki
Deprecated
Kind: static method of wiki
Display message and/or redirect to page upon completion of tasks.
Every call to Morebits.wiki.api.post() results in the dispatch of an asynchronous callback. Each callback can in turn make an additional call to Morebits.wiki.api.post() to continue a processing sequence. At the conclusion of the final callback of a processing sequence, it is not possible to simply return to the original caller because there is no call stack leading back to the original context. Instead, Morebits.wiki.actionCompleted.event() is called to display the result to the user and to perform an optional page redirect.
The determination of when to call Morebits.wiki.actionCompleted.event() is managed through the globals Morebits.wiki.numberOfActionsLeft and Morebits.wiki.nbrOfCheckpointsLeft. Morebits.wiki.numberOfActionsLeft is incremented at the start of every Morebits.wiki.api call and decremented after the completion of a callback function. If a callback function does not create a new Morebits.wiki.api object before exiting, it is the final step in the processing chain and Morebits.wiki.actionCompleted.event() will then be called.
Optionally, callers may use Morebits.wiki.addCheckpoint() to indicate that processing is not complete upon the conclusion of the final callback function. This is used for batch operations. The end of a batch is signaled by calling Morebits.wiki.removeCheckpoint().
Kind: static method of wiki
Kind: static property of actionCompleted
Kind: static property of actionCompleted
Kind: static property of actionCompleted
Kind: static method of actionCompleted
Kind: static method of wiki
Kind: static method of wiki
Wikitext manipulation.
Kind: static namespace of Morebits
-
.wikitext :
object
- .page
-
.parseTemplate(text, [start]) ⇒
object
Kind: static class of wikitext
Adjust and manipulate the wikitext of a page.
Param | Type | Description |
---|---|---|
text | string |
Wikitext to be manipulated. |
page.removeLink(link_target) ⇒ page
Removes links to link_target
from the page text.
Kind: instance method of page
Param | Type |
---|---|
link_target | string |
page.commentOutImage(image, [reason]) ⇒ page
Comments out images from page text; if used in a gallery, deletes the whole line.
If used as a template argument (not necessarily with File:
prefix), the template parameter is commented out.
Kind: instance method of page
Param | Type | Description |
---|---|---|
image | string |
Image name without |
[reason] | string |
Reason to be included in comment, alongside the commented-out image. |
page.addToImageComment(image, data) ⇒ page
Converts uses of [[File:image
]] to [[File:image
|data
]].
Kind: instance method of page
Param | Type | Description |
---|---|---|
image | string |
Image name without File: prefix. |
data | string |
The display options. |
page.removeTemplate(template) ⇒ page
Remove all transclusions of a template from page text.
Kind: instance method of page
Param | Type | Description |
---|---|---|
template | string |
Page name whose transclusions are to be removed, include namespace prefix only if not in template namespace. |
page.insertAfterTemplates(tag, regex, [flags], [preRegex]) ⇒ page
Smartly insert a tag atop page text but after specified templates, such as hatnotes, short description, or deletion and protection templates. Notably, does not insert a newline after the tag.
Kind: instance method of page
Param | Type | Default | Description |
---|---|---|---|
tag | string |
The tag to be inserted. |
|
regex |
string | Array.<string>
|
Templates after which to insert tag, given as either as a (regex-valid) string or an array to be joined by pipes. |
|
[flags] | string |
"i" |
Regex flags to apply. |
[preRegex] |
string | Array.<string>
|
Optional regex string or array to match
before any template matches (i.e. before |
Get the manipulated wikitext.
Kind: instance method of page
Get the value of every parameter found in the wikitext of a given template.
Kind: static method of wikitext
Returns: object
- {name: templateName, parameters: {key: value}}
.
Param | Type | Default | Description |
---|---|---|---|
text | string |
Wikitext containing a template. |
|
[start] | number |
0 |
Index noting where in the text the template begins. |
Function to handle finding parameter values.
Kind: inner method of parseTemplate
Param | Type | Default | Description |
---|---|---|---|
[final] | boolean |
false |
Whether this is the final
parameter and we need to remove the trailing |
Simple helper function to see what groups a user might belong.
Kind: static method of Morebits
Param | Type | Description |
---|---|---|
group | string |
e.g. |
Deprecated
Deprecated as of February 2021, use sanitizeIPv6.
Kind: static method of Morebits
Param | Type | Description |
---|---|---|
address | string |
The IPv6 address, with or without CIDR. |
Determines whether the current page is a redirect or soft redirect. Fails to detect soft redirects on edit, history, etc. pages. Will attempt to detect Module:Redirect for discussion, with the same failure points.
Kind: static method of Morebits
Create a string for use in regex matching a page name. Accounts for leading character's capitalization, underscores as spaces, and special characters being escaped. See also namespaceRegex.
Kind: static method of Morebits
Returns: string
- - For a page name Foo bar
, returns the string [Ff]oo[_ ]bar
.
Param | Type | Description |
---|---|---|
pageName | string |
Page name without namespace. |
Create a string for use in regex matching all namespace aliases, regardless
of the capitalization and underscores/spaces. Doesn't include the optional
leading :
, but if there's more than one item, wraps the list in a
non-capturing group. This means you can do Morebits.namespaceRegex([4]) + ':' + Morebits.pageNameRegex('Twinkle')
to match a full page. Uses
pageNameRegex.
Kind: static method of Morebits
Returns: string
- - Regex-suitable string of all namespace aliases.
Param | Type | Description |
---|---|---|
namespaces | Array.<number> |
Array of namespace numbers. Unused/invalid namespace numbers are silently discarded. |
Example
// returns '(?:[Ff][Ii][Ll][Ee]|[Ii][Mm][Aa][Gg][Ee])'
Morebits.namespaceRegex([6])
Simple helper function to create a simple node.
Kind: static method of Morebits
Param | Type | Description |
---|---|---|
type | string |
Type of HTML element. |
content | string |
Text content. |
[color] | string |
Font color. |
Add shift-click support for checkboxes. The wikibits version
(window.addCheckboxClickHandlers
) has some restrictions, and doesn't work
with checkboxes inside a sortable table, so let's build our own.
Kind: static method of Morebits
Param |
---|
jQuerySelector |
jQueryContext |
documentation generated on Sun Feb 14 2021