MediaWiki 1.43.1
Wikimedia\Message\MessageValue Class Reference

Value object representing a message for i18n. More...

Inherits MediaWiki\Json\JsonDeserializable, and Wikimedia\Message\MessageSpecifier.

Inherited by Wikimedia\Message\DataMessageValue.

Collaboration diagram for Wikimedia\Message\MessageValue:

Public Member Functions

 __construct ( $key, $params=[])
 
 bitrateParams (... $values)
 Chainable mutator which adds parameters which are a number of bits per second (ParamType::BITRATE).
 
 commaListParams (... $values)
 Chainable mutator which adds comma lists (ListType::COMMA).
 
 dateParams (... $values)
 Chainable mutator which adds parameters which are a date timestamp (ParamType::DATE).
 
 dateTimeParams (... $values)
 Chainable mutator which adds parameters which are a date-time timestamp (ParamType::DATETIME).
 
 dump ()
 Dump the object for testing/debugging.
 
 expiryParams (... $values)
 Chainable mutator which adds parameters which are an expiry timestamp (ParamType::EXPIRY).
 
 getKey ()
 Get the message key.
 
 getParams ()
 Get the parameter array.
 
 listParamsOfType ( $listType,... $values)
 Chainable mutator which adds list parameters with a common type.
 
 longDurationParams (... $values)
 Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATION_LONG).
 
 numParams (... $values)
 Chainable mutator which adds numeric parameters (ParamType::NUM).
 
 objectParams (... $values)
 Chainable mutator which adds object parameters.
 
 params (... $values)
 Chainable mutator which adds text parameters and MessageParam parameters.
 
 pipeListParams (... $values)
 Chainable mutator which adds pipe lists (ListType::PIPE).
 
 plaintextParams (... $values)
 Chainable mutator which adds plaintext parameters (ParamType::PLAINTEXT).
 
 rawParams (... $values)
 Chainable mutator which adds "raw" parameters (ParamType::RAW).
 
 semicolonListParams (... $values)
 Chainable mutator which adds semicolon lists (ListType::SEMICOLON).
 
 shortDurationParams (... $values)
 Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATION_SHORT).
 
 sizeParams (... $values)
 Chainable mutator which adds parameters which are a number of bytes (ParamType::SIZE).
 
 textListParams (... $values)
 Chainable mutator which adds natural-language lists (ListType::AND).
 
 textParams (... $values)
 Chainable mutator which adds parameters of type text (ParamType::TEXT).
 
 textParamsOfType ( $type,... $values)
 Chainable mutator which adds text parameters with a common type.
 
 timeParams (... $values)
 Chainable mutator which adds parameters which are a time timestamp (ParamType::TIME).
 
 userGroupParams (... $values)
 Chainable mutator which adds parameters which are a user group (ParamType::GROUP).
 

Static Public Member Functions

static new ( $key, $params=[])
 Static constructor for easier chaining of ->params() methods.
 
static newFromJsonArray (JsonDeserializer $deserializer, array $json)
 Creates a new instance of the class and initialized it from the $json array.
 
static newFromSpecifier (MessageSpecifier $spec)
 Convert from any MessageSpecifier to a MessageValue.
 

Protected Member Functions

 toJsonArray ()
 

Detailed Description

Value object representing a message for i18n.

A MessageValue holds a key and an array of parameters. It can be converted to a string in a particular language using formatters obtained from an IMessageFormatterFactory.

MessageValues are pure value objects and are newable and (de)serializable.

Stability: newable

Definition at line 21 of file MessageValue.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Message\MessageValue::__construct ( $key,
$params = [] )
Stability: stable
to call
Parameters
string$key
(MessageParam|MessageSpecifier|string|int|float)[]$params Values that are not instances of MessageParam are wrapped using ParamType::TEXT.

Definition at line 37 of file MessageValue.php.

References Wikimedia\Message\MessageValue\params().

Member Function Documentation

◆ bitrateParams()

Wikimedia\Message\MessageValue::bitrateParams ( $values)

Chainable mutator which adds parameters which are a number of bits per second (ParamType::BITRATE).

Parameters
int|float...$values
Returns
$this

Definition at line 268 of file MessageValue.php.

References Wikimedia\Message\ParamType\BITRATE, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ commaListParams()

Wikimedia\Message\MessageValue::commaListParams ( $values)

Chainable mutator which adds comma lists (ListType::COMMA).

The list parameters thus created are formatted as a comma-separated list, or some local equivalent.

Parameters
(MessageParam|MessageSpecifier|string|int|float)[]...$values Each value is an array of items suitable to pass as $params to ListParam::__construct()
Returns
$this

Definition at line 310 of file MessageValue.php.

References Wikimedia\Message\ListType\COMMA, and Wikimedia\Message\MessageValue\listParamsOfType().

◆ dateParams()

Wikimedia\Message\MessageValue::dateParams ( $values)

Chainable mutator which adds parameters which are a date timestamp (ParamType::DATE).

Since
1.36
Parameters
string...$values Timestamp as accepted by the Wikimedia\Timestamp library.
Returns
$this

Definition at line 225 of file MessageValue.php.

References Wikimedia\Message\ParamType\DATE, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ dateTimeParams()

Wikimedia\Message\MessageValue::dateTimeParams ( $values)

Chainable mutator which adds parameters which are a date-time timestamp (ParamType::DATETIME).

Since
1.36
Parameters
string...$values Timestamp as accepted by the Wikimedia\Timestamp library.
Returns
$this

Definition at line 214 of file MessageValue.php.

References Wikimedia\Message\ParamType\DATETIME, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ dump()

Wikimedia\Message\MessageValue::dump ( )

Dump the object for testing/debugging.

Returns
string

Reimplemented in Wikimedia\Message\DataMessageValue.

Definition at line 361 of file MessageValue.php.

References Wikimedia\Message\MessageValue\params().

◆ expiryParams()

Wikimedia\Message\MessageValue::expiryParams ( $values)

Chainable mutator which adds parameters which are an expiry timestamp (ParamType::EXPIRY).

Parameters
string...$values Timestamp as accepted by the Wikimedia\Timestamp library, or "infinity"
Returns
$this

Definition at line 203 of file MessageValue.php.

References Wikimedia\Message\ParamType\EXPIRY, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ getKey()

◆ getParams()

Wikimedia\Message\MessageValue::getParams ( )

Get the parameter array.

Returns
MessageParam[]

Implements Wikimedia\Message\MessageSpecifier.

Definition at line 83 of file MessageValue.php.

Referenced by Wikimedia\Message\DataMessageValue\dump(), and MediaWiki\Api\Validator\ApiParamValidatorCallbacks\recordCondition().

◆ listParamsOfType()

Wikimedia\Message\MessageValue::listParamsOfType ( $listType,
$values )

Chainable mutator which adds list parameters with a common type.

Parameters
string$listTypeOne of the ListType constants
(MessageParam|MessageSpecifier|string|int|float)[]...$values Each value is an array of items suitable to pass as $params to ListParam::__construct()
Returns
$this

Definition at line 141 of file MessageValue.php.

References Wikimedia\Message\MessageValue\params().

Referenced by Wikimedia\Message\MessageValue\commaListParams(), Wikimedia\Message\MessageValue\pipeListParams(), Wikimedia\Message\MessageValue\semicolonListParams(), and Wikimedia\Message\MessageValue\textListParams().

◆ longDurationParams()

Wikimedia\Message\MessageValue::longDurationParams ( $values)

Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATION_LONG).

This is similar to shorDurationParams() except that the result will be more verbose.

Parameters
int|float...$values
Returns
$this

Definition at line 178 of file MessageValue.php.

References Wikimedia\Message\ParamType\DURATION_LONG, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ new()

static Wikimedia\Message\MessageValue::new ( $key,
$params = [] )
static

Static constructor for easier chaining of ->params() methods.

Parameters
string$key
(MessageParam|MessageSpecifier|string|int|float)[]$params
Returns
MessageValue

Definition at line 49 of file MessageValue.php.

References $params.

◆ newFromJsonArray()

static Wikimedia\Message\MessageValue::newFromJsonArray ( JsonDeserializer $deserializer,
array $json )
static

Creates a new instance of the class and initialized it from the $json array.

Parameters
JsonDeserializer$deserializeran instance of JsonDeserializer to use for nested properties if they need special care.
array$json
Returns
JsonDeserializable

Implements MediaWiki\Json\JsonDeserializable.

Reimplemented in Wikimedia\Message\DataMessageValue.

Definition at line 379 of file MessageValue.php.

◆ newFromSpecifier()

static Wikimedia\Message\MessageValue::newFromSpecifier ( MessageSpecifier $spec)
static

Convert from any MessageSpecifier to a MessageValue.

When the given object is an instance of MessageValue, the same object is returned.

Since
1.43
Parameters
MessageSpecifier$spec
Returns
MessageValue

Definition at line 62 of file MessageValue.php.

References Wikimedia\Message\MessageSpecifier\getKey(), and Wikimedia\Message\MessageSpecifier\getParams().

Referenced by Wikimedia\Message\ScalarParam\__construct(), MediaWiki\Api\ApiBase\addBlockInfoToStatus(), MediaWiki\Api\ApiMain\errorMessagesFromException(), MediaWiki\HTMLForm\HTMLForm\getMessage(), and MediaWiki\HTMLForm\HTMLFormField\getMessage().

◆ numParams()

Wikimedia\Message\MessageValue::numParams ( $values)

Chainable mutator which adds numeric parameters (ParamType::NUM).

Parameters
int|float...$values
Returns
$this

Definition at line 164 of file MessageValue.php.

References Wikimedia\Message\ParamType\NUM, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ objectParams()

Wikimedia\Message\MessageValue::objectParams ( $values)

Chainable mutator which adds object parameters.

Deprecated
since 1.43
Parameters
Stringable...$values stringable object values
Returns
$this

Definition at line 125 of file MessageValue.php.

References Wikimedia\Message\ParamType\OBJECT, Wikimedia\Message\MessageValue\params(), and wfDeprecated().

◆ params()

Wikimedia\Message\MessageValue::params ( $values)

Chainable mutator which adds text parameters and MessageParam parameters.

Parameters
MessageParam|MessageSpecifier|string|int|float...$values
Returns
$this

Definition at line 93 of file MessageValue.php.

References Wikimedia\Message\MessageValue\params(), and Wikimedia\Message\ParamType\TEXT.

Referenced by Wikimedia\Message\MessageValue\__construct(), Wikimedia\Message\MessageValue\dump(), Wikimedia\Message\MessageValue\listParamsOfType(), Wikimedia\Message\MessageValue\objectParams(), Wikimedia\Message\MessageValue\params(), and Wikimedia\Message\MessageValue\textParamsOfType().

◆ pipeListParams()

Wikimedia\Message\MessageValue::pipeListParams ( $values)

Chainable mutator which adds pipe lists (ListType::PIPE).

The list parameters thus created are formatted as a pipe ("|") -separated list, or some local equivalent.

Parameters
(MessageParam|MessageSpecifier|string|int|float)[]...$values Each value is an array of items suitable to pass as $params to ListParam::__construct()
Returns
$this

Definition at line 338 of file MessageValue.php.

References Wikimedia\Message\MessageValue\listParamsOfType(), and Wikimedia\Message\ListType\PIPE.

◆ plaintextParams()

Wikimedia\Message\MessageValue::plaintextParams ( $values)

Chainable mutator which adds plaintext parameters (ParamType::PLAINTEXT).

Plaintext parameters are substituted after formatter processing. The value will be escaped by the formatter as appropriate for the target output format so as to be represented as plain text rather than as any sort of markup.

Parameters
string...$values
Returns
$this

Definition at line 296 of file MessageValue.php.

References Wikimedia\Message\ParamType\PLAINTEXT, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ rawParams()

Wikimedia\Message\MessageValue::rawParams ( $values)

Chainable mutator which adds "raw" parameters (ParamType::RAW).

Raw parameters are substituted after formatter processing. The caller is responsible for ensuring that the value will be safe for the intended output format, and documenting what that intended output format is.

Parameters
string...$values
Returns
$this

Definition at line 282 of file MessageValue.php.

References Wikimedia\Message\ParamType\RAW, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ semicolonListParams()

Wikimedia\Message\MessageValue::semicolonListParams ( $values)

Chainable mutator which adds semicolon lists (ListType::SEMICOLON).

The list parameters thus created are formatted as a semicolon-separated list, or some local equivalent.

Parameters
(MessageParam|MessageSpecifier|string|int|float)[]...$values Each value is an array of items suitable to pass as $params to ListParam::__construct()
Returns
$this

Definition at line 324 of file MessageValue.php.

References Wikimedia\Message\MessageValue\listParamsOfType(), and Wikimedia\Message\ListType\SEMICOLON.

◆ shortDurationParams()

Wikimedia\Message\MessageValue::shortDurationParams ( $values)

Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATION_SHORT).

This is similar to longDurationParams() except that the result will be more compact.

Parameters
int|float...$values
Returns
$this

Definition at line 192 of file MessageValue.php.

References Wikimedia\Message\ParamType\DURATION_SHORT, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ sizeParams()

Wikimedia\Message\MessageValue::sizeParams ( $values)

Chainable mutator which adds parameters which are a number of bytes (ParamType::SIZE).

Parameters
int...$values
Returns
$this

Definition at line 257 of file MessageValue.php.

References Wikimedia\Message\ParamType\SIZE, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ textListParams()

Wikimedia\Message\MessageValue::textListParams ( $values)

Chainable mutator which adds natural-language lists (ListType::AND).

The list parameters thus created, when formatted, are joined as in natural language. In English, this means a comma-separated list, with the last two elements joined with "and".

Parameters
(MessageParam|string)[]...$values
Returns
$this

Definition at line 352 of file MessageValue.php.

References Wikimedia\Message\ListType\AND, and Wikimedia\Message\MessageValue\listParamsOfType().

◆ textParams()

Wikimedia\Message\MessageValue::textParams ( $values)

Chainable mutator which adds parameters of type text (ParamType::TEXT).

Parameters
MessageSpecifier|string|int|float...$values
Returns
$this

Definition at line 154 of file MessageValue.php.

References Wikimedia\Message\ParamType\TEXT, and Wikimedia\Message\MessageValue\textParamsOfType().

◆ textParamsOfType()

◆ timeParams()

Wikimedia\Message\MessageValue::timeParams ( $values)

Chainable mutator which adds parameters which are a time timestamp (ParamType::TIME).

Since
1.36
Parameters
string...$values Timestamp as accepted by the Wikimedia\Timestamp library.
Returns
$this

Definition at line 236 of file MessageValue.php.

References Wikimedia\Message\MessageValue\textParamsOfType(), and Wikimedia\Message\ParamType\TIME.

◆ toJsonArray()

Wikimedia\Message\MessageValue::toJsonArray ( )
protected

Reimplemented in Wikimedia\Message\DataMessageValue.

Definition at line 370 of file MessageValue.php.

◆ userGroupParams()

Wikimedia\Message\MessageValue::userGroupParams ( $values)

Chainable mutator which adds parameters which are a user group (ParamType::GROUP).

Since
1.38
Parameters
string...$values User Groups
Returns
$this

Definition at line 247 of file MessageValue.php.

References Wikimedia\Message\ParamType\GROUP, and Wikimedia\Message\MessageValue\textParamsOfType().


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