Base library for MediaWiki. Exposed globally as mw
, with mediaWiki
as alias.
- Source:
Classes
- Api
- Client library for the action API.
- Debug
- Debug toolbar.
- Feedback
- This is a way of getting simple feedback from users.
- ForeignApi
Create an object like
mw.Api
, but automatically handling everything required to communicate with another MediaWiki wiki via cross-origin requests (CORS).- ForeignRest
Create an object like
mw.Rest
, but automatically handling everything required to communicate with another MediaWiki wiki via cross-origin requests (CORS).- ForeignStructuredUpload
- Used to represent an upload in progress on the frontend.
- ForeignUpload
- Used to represent an upload in progress on the frontend.
- GallerySlideshow
mw.GallerySlideshow encapsulates the user interface of the slideshow galleries.
- Map
- ES3 compatible class similar to ES6 Map.
- Message
- Object constructor for messages.
- Rest
- Constructor to create an object to interact with the REST API of a particular MediaWiki server.
- Title
- Parse titles into an object structure.
- Upload
- Used to represent an upload in progress on the frontend.
- Uri
- Create and manipulate MediaWiki URIs.
Namespaces
- cldr
- Namespace for CLDR-related utility methods.
- cookie
Manage cookies in a way that is syntactically and functionally similar to the
WebRequest#getCookie
andWebResponse#setcookie
methods in PHP.- errorLogger
- Allows the logging of client errors for later inspections.
- experiments
- Provides an API for bucketing users in experiments.
- html
- HTML construction helper functions.
- htmlform
- Provides access to HTMLForm OOUI classes.
- language
- Methods for transforming message syntax.
- loader
- Client for ResourceLoader server end point.
- log
- Library for logging developer warnings to the JavaScript console.
- messagePoster
- Library for posting messages to talk pages.
- notification
- Library for sending notifications to end users.
- searchSuggest
- Convenience library for making searches for titles that match a string.
- tempUserCreated
- Respond to the creation of a temporary user.
- template
- An extensible library for rendering templates in different template languages.
- user
- User library provided by 'mediawiki.user' ResourceLoader module.
- util
- Library providing useful common skin-agnostic utility functions.
- widgets
- OOUI widgets specific to MediaWiki.
Properties
config :mw.Mapstatic
#
Map of configuration values.
Check out the complete list of configuration values on mediawiki.org.
Type:
- Source:
libs :Objectstatic
#
Empty object for third-party libraries, for cases where you don't want to add a new global, or the global is bad and needs containment or wrapping.
Type:
- Object
- Source:
Empty object for third-party libraries, for cases where you don't want to add a new global, or the global is bad and needs containment or wrapping.
storage :SafeStoragestatic
#
Alias for module:mediawiki.storage.local
.
Type:
Properties:
Name | Type | Description |
---|---|---|
session |
SafeStorage | Alias for |
- Source:
module:mediawiki.storage.local
.
Methods
UriRelative(documentLocation) → {mw.Uri}static
#
A factory method to create an mw.Uri
class with a default location to resolve relative URLs
against (including protocol-relative URLs).
Parameters:
Name | Type | Description |
---|---|---|
documentLocation |
string | function | A full url, or function returning one. If passed a function, the return value may change over time and this will be honoured. (T74334) |
- Source:
Returns:
An mw.Uri class constructor
- Type
- mw.Uri
A factory method to create an mw.Uri
class with a default location to resolve relative URLs
against (including protocol-relative URLs).
confirmCloseWindow(optionsopt) → {Object}static
#
Prevent the closing of a window with a confirm message (the onbeforeunload event seems to work in most browsers).
Provided by the mediawiki.confirmCloseWindow module.
This supersedes any previous onbeforeunload handler. If there was a handler before, it is restored when you execute the returned release() function.
Example
mw.loader.using( 'mediawiki.confirmCloseWindow' ).then(() => {
var allowCloseWindow = mw.confirmCloseWindow();
// ... do stuff that can't be interrupted ...
allowCloseWindow.release();
// The second function returned is a trigger function to trigger the check and an alert
// window manually, e.g.:
var allowCloseWindow = mw.confirmCloseWindow();
// ... do stuff that can't be interrupted ...
if ( allowCloseWindow.trigger() ) {
// don't do anything (e.g. destroy the input field)
} else {
// do whatever you wanted to do
}
})
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Properties
|
- Source:
Returns:
An object of functions to work with this module
- Type
- Object
Prevent the closing of a window with a confirm message (the onbeforeunload event seems to work in most browsers).
deflate(data) → {string}static
#
Convert a byte stream to base64 text. Before using load the mediawiki.deflate ResourceLoader module.
Example
return mw.loader.using( 'mediawiki.deflate' ).then( function () {
return mw.deflate( html );
} );
Parameters:
Name | Type | Description |
---|---|---|
data |
string |
- Source:
Returns:
- Type
- string
format(formatString, …parameters) → {string}static
#
Format a string. Replace $1, $2 ... $N with positional arguments.
Used by mw.Message#parse
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
formatString |
string | Format string |
|
parameters |
Mixed |
<repeatable> |
Values for $N replacements |
- Since:
- 1.25
- Source:
Returns:
Formatted string
- Type
- string
hook(name) → {Hook}static
#
Hook
.
inspect(…reportsopt)static
#
Generate and print reports.
When invoked without arguments, prints all available reports.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
reports |
string |
<optional> <repeatable> |
One or more of "size", "css", "store", or "time". |
- Source:
message(key, …parameters) → {mw.Message}static
#
Get a message object.
Shortcut for new mw.Message( mw.messages, key, parameters )
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
string | Key of message to get |
|
parameters |
Mixed |
<repeatable> |
Values for $N replacements |
- Source:
- See:
Returns:
- Type
- mw.Message
msg(key, …parameters) → {string}static
#
Get a message string using the (default) 'text' format.
Shortcut for mw.message( key, parameters... ).text()
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
string | Key of message to get |
|
parameters |
any |
<repeatable> |
Values for $N replacements |
- Source:
- See:
Returns:
- Type
- string
notify(message, optionsopt) → {jQuery.Promise}static
#
Convenience method for loading and accessing the
mw.notification module
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
HTMLElement | Array.<HTMLElement> | jQuery | mw.Message | string | ||
options |
Object |
<optional> |
See mw.notification#defaults for the defaults. |
- Source:
Returns:
- Type
- jQuery.Promise
Convenience method for loading and accessing the
mw.notification module
.
now() → {number}static
#
Get the current time, measured in milliseconds since January 1, 1970 (UTC).
On browsers that implement the Navigation Timing API, this function will produce
floating-point values with microsecond precision that are guaranteed to be monotonic.
On all other browsers, it will fall back to using Date
.
- Source:
Returns:
Current time
- Type
- number
requestIdleCallback(callback, optionsopt)static
#
Schedule a deferred task to run in the background.
This allows code to perform tasks in the main thread without impacting time-critical operations such as animations and response to input events.
Basic logic is as follows:
- User input event should be acknowledged within 100ms per RAIL.
- Idle work should be grouped in blocks of upto 50ms so that enough time remains for the event handler to execute and any rendering to take place.
- Whenever a native event happens (e.g. user input), the deadline for any running idle callback drops to 0.
- As long as the deadline is non-zero, other callbacks pending may be executed in the same idle period.
See also:
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function | ||||||||||
options |
Object |
<optional> |
Properties
|
track(topic, dataopt)static
#
Track an analytic event.
This method provides a generic means for MediaWiki JavaScript code to capture state information for analysis. Each logged event specifies a string topic name that describes the kind of event that it is. Topic names consist of dot-separated path components, arranged from most general to most specific. Each path component should have a clear and well-defined purpose.
Data handlers are registered via mw.trackSubscribe
, and receive the full set of
events that match their subscription, including buffered events that fired before the handler
was subscribed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
topic |
string | Topic name |
|
data |
Object | number | string |
<optional> |
Data describing the event. |
- Source:
trackSubscribe(topic, callback)static
#
Register a handler for subset of analytic events, specified by topic.
Handlers will be called once for each tracked event, including for any buffered events that
fired before the handler was subscribed. The callback is passed a topic
string, and optional
data
event object. The this
value for the callback is a plain object with topic
and
data
properties set to those same values.
Examples
// To monitor all topics for debugging
mw.trackSubscribe( '', console.log );
// To subscribe to any of `foo.*`, e.g. both `foo.bar` and `foo.quux`
mw.trackSubscribe( 'foo.', console.log );
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
topic |
string | Handle events whose name starts with this string prefix |
||||||||||||
callback |
function | Handler to call for each matching tracked event Properties
|
- Source:
trackUnsubscribe(callback)static
#
Stop handling events for a particular handler.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
- Source: