MediaWiki  master
Message Class Reference

The Message class provides methods which fulfil two basic services: More...

Inheritance diagram for Message:
Collaboration diagram for Message:

Public Member Functions

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

Static Public Member Functions

static bitrateParam ( $bitrate)
 
static durationParam ( $duration)
 
static expiryParam ( $expiry)
 
static listParam (array $list, $type='text')
 
static newFallbackSequence ()
 Factory function accepting multiple message keys and returning a message instance for the first message which is non-empty. More...
 
static newFromKey ( $key)
 Factory function that is just wrapper for the real constructor. More...
 
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. More...
 
static numParam ( $num)
 
static plaintextParam ( $plaintext)
 
static rawParam ( $raw)
 
static sizeParam ( $size)
 
static timeperiodParam ( $period)
 

Public Attributes

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

Protected Member Functions

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

Protected Attributes

Content $content = null
 Content object representing the message. More...
 
string $format = 'parse'
 
static array bool $interface = true
 In which language to get this message. More...
 
string $key
 The message key. More...
 
string [] $keysToTry
 List of keys to try when fetching the message. More...
 
Language bool $language = false
 In which language to get this message. More...
 
string $message
 
array $parameters = []
 List of parameters which will be substituted into the message. More...
 
Title $title = null
 Title object to use as context. More...
 
bool $useDatabase = true
 Whether database can be used. More...
 

Static Protected Attributes

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

Detailed Description

The Message class provides methods which fulfil two basic services:

  • fetching interface messages
  • processing messages 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.

You should use the wfMessage() global function which acts as a wrapper for the Message class. The wrapper let you pass parameters as arguments.

The most basic usage cases would be:

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

Global function wrapper:

Since wfMessage() 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 wfMessage() usage.

Fetching a message text for interface message:

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

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

wfMessage( 'welcome-to' )
->params( $wgSitename )
->text();

{{GRAMMAR}} and friends work correctly:

wfMessage( 'are-friends',
$user, $friend
);
wfMessage( '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:

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

wfMessage( 'file-log',
$user, $filename
)->inContentLanguage()->text();

Checking whether a message exists:

wfMessage( '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

Comparison with old wfMsg* functions:

Use full parsing:

// old style:
wfMsgExt( 'key', [ 'parseinline' ], 'apple' );
// new style:
wfMessage( 'key', 'apple' )->parse();

Parseinline is used because it is more useful when pre-building HTML. In normal use it is better to use OutputPage::(add|wrap)WikiMsg.

Places where HTML cannot be used. {{-transformation is done.

// old style:
wfMsgExt( 'key', [ 'parsemag' ], 'apple', 'pear' );
// new style:
wfMessage( 'key', 'apple', 'pear' )->text();

Shortcut for escaping the message too, similar to wfMsgHTML(), but parameters are not replaced after escaping by default.

$escaped = wfMessage( 'key' )
->rawParams( 'apple' )
->escaped();

Appendix:

Todo:
  • test, can we have tests?
  • this documentation needs to be extended
See also
https://www.mediawiki.org/wiki/WfMessage()
https://www.mediawiki.org/wiki/New_messages_API
https://www.mediawiki.org/wiki/Localisation
Since
1.17

Definition at line 160 of file Message.php.

Constructor & Destructor Documentation

◆ __construct()

Message::__construct (   $key,
  $params = [],
Language  $language = null 
)
Since
1.17
Parameters
string|string[]|MessageSpecifier$key Message key, or array of message keys to try and use the first non-empty message for, or a MessageSpecifier to copy from.
array$paramsMessage parameters.
Language | null$language[optional] Language to use (defaults to current user language).
Exceptions
InvalidArgumentException

Definition at line 249 of file Message.php.

References $params, array(), and key.

Member Function Documentation

◆ __toString()

Message::__toString ( )

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

Since
1.18
Returns
string

Definition at line 917 of file Message.php.

References key, and toString().

◆ bitrateParam()

static Message::bitrateParam (   $bitrate)
static
Since
1.22
Parameters
int$bitrate
Returns
int[] Array with a single "bitrate" key.

Definition at line 1105 of file Message.php.

◆ bitrateParams()

Message::bitrateParams ( )

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

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

Definition at line 681 of file Message.php.

References $params, and as.

◆ content()

Message::content ( )

Returns the message as a Content object.

Returns
Content

Definition at line 838 of file Message.php.

References $content.

◆ durationParam()

static Message::durationParam (   $duration)
static
Since
1.22
Parameters
int$duration
Returns
int[] Array with a single "duration" key.

Definition at line 1061 of file Message.php.

◆ durationParams()

Message::durationParams ( )

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

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

Definition at line 593 of file Message.php.

References $params, and as.

◆ escaped()

Message::escaped ( )

Returns the message text.

{{-transformation is done and the result is escaped excluding any raw parameters.

Since
1.17
Returns
string Escaped message text.

Definition at line 991 of file Message.php.

References format, and toString().

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

◆ exists()

Message::exists ( )

Check whether a message key has been defined currently.

Since
1.17
Returns
bool

Definition at line 1003 of file Message.php.

References fetchMessage().

◆ expiryParam()

static Message::expiryParam (   $expiry)
static
Since
1.22
Parameters
string$expiry
Returns
string[] Array with a single "expiry" key.

Definition at line 1072 of file Message.php.

◆ expiryParams()

Message::expiryParams ( )

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

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

Definition at line 615 of file Message.php.

References $params, and as.

◆ extractParam()

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

Extracts the parameter type and preprocessed the value if needed.

Since
1.18
Parameters
mixed$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 1187 of file Message.php.

References $format, $interface, $language, $title, $useDatabase, formatListParam(), formatPlaintext(), MediaWiki\Logger\LoggerFactory\getInstance(), getKey(), getLanguage(), and serialize().

Referenced by formatListParam(), and replaceParameters().

◆ fetchMessage()

Message::fetchMessage ( )
protected

Wrapper for what ever method we use to get message contents.

Since
1.17
Returns
string
Exceptions
MWExceptionIf message key array is empty.

Definition at line 1307 of file Message.php.

References $cache, $key, $message, as, getLanguage(), key, message, MessageCache\singleton(), and useDatabase().

Referenced by exists(), isBlank(), isDisabled(), and toString().

◆ formatListParam()

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 1360 of file Message.php.

References $e, $type, $value, $vars, as, extractParam(), getKey(), getLanguage(), key, list, serialize(), and wfDebugLog().

Referenced by extractParam().

◆ formatPlaintext()

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 1338 of file Message.php.

Referenced by extractParam().

◆ getFormat()

Message::getFormat ( )

Returns the message format.

Since
1.21
Returns
string
Deprecated:
since 1.29 formatting is not stateful

Definition at line 380 of file Message.php.

References $format, and wfDeprecated().

◆ getKey()

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 MessageSpecifier.

Definition at line 357 of file Message.php.

References $key.

Referenced by ApiMessageTest\compareMessages(), CommentStore\encodeMessage(), extractParam(), formatListParam(), and ApiAuthManagerHelper\formatMessage().

◆ getKeysToTry()

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 342 of file Message.php.

References $keysToTry.

Referenced by ApiMessageTest\compareMessages(), and CommentStore\encodeMessage().

◆ getLanguage()

Message::getLanguage ( )

Returns the Language of the Message.

Since
1.23
Returns
Language

Definition at line 392 of file Message.php.

References RequestContext\getMain().

Referenced by ApiMessageTest\compareMessages(), extractParam(), fetchMessage(), formatListParam(), getTitle(), parseText(), and transformText().

◆ getParams()

Message::getParams ( )

Returns the message parameters.

Since
1.21
Returns
array

Implements MessageSpecifier.

Definition at line 368 of file Message.php.

References $parameters.

Referenced by ApiMessageTest\compareMessages(), CommentStore\encodeMessage(), ApiAuthManagerHelper\formatMessage(), and StatusTest\sanitizedMessageParams().

◆ getTitle()

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 485 of file Message.php.

References $key, $lang, $wgForceUIMsgAsContentMsg, array(), getLanguage(), key, Title\makeTitle(), and NS_MEDIAWIKI.

◆ inContentLanguage()

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
Message $this

Definition at line 779 of file Message.php.

References $wgForceUIMsgAsContentMsg, array(), inLanguage(), and key.

◆ inLanguage()

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
Language | string$langLanguage code or Language object.
Returns
Message $this
Exceptions
MWException

Definition at line 744 of file Message.php.

References $lang, $language, $type, Language\factory(), false, and message.

Referenced by inContentLanguage(), CommentStoreComment\newUnsavedComment(), and setContext().

◆ isBlank()

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 1015 of file Message.php.

References fetchMessage().

◆ isDisabled()

Message::isDisabled ( )

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

Since
1.18
Returns
bool

Definition at line 1027 of file Message.php.

References fetchMessage().

◆ isMultiKey()

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 332 of file Message.php.

◆ listParam()

static Message::listParam ( array  $list,
  $type = 'text' 
)
static

◆ newFallbackSequence()

static Message::newFallbackSequence ( )
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 first 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
Message

Definition at line 461 of file Message.php.

References $keys.

Referenced by wfMessageFallback().

◆ newFromKey()

static Message::newFromKey (   $key)
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
mixed$param,...Parameters as strings.
Returns
Message

Definition at line 409 of file Message.php.

References $key, and $params.

Referenced by MediaWiki\Auth\ButtonAuthenticationRequest\__set_state(), MessageTest\testNewFromKey(), and MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\testUserForCreation().

◆ newFromSpecifier()

static 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. Further array elements are ignored in that case.

Parameters
string | array | MessageSpecifier$value
Returns
Message
Exceptions
InvalidArgumentException
Since
1.27

Definition at line 428 of file Message.php.

References $message, $params, and $value.

Referenced by PermissionsError\__construct(), ApiMain\errorMessagesFromException(), PasswordReset\execute(), ApiLogin\formatMessage(), HTMLFormField\getMessage(), HTMLForm\getMessage(), ApiErrorFormatter\getMessageFromException(), LocalizedException\getMessageObject(), UploadStashException\getMessageObject(), MWExceptionRenderer\reportHTML(), and MessageTest\testNewFromSpecifier().

◆ numParam()

◆ numParams()

Message::numParams ( )

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

Since
1.18
Parameters
mixed$param,...Numeric parameters, or a single argument that is an array of numeric parameters.
Returns
Message $this

Definition at line 571 of file Message.php.

References $params, and as.

◆ params()

Message::params ( )

Adds parameters to the parameter list of this message.

Since
1.17
Parameters
mixed$args,...Parameters as strings or arrays from Message::numParam() and the like, or a single array of parameters.
Returns
Message $this

Definition at line 512 of file Message.php.

References $args, $value, and as.

◆ parse()

Message::parse ( )

Fully parse the text from wikitext to HTML.

Since
1.17
Returns
string Parsed HTML.

Definition at line 942 of file Message.php.

References format, and toString().

Referenced by ApiHelp\wrap().

◆ parseAsBlock()

Message::parseAsBlock ( )

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

Since
1.17
Returns
string HTML

Definition at line 978 of file Message.php.

References format, and toString().

◆ parseText()

Message::parseText (   $string)
protected

Wrapper for what ever method we use to parse wikitext.

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

Definition at line 1260 of file Message.php.

References $out, getLanguage(), MessageCache\singleton(), and title().

Referenced by toString().

◆ plain()

Message::plain ( )

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

Since
1.17
Returns
string Unescaped untransformed message text.

Definition at line 966 of file Message.php.

References format, and toString().

◆ plaintextParam()

static Message::plaintextParam (   $plaintext)
static
Since
1.25
Parameters
string$plaintext
Returns
string[] Array with a single "plaintext" key.

Definition at line 1116 of file Message.php.

◆ plaintextParams()

Message::plaintextParams ( )

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[]$param,... plaintext parameters, or a single argument that is an array of plaintext parameters.
Returns
Message $this

Definition at line 705 of file Message.php.

References $params, and as.

◆ rawParam()

◆ rawParams()

Message::rawParams ( )

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
mixed$params,...Raw parameters as strings, or a single argument that is an array of raw parameters.
Returns
Message $this

Definition at line 549 of file Message.php.

References $params, and as.

◆ replaceParameters()

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 1147 of file Message.php.

References $message, $type, $value, as, extractParam(), and list.

Referenced by toString().

◆ serialize()

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

Definition at line 283 of file Message.php.

References $format, $key, $keysToTry, $parameters, $title, $useDatabase, and title().

Referenced by extractParam(), and formatListParam().

◆ setContext()

Message::setContext ( IContextSource  $context)

Set the language and the title from a context object.

Since
1.19
Parameters
IContextSource$context
Returns
Message $this

Definition at line 725 of file Message.php.

References IContextSource\getLanguage(), IContextSource\getTitle(), inLanguage(), title(), and true.

Referenced by ApiAuthManagerHelper\formatMessage(), and ApiBase\getFinalParamDescription().

◆ setInterfaceMessageFlag()

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
Message $this

Definition at line 799 of file Message.php.

◆ sizeParam()

static Message::sizeParam (   $size)
static
Since
1.22
Parameters
int$size
Returns
int[] Array with a single "size" key.

Definition at line 1094 of file Message.php.

◆ sizeParams()

Message::sizeParams ( )

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

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

Definition at line 659 of file Message.php.

References $params, and as.

◆ text()

Message::text ( )

Returns the message text.

{{-transformation is done.

Since
1.17
Returns
string Unescaped message text.

Definition at line 954 of file Message.php.

References format, and toString().

◆ timeperiodParam()

static Message::timeperiodParam (   $period)
static
Since
1.22
Parameters
int$period
Returns
int[] Array with a single "period" key.

Definition at line 1083 of file Message.php.

◆ timeperiodParams()

Message::timeperiodParams ( )

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

Since
1.22
Parameters
int|int[]$param,... Time period parameters, or a single argument that is an array of time period parameters.
Returns
Message $this

Definition at line 637 of file Message.php.

References $params, and as.

◆ title()

Message::title (   $title)

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

Since
1.18
Parameters
Title$title
Returns
Message $this

Definition at line 828 of file Message.php.

References $title.

Referenced by ApiMessageTest\compareMessages(), parseText(), serialize(), setContext(), transformText(), and unserialize().

◆ toString()

Message::toString (   $format = null)

Returns the message parsed from wikitext to HTML.

Since
1.17
Parameters
string | null$formatOne of the FORMAT_* constants. Null means use whatever was used the last time (this is for B/C and should be avoided).
Returns
string HTML SecurityCheck-DoubleEscaped phan false positive

Definition at line 857 of file Message.php.

References $format, $key, fetchMessage(), format, MediaWiki\Logger\LoggerFactory\getInstance(), key, parseText(), replaceParameters(), Parser\stripOuterParagraph(), and transformText().

Referenced by __toString(), escaped(), parse(), parseAsBlock(), plain(), and text().

◆ transformText()

Message::transformText (   $string)
protected

Wrapper for what ever method we use to {{-transform wikitext.

Since
1.17
Parameters
string$stringWikitext message contents.
Returns
string Wikitext with {{-constructs replaced with their values.

Definition at line 1290 of file Message.php.

References getLanguage(), MessageCache\singleton(), and title().

Referenced by toString().

◆ unserialize()

Message::unserialize (   $serialized)
See also
Serializable::unserialize()
Since
1.26
Parameters
string$serialized

Definition at line 302 of file Message.php.

References $serialized, Language\factory(), format, key, Title\newFromText(), title(), and useDatabase().

◆ useDatabase()

Message::useDatabase (   $useDatabase)

Enable or disable database use.

Since
1.17
Parameters
bool$useDatabase
Returns
Message $this

Definition at line 813 of file Message.php.

References message.

Referenced by ApiMessageTest\compareMessages(), fetchMessage(), and unserialize().

Member Data Documentation

◆ $content

Content Message::$content = null
protected

Content object representing the message.

Definition at line 233 of file Message.php.

Referenced by content().

◆ $format

string Message::$format = 'parse'
protected
Deprecated:

Definition at line 218 of file Message.php.

Referenced by extractParam(), getFormat(), serialize(), and toString().

◆ $interface

array bool Message::$interface = 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 189 of file Message.php.

Referenced by extractParam(), and ApiHelpParamValueMessage\fetchMessage().

◆ $key

string 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 202 of file Message.php.

Referenced by ApiRawMessage\__construct(), ApiMessage\__construct(), RawMessage\fetchMessage(), fetchMessage(), getKey(), getTitle(), newFromKey(), serialize(), and toString().

◆ $keysToTry

string [] Message::$keysToTry
protected

List of keys to try when fetching the message.

Definition at line 207 of file Message.php.

Referenced by getKeysToTry(), and serialize().

◆ $language

Language bool Message::$language = false
protected

In which language to get this message.

Overrides the $interface setting.

Explicit language object, or false for user language

Definition at line 196 of file Message.php.

Referenced by extractParam(), ApiHelpParamValueMessage\fetchMessage(), and inLanguage().

◆ $listTypeMap

array Message::$listTypeMap
staticprotected
Initial value:
= [
'comma' => 'commaList'

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

Definition at line 176 of file Message.php.

◆ $message

◆ $parameters

array Message::$parameters = []
protected

List of parameters which will be substituted into the message.

Definition at line 212 of file Message.php.

Referenced by getParams(), and serialize().

◆ $title

Title Message::$title = null
protected

Title object to use as context.

Definition at line 228 of file Message.php.

Referenced by extractParam(), ApiHelpParamValueMessage\fetchMessage(), serialize(), and title().

◆ $useDatabase

bool Message::$useDatabase = true
protected

Whether database can be used.

Definition at line 223 of file Message.php.

Referenced by extractParam(), ApiHelpParamValueMessage\fetchMessage(), and serialize().

◆ FORMAT_BLOCK_PARSE

const 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 164 of file Message.php.

◆ FORMAT_ESCAPED

const Message::FORMAT_ESCAPED = 'escaped'

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

Definition at line 170 of file Message.php.

◆ FORMAT_PARSE

const Message::FORMAT_PARSE = 'parse'

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

Definition at line 166 of file Message.php.

◆ FORMAT_PLAIN

const Message::FORMAT_PLAIN = 'plain'

Use message text as-is.

Definition at line 162 of file Message.php.

◆ FORMAT_TEXT

const Message::FORMAT_TEXT = 'text'

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

Definition at line 168 of file Message.php.


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