mw

Base library for MediaWiki. Exposed globally as mw, with mediaWiki as alias.

Show:

Collection of methods to help log messages to the console.

Source:

Namespaces

errorLogger
hook
hook
html
loader
log
notification
util

Members

(static) config :MwMap

...

Map of configuration values.

Check out the complete list of configuration values on mediawiki.org.

Type:
Source:

(static) libs

...

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.

Properties:
Type Description
Object
Source:

(static) Map :MwMap

...

(static) Message :Message

...

(static) messages :MwMap

...

Store for messages.

Type:
Source:

(static) requestIdleCallback

...

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:

Source:

(static) templates :MwMap

...

Store for templates associated with a module.

Type:
Source:

Methods

(static) format(formatString, …parameters) → {string}

...

Format a string. Replace $1, $2 ... $N with positional arguments.

Used by Message#parser().

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

(static) inspect()

...

Generates a ResourceLoader report using the mediawiki.inspect module.

Source:

(static) log(…msg)

...

Write a verbose message to the browser's console in debug mode.

This method is mainly intended for verbose logging. It is a no-op in production mode. In ResourceLoader debug mode, it will use the browser's console.

Parameters:
Name Type Attributes Description
msg string <repeatable>

Messages to output to console.

Source:

(static) log.warn(…msg)

...

Write a message to the browser console's warning channel.

Parameters:
Name Type Attributes Description
msg string <repeatable>

Messages to output to console

Source:

(static) message(key, …parameters) → {Message}

...

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
Message

(static) msg(key, …parameters) → {string}

...

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

(static) notify(message, optionsopt) → {jQuery.Promise}

...

Convenience method for loading and accessing the mw.notification module.

Parameters:
Name Type Attributes Description
message HTMLElement | Array.<HTMLElement> | jQuery | Message | string
options Object <optional>

See mw.notification#defaults for the defaults.

Source:
Returns:
Type
jQuery.Promise

(static) now() → {number}

...

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

(static) track(topic, dataopt)

...

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:

(static) track(topic, data)

...
Parameters:
Name Type Description
topic any
data any
Source:

(static) trackSubscribe(topic, callback)

...

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.

Example to monitor all topics for debugging:

mw.trackSubscribe( '', console.log );

Example 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
Name Type Attributes Description
topic string
data Object <optional>
Source:

(static) trackUnsubscribe(callback)

...

Stop handling events for a particular handler

Parameters:
Name Type Description
callback function
Source: