MediaWiki master
MediaWiki\Message\Message Class Reference

The Message class deals with fetching and processing of interface message into a variety of formats. More...

Inherits Stringable, Wikimedia\Message\MessageSpecifier, and Serializable.

Inherited by MediaWiki\Api\ApiHelpParamValueMessage, MediaWiki\Api\ApiMessage, and MediaWiki\Language\RawMessage.

Collaboration diagram for MediaWiki\Message\Message:

Public Member Functions

 __construct ( $key, $params=[], ?Language $language=null)
 
 __serialize ()
 
 __toString ()
 Magic method implementation of the above, so we can do, eg: $foo = new Message( $key ); $string = "<abbr>$foo</abbr>";.
 
 __unserialize ( $data)
 
 bitrateParams (... $params)
 Add parameters that are bitrates and will be passed through Language::formatBitrate before substitution.
 
 dateParams (... $params)
 Add parameters that are dates and will be passed through Language::date before substitution.
 
 dateTimeParams (... $params)
 Add parameters that are date-times and will be passed through Language::timeanddate before substitution.
 
 durationParams (... $params)
 Add parameters that are durations of time and will be passed through Language::formatDuration before substitution.
 
 escaped ()
 Returns the message text.
 
 exists ()
 Check whether a message key has been defined currently.
 
 expiryParams (... $params)
 Add parameters that are expiration times and will be passed through Language::formatExpiry before substitution.
 
 getKey ()
 Returns the message key.
 
 getKeysToTry ()
 
 getLanguage ()
 Returns the Language of the Message.
 
 getParams ()
 Returns the message parameters.
 
 getTitle ()
 Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.
 
 inContentLanguage ()
 Request the message in the wiki's content language, unless it is disabled for this message.
 
 inLanguage ( $lang)
 Request the message in any language that is supported.
 
 inUserLanguage ()
 Request the message in the user's current language, overriding any explicit language that was previously set.
 
 isBlank ()
 Check whether a message does not exist, or is an empty string.
 
 isDisabled ()
 Check whether a message does not exist, is an empty string, or is "-".
 
 isMultiKey ()
 
 numParams (... $params)
 Add parameters that are numeric and will be passed through Language::formatNum before substitution.
 
 page (?PageReference $page)
 Set the page object to use as context when transforming the message.
 
 params (... $params)
 Adds parameters to the parameter list of this message.
 
 parse ()
 Fully parse the text from wikitext to HTML.
 
 parseAsBlock ()
 Returns the parsed message text which is always surrounded by a block element.
 
 plain ()
 Returns the message text as-is, only parameters are substituted.
 
 plaintextParams (... $params)
 Add parameters that are plaintext and will be passed through without the content being evaluated.
 
 rawParams (... $params)
 Add parameters that are substituted after parsing or escaping.
 
 serialize ()
 
 setContext (IContextSource $context)
 Set the language and the title from a context object.
 
 setInterfaceMessageFlag ( $interface)
 Allows manipulating the interface message flag directly.
 
 sizeParams (... $params)
 Add parameters that are file sizes and will be passed through Language::formatSize before substitution.
 
 text ()
 Returns the message text.
 
 timeParams (... $params)
 Add parameters that are times and will be passed through Language::time before substitution.
 
 timeperiodParams (... $params)
 Add parameters that are time periods and will be passed through Language::formatTimePeriod before substitution.
 
 title ( $title)
 Set the Title object to use as context when transforming the message.
 
 toString (string $format)
 Returns the message formatted a certain way.
 
 unserialize ( $serialized)
 
 useDatabase ( $useDatabase)
 
 userGroupParams (... $params)
 Add parameters that represent user groups.
 

Static Public Member Functions

static bitrateParam ( $bitrate)
 
static dateParam (string $date)
 
static dateTimeParam (string $dateTime)
 
static durationParam ( $duration)
 
static expiryParam ( $expiry)
 
static listParam (array $list, $type=ListType::AND)
 
static newFallbackSequence (... $keys)
 Factory function accepting multiple message keys and returning a message instance for the first message which is non-empty.
 
static newFromKey ( $key,... $params)
 Factory function that is just wrapper for the real constructor.
 
static newFromSpecifier ( $value)
 Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key string, or a key + params array) into a proper Message.
 
static numParam ( $num)
 
static plaintextParam ( $plaintext)
 
static rawParam ( $raw)
 
static sizeParam ( $size)
 
static timeParam (string $time)
 
static timeperiodParam ( $period)
 
static userGroupParam (string $userGroup)
 

Public Attributes

const FORMAT_BLOCK_PARSE = 'block-parse'
 Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag)
 
const FORMAT_ESCAPED = 'escaped'
 Transform {{..}} constructs, HTML-escape the result.
 
const FORMAT_PARSE = 'parse'
 Use normal wikitext -> HTML parsing but strip the block-level wrapper.
 
const FORMAT_PLAIN = 'plain'
 Use message text as-is.
 
const FORMAT_TEXT = 'text'
 Transform {{..}} constructs but don't transform to HTML.
 

Protected Member Functions

 extractParam ( $param, $format)
 Extracts the parameter type and preprocessed the value if needed.
 
 fetchMessage ()
 Wrapper for whatever method we use to get message contents.
 
 formatListParam (array $params, $listType, $format)
 Formats a list of parameters as a concatenated string.
 
 formatPlaintext ( $plaintext, $format)
 Formats a message parameter wrapped with 'plaintext'.
 
 parseText (string $string)
 Wrapper for what ever method we use to parse wikitext.
 
 replaceParameters ( $message, $type, $format)
 Substitutes any parameters into the message text.
 
 transformText ( $string)
 Wrapper for what ever method we use to {{-transform wikitext (substituting the template with its parsed result).
 

Protected Attributes

Content null $content = null
 Content object representing the message.
 
PageReference $contextPage = null
 page object to use as context.
 
bool $isInterface = true
 In which language to get this message.
 
string $key
 The message key.
 
string[] $keysToTry
 List of keys to try when fetching the message.
 
Language Language null $language = null
 In which language to get this message.
 
string null false $message
 
string $overriddenKey = null
 The message key that the message was fetched from, if different from all of the requested $keysToTry (the requested key may be overridden by hooks).
 
MessageParam Message string int float[] $parameters = []
 List of parameters which will be substituted into the message.
 
bool $useDatabase = true
 If messages in the local MediaWiki namespace should be loaded; false to use only the compiled LocalisationCache.
 
callable null $userLangCallback
 A callable which returns the current user language, or null to get it from global state.
 

Static Protected Attributes

static array $listTypeMap
 Mapping from Message::listParam() types to Language methods.
 

Detailed Description

The Message class deals with fetching and processing of interface message into a variety of formats.

First implemented with MediaWiki 1.17, the Message class is intended to replace the old wfMsg* functions that over time grew unusable.

See also
https://www.mediawiki.org/wiki/Manual:Messages_API for equivalences between old and new functions.

The preferred way to create Message objects is via the msg() method of of an available RequestContext and ResourceLoader Context object; this will ensure that the message uses the correct language. When that is not possible, the wfMessage() global function can be used, which will cause Message to get the language from the global RequestContext object. In rare circumstances when sessions are not available or not initialized, that can lead to errors.

The most basic usage cases would be:

// Initialize a Message object using the 'some_key' message key
$message = $context->msg( 'some_key' );
// Using two parameters those values are strings 'value1' and 'value2':
$message = $context->msg( 'some_key',
'value1', 'value2'
);

Global function wrapper:

Since msg() returns a Message instance, you can chain its call with a method. Some of them return a Message instance too so you can chain them. You will find below several examples of msg() usage.

Fetching a message text for interface message:

$button = Xml::button(
$context->msg( 'submit' )->text()
);

A Message instance can be passed parameters after it has been constructed, use the params() method to do so:

$context->msg( 'welcome-to' )
->params( $wgSitename )
->text();
$wgSitename
Config variable stub for the Sitename setting, for use by phpdoc and IDEs.

{{GRAMMAR}} and friends work correctly:

$context->msg( 'are-friends',
$user, $friend
);
$context->msg( 'bad-message' )
->rawParams( '<script>...</script>' )
->escaped();

Changing language:

Messages can be requested in a different language or in whatever current content language is being used. The methods are:

  • Message->inContentLanguage()
  • Message->inLanguage()

Sometimes the message text ends up in the database, so content language is needed:

wfMessage( 'file-log',
$user, $filename
)->inContentLanguage()->text();
wfMessage( $key,... $params)
This is the function for getting translated interface messages.

Checking whether a message exists:

$context->msg( 'mysterious-message' )->exists()
// returns a boolean whether the 'mysterious-message' key exist.

If you want to use a different language:

$userLanguage = $user->getOption( 'language' );
wfMessage( 'email-header' )
->inLanguage( $userLanguage )
->plain();
Note
You can parse the text only in the content or interface languages
See also
https://www.mediawiki.org/wiki/Manual:Messages_API
https://www.mediawiki.org/wiki/Localisation
Since
1.17
Stability: newable

Definition at line 155 of file Message.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Message\Message::__construct ( $key,
$params = [],
?Language $language = null )
Stability: stable
to call
Since
1.17
Parameters
string | MessageSpecifier | string[]$keyMessage key, MessageSpecifier object to copy, or array of fallback message keys where we use the first message that exists and is non-empty.
array$paramsMessage parameters
Language | null$language[optional] Language to use (defaults to current user language).

Definition at line 252 of file Message.php.

References MediaWiki\Message\Message\$key, MediaWiki\Message\Message\$language, $params, and MediaWiki\Message\Message\params().

Member Function Documentation

◆ __serialize()

MediaWiki\Message\Message::__serialize ( )
See also
Serializable::serialize()
Since
1.38
Returns
array

Definition at line 299 of file Message.php.

◆ __toString()

MediaWiki\Message\Message::__toString ( )

Magic method implementation of the above, so we can do, eg: $foo = new Message( $key ); $string = "<abbr>$foo</abbr>";.

Since
1.18
Returns
string

Definition at line 1079 of file Message.php.

◆ __unserialize()

MediaWiki\Message\Message::__unserialize ( $data)
See also
Serializable::unserialize()
Since
1.26
Parameters
array$data

Definition at line 331 of file Message.php.

◆ bitrateParam()

static MediaWiki\Message\Message::bitrateParam ( $bitrate)
static
Since
1.22
Parameters
int$bitrate
Returns
ScalarParam

Definition at line 1299 of file Message.php.

◆ bitrateParams()

MediaWiki\Message\Message::bitrateParams ( $params)

Add parameters that are bitrates and will be passed through Language::formatBitrate before substitution.

Since
1.22
Parameters
int|int[]...$params Bit rate parameters, or a single argument that is an array of bit rate parameters.
Returns
self $this

Definition at line 808 of file Message.php.

References $params.

◆ dateParam()

static MediaWiki\Message\Message::dateParam ( string $date)
static
Since
1.36
Parameters
string$date
Returns
ScalarParam

Definition at line 1244 of file Message.php.

◆ dateParams()

MediaWiki\Message\Message::dateParams ( $params)

Add parameters that are dates and will be passed through Language::date before substitution.

Since
1.36
Parameters
string|string[]...$params Date parameters, or a single argument that is an array of date parameters.
Returns
self $this

Definition at line 704 of file Message.php.

References $params.

◆ dateTimeParam()

static MediaWiki\Message\Message::dateTimeParam ( string $dateTime)
static
Since
1.36
Parameters
string$dateTime
Returns
ScalarParam

Definition at line 1233 of file Message.php.

◆ dateTimeParams()

MediaWiki\Message\Message::dateTimeParams ( $params)

Add parameters that are date-times and will be passed through Language::timeanddate before substitution.

Since
1.36
Parameters
string|string[]...$params Date-time parameters, or a single argument that is an array of date-time parameters.
Returns
self $this

Definition at line 683 of file Message.php.

References $params.

◆ durationParam()

static MediaWiki\Message\Message::durationParam ( $duration)
static
Since
1.22
Parameters
int$duration
Returns
ScalarParam

Definition at line 1211 of file Message.php.

Referenced by MediaWiki\Specials\SpecialBlock\getFormFields().

◆ durationParams()

MediaWiki\Message\Message::durationParams ( $params)

Add parameters that are durations of time and will be passed through Language::formatDuration before substitution.

Since
1.22
Parameters
int|int[]...$params Duration parameters, or a single argument that is an array of duration parameters.
Returns
self $this

Definition at line 641 of file Message.php.

References $params.

◆ escaped()

MediaWiki\Message\Message::escaped ( )

Returns the message text.

{{-transformation (substituting the template with its parsed result) is done and the result is HTML escaped excluding any raw parameters.

Since
1.17
Returns
string HTML escaped message text.

Definition at line 1141 of file Message.php.

Referenced by MediaWiki\Search\SearchWidgets\BasicSearchResultSetWidget\header().

◆ exists()

MediaWiki\Message\Message::exists ( )

Check whether a message key has been defined currently.

Since
1.17
Returns
bool

Definition at line 1152 of file Message.php.

◆ expiryParam()

static MediaWiki\Message\Message::expiryParam ( $expiry)
static
Since
1.22
Parameters
string$expiry
Returns
ScalarParam

Definition at line 1222 of file Message.php.

◆ expiryParams()

MediaWiki\Message\Message::expiryParams ( $params)

Add parameters that are expiration times and will be passed through Language::formatExpiry before substitution.

Since
1.22
Parameters
string|string[]...$params Expiry parameters, or a single argument that is an array of expiry parameters.
Returns
self $this

Definition at line 662 of file Message.php.

References $params.

◆ extractParam()

MediaWiki\Message\Message::extractParam ( $param,
$format )
protected

Extracts the parameter type and preprocessed the value if needed.

Since
1.18
Parameters
ScalarParam | ListParam | MessageSpecifier | string$paramParameter as defined in this class.
string$formatOne of the FORMAT_* constants.
Returns
array Array with the parameter type (either "before" or "after") and the value.

Definition at line 1373 of file Message.php.

◆ fetchMessage()

MediaWiki\Message\Message::fetchMessage ( )
protected

Wrapper for whatever method we use to get message contents.

Since
1.17
Returns
string|false

Reimplemented in MediaWiki\Api\ApiHelpParamValueMessage, and MediaWiki\Language\RawMessage.

Definition at line 1492 of file Message.php.

◆ formatListParam()

MediaWiki\Message\Message::formatListParam ( array $params,
$listType,
$format )
protected

Formats a list of parameters as a concatenated string.

Since
1.29
Parameters
array$params
string$listType
string$formatOne of the FORMAT_* constants.
Returns
array Array with the parameter type (either "before" or "after") and the value.

Definition at line 1552 of file Message.php.

References $params, Wikimedia\Message\MessageParam\getType(), and wfDebugLog().

◆ formatPlaintext()

MediaWiki\Message\Message::formatPlaintext ( $plaintext,
$format )
protected

Formats a message parameter wrapped with 'plaintext'.

Ensures that the entire string is displayed unchanged when displayed in the output format.

Since
1.25
Parameters
string$plaintextString to ensure plaintext output of
string$formatOne of the FORMAT_* constants.
Returns
string Input plaintext encoded for output to $format

Definition at line 1530 of file Message.php.

◆ getKey()

MediaWiki\Message\Message::getKey ( )

Returns the message key.

If a list of multiple possible keys was supplied to the constructor, this method may return any of these keys. After the message has been fetched, this method will return the key that was actually used to fetch the message.

Since
1.21
Returns
string

Implements Wikimedia\Message\MessageSpecifier.

Reimplemented in MediaWiki\Language\RawMessage.

Definition at line 402 of file Message.php.

Referenced by MediaWiki\EditPage\IntroMessageList\add().

◆ getKeysToTry()

MediaWiki\Message\Message::getKeysToTry ( )
Since
1.24
Returns
string[] The list of keys to try when fetching the message text, in order of preference.

Definition at line 387 of file Message.php.

◆ getLanguage()

MediaWiki\Message\Message::getLanguage ( )

Returns the Language of the Message.

Since
1.23
Returns
Language

Definition at line 424 of file Message.php.

Referenced by MediaWiki\Api\ApiHelpParamValueMessage\fetchMessage().

◆ getParams()

MediaWiki\Message\Message::getParams ( )

Returns the message parameters.

Since
1.21
Returns
(MessageParam|Message|string|int|float)[]

Implements Wikimedia\Message\MessageSpecifier.

Reimplemented in MediaWiki\Language\RawMessage.

Definition at line 413 of file Message.php.

◆ getTitle()

MediaWiki\Message\Message::getTitle ( )

Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.

The title will be for the current language, if the message key is in $wgForceUIMsgAsContentMsg it will be append with the language code (except content language), because Message::inContentLanguage will also return in user language.

See also
$wgForceUIMsgAsContentMsg
Returns
Title
Since
1.26

Definition at line 537 of file Message.php.

References NS_MEDIAWIKI.

◆ inContentLanguage()

MediaWiki\Message\Message::inContentLanguage ( )

Request the message in the wiki's content language, unless it is disabled for this message.

Since
1.17
See also
$wgForceUIMsgAsContentMsg
Returns
self $this

Definition at line 927 of file Message.php.

◆ inLanguage()

MediaWiki\Message\Message::inLanguage ( $lang)

Request the message in any language that is supported.

As a side effect interface message status is unconditionally turned off.

Since
1.17
Parameters
Bcp47Code | StubUserLang | string$langLanguage code or language object.
Returns
self $this

Definition at line 870 of file Message.php.

Referenced by MediaWiki\CommentStore\CommentStoreComment\newUnsavedComment().

◆ inUserLanguage()

MediaWiki\Message\Message::inUserLanguage ( )

Request the message in the user's current language, overriding any explicit language that was previously set.

Set the interface flag to true.

Since
1.42
Returns
$this

Definition at line 908 of file Message.php.

◆ isBlank()

MediaWiki\Message\Message::isBlank ( )

Check whether a message does not exist, or is an empty string.

Since
1.18
Todo
FIXME: Merge with isDisabled()?
Returns
bool

Definition at line 1164 of file Message.php.

◆ isDisabled()

MediaWiki\Message\Message::isDisabled ( )

Check whether a message does not exist, is an empty string, or is "-".

Since
1.18
Returns
bool

Definition at line 1176 of file Message.php.

◆ isMultiKey()

MediaWiki\Message\Message::isMultiKey ( )
Since
1.24
Returns
bool True if this is a multi-key message, that is, if the key provided to the constructor was a fallback list of keys to try.

Definition at line 377 of file Message.php.

◆ listParam()

◆ newFallbackSequence()

static MediaWiki\Message\Message::newFallbackSequence ( $keys)
static

Factory function accepting multiple message keys and returning a message instance for the first message which is non-empty.

If all messages are empty then an instance of the last message key is returned.

Since
1.18
Parameters
string|string[]...$keys Message keys, or first argument as an array of all the message keys.
Returns
self

Definition at line 514 of file Message.php.

◆ newFromKey()

static MediaWiki\Message\Message::newFromKey ( $key,
$params )
static

Factory function that is just wrapper for the real constructor.

It is intended to be used instead of the real constructor, because it allows chaining method calls, while new objects don't.

Since
1.17
Parameters
string | string[] | MessageSpecifier$key@phpcs:ignore Generic.Files.LineLength
MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float>...$params See Message::params()
Returns
self

Definition at line 449 of file Message.php.

References $params.

Referenced by MediaWiki\Auth\ButtonAuthenticationRequest\__set_state().

◆ newFromSpecifier()

static MediaWiki\Message\Message::newFromSpecifier ( $value)
static

Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key string, or a key + params array) into a proper Message.

Also accepts a MessageSpecifier inside an array: that's not considered a valid format but is an easy error to make due to how StatusValue stores messages internally. Providing further array elements in that case causes an exception to be thrown.

When the MessageSpecifier object is an instance of Message, a clone of the object is returned. This is unlike the new Message( … ) constructor, which returns a new object constructed from scratch with the same key. This difference is mostly relevant when the passed object is an instance of a subclass like RawMessage or ApiMessage.

Parameters
string | array | MessageSpecifier$value
Returns
self
Since
1.27

Definition at line 471 of file Message.php.

References $params.

Referenced by MediaWiki\Api\ApiBase\addBlockInfoToStatus(), MediaWiki\Message\TextFormatter\createMessage(), MediaWiki\Api\ApiMain\errorMessagesFromException(), MediaWiki\HTMLForm\HTMLForm\getMessage(), MediaWiki\HTMLForm\HTMLFormField\getMessage(), and MediaWiki\Specials\SpecialUpload\processVerificationError().

◆ numParam()

◆ numParams()

MediaWiki\Message\Message::numParams ( $params)

Add parameters that are numeric and will be passed through Language::formatNum before substitution.

Since
1.18
Parameters
string|int|float|list<string|int|float>...$params Numeric parameters, or a single argument that is an array of numeric parameters.
Returns
self $this

Definition at line 620 of file Message.php.

References $params.

◆ page()

MediaWiki\Message\Message::page ( ?PageReference $page)

Set the page object to use as context when transforming the message.

Since
1.37
Parameters
?PageReference$page
Returns
self $this

Definition at line 990 of file Message.php.

◆ params()

MediaWiki\Message\Message::params ( $params)

Adds parameters to the parameter list of this message.

Since
1.17

@phpcs:ignore Generic.Files.LineLength

Parameters
MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float>...$params Parameters as strings or MessageParam values (from Message::numParam() and the like), may also be passed as a single array instead of variadic parameters.
Returns
self $this

Definition at line 568 of file Message.php.

References $params, and Wikimedia\Message\MessageParam\getType().

Referenced by MediaWiki\Message\Message\__construct().

◆ parse()

MediaWiki\Message\Message::parse ( )

Fully parse the text from wikitext to HTML.

Since
1.17
Returns
string Parsed HTML.

Definition at line 1091 of file Message.php.

Referenced by MediaWiki\EditPage\IntroMessageList\add(), and MediaWiki\HTMLForm\HTMLFormField\formatErrors().

◆ parseAsBlock()

MediaWiki\Message\Message::parseAsBlock ( )

Returns the parsed message text which is always surrounded by a block element.

Since
1.17
Returns
string HTML

Definition at line 1128 of file Message.php.

◆ parseText()

MediaWiki\Message\Message::parseText ( string $string)
protected

Wrapper for what ever method we use to parse wikitext.

Since
1.17
Parameters
string$stringWikitext message contents.
Returns
ParserOutput Wikitext parsed into HTML.

Definition at line 1454 of file Message.php.

◆ plain()

MediaWiki\Message\Message::plain ( )

Returns the message text as-is, only parameters are substituted.

Since
1.17
Returns
string Unescaped untransformed message text.

Definition at line 1116 of file Message.php.

◆ plaintextParam()

static MediaWiki\Message\Message::plaintextParam ( $plaintext)
static

◆ plaintextParams()

MediaWiki\Message\Message::plaintextParams ( $params)

Add parameters that are plaintext and will be passed through without the content being evaluated.

Plaintext parameters are not valid as arguments to parser functions. This differs from self::rawParams in that the Message class handles escaping to match the output format.

Since
1.25
Parameters
string|string[]...$params plaintext parameters, or a single argument that is an array of plaintext parameters.
Returns
self $this

Definition at line 831 of file Message.php.

References $params.

◆ rawParam()

static MediaWiki\Message\Message::rawParam ( $raw)
static
Since
1.17
Parameters
string | int | float | MessageSpecifier$raw
Returns
ScalarParam

Definition at line 1189 of file Message.php.

Referenced by MediaWiki\Installer\WebInstallerComplete\execute().

◆ rawParams()

MediaWiki\Message\Message::rawParams ( $params)

Add parameters that are substituted after parsing or escaping.

In other words the parsing process cannot access the contents of this type of parameter, and you need to make sure it is sanitized beforehand. The parser will see "$n", instead.

Since
1.17
Parameters
string|int|float|MessageSpecifier|array<string|int|float|MessageSpecifier>...$params Raw parameters as strings, or a single argument that is an array of raw parameters.
Returns
self $this

Definition at line 599 of file Message.php.

References $params.

◆ replaceParameters()

MediaWiki\Message\Message::replaceParameters ( $message,
$type,
$format )
protected

Substitutes any parameters into the message text.

Since
1.17
Parameters
string$messageThe message text.
string$typeEither "before" or "after".
string$formatOne of the FORMAT_* constants.
Returns
string

Definition at line 1336 of file Message.php.

◆ serialize()

MediaWiki\Message\Message::serialize ( )
See also
Serializable::serialize()
Since
1.26
Returns
string

Definition at line 290 of file Message.php.

◆ setContext()

MediaWiki\Message\Message::setContext ( IContextSource $context)

Set the language and the title from a context object.

Since
1.19
Parameters
IContextSource$context
Returns
self $this

Definition at line 850 of file Message.php.

References MediaWiki\Context\IContextSource\getLanguage(), and MediaWiki\Context\IContextSource\getTitle().

◆ setInterfaceMessageFlag()

MediaWiki\Message\Message::setInterfaceMessageFlag ( $interface)

Allows manipulating the interface message flag directly.

Can be used to restore the flag after setting a language.

Since
1.20
Parameters
bool$interface
Returns
self $this

Definition at line 948 of file Message.php.

◆ sizeParam()

static MediaWiki\Message\Message::sizeParam ( $size)
static
Since
1.22
Parameters
int$size
Returns
ScalarParam

Definition at line 1288 of file Message.php.

Referenced by MediaWiki\Api\ApiMain\setupExternalResponse().

◆ sizeParams()

MediaWiki\Message\Message::sizeParams ( $params)

Add parameters that are file sizes and will be passed through Language::formatSize before substitution.

Since
1.22
Parameters
int|int[]...$params Size parameters, or a single argument that is an array of size parameters.
Returns
self $this

Definition at line 787 of file Message.php.

References $params.

◆ text()

MediaWiki\Message\Message::text ( )

Returns the message text.

{{-transformation occurs (substituting the template with its parsed result).

Since
1.17
Returns
string Unescaped message text.

Definition at line 1104 of file Message.php.

◆ timeParam()

static MediaWiki\Message\Message::timeParam ( string $time)
static
Since
1.36
Parameters
string$time
Returns
ScalarParam

Definition at line 1255 of file Message.php.

◆ timeParams()

MediaWiki\Message\Message::timeParams ( $params)

Add parameters that are times and will be passed through Language::time before substitution.

Since
1.36
Parameters
string|string[]...$params Time parameters, or a single argument that is an array of time parameters.
Returns
self $this

Definition at line 745 of file Message.php.

References $params.

◆ timeperiodParam()

static MediaWiki\Message\Message::timeperiodParam ( $period)
static
Since
1.22
Parameters
int | float$period
Returns
ScalarParam

Definition at line 1277 of file Message.php.

◆ timeperiodParams()

MediaWiki\Message\Message::timeperiodParams ( $params)

Add parameters that are time periods and will be passed through Language::formatTimePeriod before substitution.

Since
1.22
Parameters
int|float|(int|float)[]...$params Time period parameters, or a single argument that is an array of time period parameters.
Returns
self $this

Definition at line 766 of file Message.php.

References $params.

◆ title()

MediaWiki\Message\Message::title ( $title)

Set the Title object to use as context when transforming the message.

Since
1.18
Deprecated
since 1.37. Use ::page instead
Parameters
Title$title
Returns
self $this

Definition at line 977 of file Message.php.

◆ toString()

MediaWiki\Message\Message::toString ( string $format)

Returns the message formatted a certain way.

Since
1.17
Parameters
string$formatOne of the FORMAT_* constants.
Returns
string Text or HTML

Definition at line 1002 of file Message.php.

◆ transformText()

MediaWiki\Message\Message::transformText ( $string)
protected

Wrapper for what ever method we use to {{-transform wikitext (substituting the template with its parsed result).

Since
1.17
Parameters
string$stringWikitext message contents.
Returns
string Wikitext with {{-constructs substituted with its parsed result.

Definition at line 1476 of file Message.php.

◆ unserialize()

MediaWiki\Message\Message::unserialize ( $serialized)
See also
Serializable::unserialize()
Since
1.38
Parameters
string$serialized

Definition at line 322 of file Message.php.

◆ useDatabase()

MediaWiki\Message\Message::useDatabase ( $useDatabase)
Since
1.17
Parameters
bool$useDatabaseIf messages in the local MediaWiki namespace should be loaded; false to use only the compiled LocalisationCache
Returns
self $this

Definition at line 961 of file Message.php.

◆ userGroupParam()

static MediaWiki\Message\Message::userGroupParam ( string $userGroup)
static
Since
1.38
Parameters
string$userGroup
Returns
ScalarParam

Definition at line 1266 of file Message.php.

◆ userGroupParams()

MediaWiki\Message\Message::userGroupParams ( $params)

Add parameters that represent user groups.

Since
1.38
Parameters
string|string[]...$params User Group parameters, or a single argument that is an array of user group parameters.
Returns
self $this

Definition at line 724 of file Message.php.

References $params.

Member Data Documentation

◆ $content

Content null MediaWiki\Message\Message::$content = null
protected

Content object representing the message.

Definition at line 237 of file Message.php.

◆ $contextPage

PageReference MediaWiki\Message\Message::$contextPage = null
protected

page object to use as context.

Definition at line 232 of file Message.php.

◆ $isInterface

bool MediaWiki\Message\Message::$isInterface = true
protected

In which language to get this message.

True, which is the default, means the current user language, false content language.

Definition at line 184 of file Message.php.

◆ $key

string MediaWiki\Message\Message::$key
protected

The message key.

If $keysToTry has more than one element, this may change to one of the keys to try when fetching the message text.

Definition at line 203 of file Message.php.

Referenced by MediaWiki\Message\Message\__construct(), MediaWiki\Api\ApiMessage\__construct(), MediaWiki\Api\ApiRawMessage\__construct(), MediaWiki\Language\RawMessage\fetchMessage(), and MediaWiki\Language\RawMessage\getTextOfRawMessage().

◆ $keysToTry

string [] MediaWiki\Message\Message::$keysToTry
protected

List of keys to try when fetching the message.

Definition at line 209 of file Message.php.

◆ $language

Language Language null MediaWiki\Message\Message::$language = null
protected

In which language to get this message.

Overrides the $interface setting.

Explicit language object, or null for user language

Definition at line 191 of file Message.php.

Referenced by MediaWiki\Message\Message\__construct().

◆ $listTypeMap

array MediaWiki\Message\Message::$listTypeMap
staticprotected
Initial value:
= [
ListType::COMMA => 'commaList',
ListType::SEMICOLON => 'semicolonList',
ListType::PIPE => 'pipeList',
ListType::AND => 'listToText',
]
const COMMA
A comma-separated list.
Definition ListType.php:11
const PIPE
A pipe-separated list.
Definition ListType.php:17
const AND
A natural-language list separated by "and".
Definition ListType.php:20
const SEMICOLON
A semicolon-separated list.
Definition ListType.php:14

Mapping from Message::listParam() types to Language methods.

Definition at line 171 of file Message.php.

◆ $message

string null false MediaWiki\Message\Message::$message
protected

◆ $overriddenKey

string MediaWiki\Message\Message::$overriddenKey = null
protected

The message key that the message was fetched from, if different from all of the requested $keysToTry (the requested key may be overridden by hooks).

Definition at line 215 of file Message.php.

Referenced by MediaWiki\Api\ApiHelpParamValueMessage\fetchMessage().

◆ $parameters

MessageParam Message string int float [] MediaWiki\Message\Message::$parameters = []
protected

List of parameters which will be substituted into the message.

Definition at line 221 of file Message.php.

Referenced by MediaWiki\Language\RawMessage\getParamsOfRawMessage().

◆ $useDatabase

bool MediaWiki\Message\Message::$useDatabase = true
protected

If messages in the local MediaWiki namespace should be loaded; false to use only the compiled LocalisationCache.

Definition at line 227 of file Message.php.

◆ $userLangCallback

callable null MediaWiki\Message\Message::$userLangCallback
protected

A callable which returns the current user language, or null to get it from global state.

Definition at line 197 of file Message.php.

◆ FORMAT_BLOCK_PARSE

const MediaWiki\Message\Message::FORMAT_BLOCK_PARSE = 'block-parse'

Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag)

Definition at line 159 of file Message.php.

◆ FORMAT_ESCAPED

const MediaWiki\Message\Message::FORMAT_ESCAPED = 'escaped'

Transform {{..}} constructs, HTML-escape the result.

Definition at line 165 of file Message.php.

◆ FORMAT_PARSE

const MediaWiki\Message\Message::FORMAT_PARSE = 'parse'

Use normal wikitext -> HTML parsing but strip the block-level wrapper.

Definition at line 161 of file Message.php.

◆ FORMAT_PLAIN

const MediaWiki\Message\Message::FORMAT_PLAIN = 'plain'

Use message text as-is.

Definition at line 157 of file Message.php.

◆ FORMAT_TEXT

const MediaWiki\Message\Message::FORMAT_TEXT = 'text'

Transform {{..}} constructs but don't transform to HTML.

Definition at line 163 of file Message.php.


The documentation for this class was generated from the following file: