Readonly
DeputyReadonly
DeputyReadonly
DeputyReadonly
DeputyReadonly
DeputyReadonly
DeputyAn OOUI WindowManager. Automatically instantiated when needed. See the
windowManager
getter for instantiation.
CopiedTemplateEditor instance.
The current page as an mw.Title.
The current page ID.
Readonly
modelsReadonly
modulesReadonly
utilApplies configuration overrides. This takes two objects, A and B. A's keys will be respected and will remain unchanged. Object values of A that also exist in B will be overwritten with its values in B.
Mixes values together into a string for the class
attribute.
Rest
...classes: ArrayOrNot<string | false>[]string
Cleans a parameter list. By default, this performs the following:
This mutates the original object and also returns it for chaining.
The cleaned parameter list.
Copies text to the clipboard. Relies on the old style of clipboard copying
(using document.execCommand
due to a lack of support for navigator
-based
clipboard handling).
The text to copy to the clipboard.
Shows a confirmation dialog, if the user does not have danger mode enabled. If the user has danger mode enabled, this immediately resolves to true, letting the action run immediately.
Do not use this with any action that can potentially break templates, user data, or cause irreversible data loss.
The user's configuration
See OO.ui.MessageDialog's parameters.
Optional
options: SetupDataMapSee OO.ui.MessageDialog's parameters.
Promise resolving to a true/false boolean.
Checks if two MediaWiki page titles are equal.
true
if title1
and title2
refer to the same page
Log errors to the console.
Rest
...data: any[]Generates an ID using the current time and a random number. Quick and dirty way to generate random IDs.
A string in the format TIMESTAMP++RANDOM_NUMBER
Works like Object.values
.
The object to get the values of.
The values of the given object as an array
Returns the last item of a NodeList array.
The array to get the last element from
The last element of the array
Returns the last item of an array.
The array to get the last element from
The last element of the array
Returns the last character of a string.
The string to get the last character from
The last character of the string
Log to the console.
Rest
...data: any[]Replacement for String.prototype.matchALl (ES2020 only)
The regular expression to exec with
The string to exec against
The matches found
Iterates over an array and returns an Iterator which checks each element
of the array sequentially for a given condition (predicated by condition
)
and returns another array, containing an element where true
was returned,
and every subsequent element where the check returns false
.
Unwraps an element into its child elements. This entirely discards the parent element.
The element to unwrap.
The unwrapped element.
Get the nodes from a JQuery object and wraps it in an element.
The element to add the children into
The JQuery object
The original element, now with children
Unwraps an OOUI widget from its JQuery $element
variable and returns it as an
HTML element.
The widget to unwrap.
The unwrapped widget.
Log warnings to the console.
Rest
...data: any[]Performs {{yesno}}-based string interpretation.
The value to check
Depends which direction to pull unspecified values.
If pull
is true,
any value that isn't explicitly a negative value will return true
. Otherwise,
any value that isn't explicitly a positive value will return false
.
Readonly
versionThis version of Deputy.
Readonly
wikiAppends extra information to an edit summary (also known as the "advert").
The edit summary
Optional
config: UserConfigurationThe user's configuration. Used to get the "danger mode" setting.
The decorated edit summary (in wikitext)
Delinks wikitext. Does not handle templates. Only does dumb delinking (RegExp replacement; does not parse and handle link nesting, etc.).
delinked wikitext
Converts a normal error into an OO.ui.Error for ProcessDialogs.
A plain error object.
Error configuration.
Whether or not the error is recoverable.
Whether or not the error is a warning.
An OOUI Error.
Finds a MediaWiki section heading from the current DOM using its title.
The name of the section to find.
The n
of the section. Starts at 1.
The found section heading. null
if not found.
Get the API error text from an API response.
Get the n
th error. Defaults to 0 (first error).
Get the content of a page on-wiki.
The page to get
Extra options to pass to the request
The API object to use
A promise resolving to the page content. Resolves to null
if missing page.
From a list of page titles, get which pages exist.
The pages to search for
An array of pages which exist, ordered by input order.
Get the content of a revision on-wiki.
The revision ID of the revision to get the content of
Extra options to pass to the request
The API object to use
A promise resolving to the page content
Gets the URL of a diff page.
The revision to compare with
Optional
to: The revision to compare from
true
if the current query parameters should be included
The URL of the diff page
Gets the URL of a permanent link page.
The revision ID to link to
The title of the page to compare to
true
if the current query parameters should be included
The URL of the diff page
Finds section elements from a given section heading (and optionally a predicate)
A function which returns true
if the section should stop here
Section headings.
Get the parser output HTML of a specific page section.
A promise resolving to the <div class="mw-parser-output">
element.
Attempt to guess the author of a comment from the comment signature.
The comment to read.
The author of the comment
Check if a given parameter is a wikitext heading parsed into HTML.
Alias for normalizeWikiHeading( el ) != null
.
The element to check
true
if the element is a heading, false
otherwise
Evaluates any string using mw.msg
. This handles internationalization of strings
that are loaded outside the script or asynchronously.
The string to evaluate
Named parameters to evaluate. Uses $
notation.
Rest
...parameters: string[]Parameters to pass, if any
A mw.Message
Evaluates any string using mw.msg
. This handles internationalization of strings
that are loaded outside the script or asynchronously.
The string to evaluate
Rest
...parameters: string[]Parameters to pass, if any
A mw.Message
Annoyingly, there are many different ways that a heading can be parsed into depending on the version and the parser used for given wikitext.
In order to properly perform such wiki heading checks, we need to identify if a given element is part of a wiki heading, and perform a normalization if so.
Since this function needs to check many things before deciding if a given
HTML element is part of a section heading or not, this also acts as an
isWikiHeading
check.
The layout for a heading differs depending on the MediaWiki version:
On 1.43+ (Parser)
<div class="mw-heading mw-heading2">
<h2 id="Parsed_wikitext...">Parsed <i>wikitext</i>...</h2>
<span class="mw-editsection>...</span>
</div>
On Parsoid
<h2 id="Parsed_wikitext...">Parsed <i>wikitext</i>...</h2>
On pre-1.43
<h2>
<span class="mw-headline" id="Parsed_wikitext...">Parsed <i>wikitext</i>...</span>
<span class="mw-editsection">...</span>
</h2>
Worst case execution time would be if this was run with an element which was outside a heading and deeply nested within the page.
Backwards-compatibility support may be removed in the future. This function does not support Parsoid specification versions lower than 2.0.
The root heading element (can be an <h2> or <div>),
or null
if it is not a valid heading.
Gets the namespace ID from a canonical (not localized) namespace name.
The namespace to get
The namespace ID
Extracts a page title from a MediaWiki <a>
. If the link does not validly point
to a MediaWiki page, false
is returned.
The part of the link used to determine the page title depends on how trustworthy
the data is in telling the correct title. If the link does not have an href
, only
two routes are available: the selflink check and the title
attribute check.
The following methods are used, in order.
title
parameter from anchor href/wiki/$1
path from anchor href./$1
path from Parsoid document anchor hreftitle
attribute from anchorthe page linked to
What it says on the tin. Attempt to parse out a title
, diff
,
or oldid
from a URL. This is useful for converting diff URLs into actual
diff information, and especially useful for {{copied}} templates.
If diff parameters were not found (no diff
or oldid
), they will be null
.
The URL to parse
Parsed info: diff
or oldid
revision IDs, and/or the page title.
MediaWiki core contains a lot of quirks in the code. Other extensions also have their own quirks. To prevent these quirks from affecting Deputy's functionality, we need to perform a few hacks.
Checks the n of a given element, that is to say the n
th occurrence of a section
with this exact heading name in the entire page.
This is purely string- and element-based, with no additional metadata or parsing information required.
This function detects the n
using the following conditions:
The heading to check
The n, a number
Transforms the redirects
object returned by MediaWiki's query
action into an
object instead of an array.
Optional
normalized: { Redirects as an object
Gets the wiki-specific configuration for Deputy.
A promise resolving to the loaded configuration
Static
init
The main class for Deputy. Entry point for execution.
This class is not exported to avoid circular references and extraneous export code in the Rollup bundle (unnecessary for a userscript).