Expand all

mw.Map

Collection of values by string keys.

This is an internal class that backs the mw.config and mw.messages APIs.

It allows reading and writing to the collection via public methods, and allows batch iteraction for all its methods.

For mw.config, scripts sometimes choose to "import" a set of keys locally, like so:

var conf = mw.config.get( [ 'wgServerName', 'wgUserName', 'wgPageName' ] );
conf.wgServerName; // "example.org"

Check the existence ("AND" condition) of multiple keys:

if ( mw.config.exists( [ 'wgFoo', 'wgBar' ] ) );

For mw.messages, the mw.Map#set method allows mw.loader and mw.Api to essentially extend the object, and batch-apply all their loaded values in one go:

mw.messages.set( { "mon": "Monday", "tue": "Tuesday" } );

Methods

exists(selection) → {boolean} #

Check if a given key exists in the map.

Parameters:

Name Type Description
selection string

Key to check

Source:

Returns:

True if the key exists

Type
boolean
Check if a given key exists in the map.

get([selection], [fallback]) → {any|Object|null} #

Get the value of one or more keys.

If called with no arguments, all values are returned.

Parameters:

Name Type Attributes Default Description
selection string | Array optional

Key or array of keys to retrieve values for.

fallback any optional
null

Value for keys that don't exist.

Source:

Returns:

If selection was a string, returns the value, If selection was an array, returns an object of key/values. If no selection is passed, a new object with all key/values is returned.

Type
any | Object | null
Get the value of one or more keys.

set(selection, [value]) → {boolean} #

Set one or more key/value pairs.

Parameters:

Name Type Attributes Description
selection string | Object

Key to set value for, or object mapping keys to values

value any optional

Value to set (optional, only in use when key is a string)

Source:

Returns:

True on success, false on failure

Type
boolean
Set one or more key/value pairs.