Message(map, key, parametersopt)

Message

Show:

Constructor

new Message(map, key, parametersopt)

...

Object constructor for messages.

Similar to the Message class in MediaWiki PHP.

Parameters:
Name Type Attributes Description
map MwMap

Message store

key string
parameters Array <optional>
Source:
Example
var obj, str;
    mw.messages.set( {
        'hello': 'Hello world',
        'hello-user': 'Hello, $1!',
        'welcome-user': 'Welcome back to $2, $1! Last visit by $1: $3',
        'so-unusual': 'You will find: $1'
    } );

    obj = mw.message( 'hello' );
    mw.log( obj.text() );
    // Hello world

    obj = mw.message( 'hello-user', 'John Doe' );
    mw.log( obj.text() );
    // Hello, John Doe!

    obj = mw.message( 'welcome-user', 'John Doe', 'Wikipedia', '2 hours ago' );
    mw.log( obj.text() );
    // Welcome back to Wikipedia, John Doe! Last visit by John Doe: 2 hours ago

    // Using mw.msg shortcut, always in "text' format.
    str = mw.msg( 'hello-user', 'John Doe' );
    mw.log( str );
    // Hello, John Doe!

    // Different formats
    obj = mw.message( 'so-unusual', 'Time "after" <time>' );

    mw.log( obj.text() );
    // You will find: Time "after" <time>

    mw.log( obj.escaped() );
    // You will find: Time &quot;after&quot; &lt;time&gt;

Methods

escaped() → {string}

...

Format message and return as escaped text in HTML.

This is equivalent to the #text format, which is then HTML-escaped.

Source:
Returns:

String form of html escaped message

Type
string

exists() → {boolean}

...

Check if a message exists. Equivalent to MwMap#exists.

Source:
Returns:
Type
boolean

params(parameters) → {Message}

...

Add (does not replace) parameters for $N placeholder values.

Parameters:
Name Type Description
parameters Array
Source:
Returns:
Type
Message

parse() → {string}

...

Parse message as wikitext and return HTML.

If jqueryMsg is loaded, this transforms text and parses a subset of supported wikitext into HTML. Without jqueryMsg, it is equivalent to #escaped.

Source:
Returns:

String form of parsed message

Type
string

plain() → {string}

...

Return message plainly.

This substitutes parameters, but otherwise does not transform the message content.

Source:
Returns:

String form of plain message

Type
string

text() → {string}

...

Format message with text transformations applied.

If jqueryMsg is loaded, {{-transformation is done for supported magic words such as {{plural:}}, {{gender:}}, and {{int:}}. Without jqueryMsg, it is equivalent to #plain.

Source:
Returns:

String form of text message

Type
string