MediaWiki master
RawMessage.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Language;
22
23use InvalidArgumentException;
25
40class RawMessage extends Message {
41
54 public function __construct( $text, $params = [] ) {
55 if ( !is_string( $text ) ) {
56 throw new InvalidArgumentException( '$text must be a string' );
57 }
58
59 parent::__construct( $text, $params );
60
61 // The key is the message.
62 $this->message = $text;
63 }
64
70 public function fetchMessage() {
71 // Just in case the message is unset somewhere.
72 $this->message ??= $this->key;
73
74 return $this->message;
75 }
76
77 public function getTextOfRawMessage() {
78 return $this->key;
79 }
80
81 public function getParamsOfRawMessage() {
82 return $this->parameters;
83 }
84
90 public function getKey() {
91 return 'rawmessage';
92 }
93
99 public function getParams() {
100 // If the provided text is equivalent to 'rawmessage', return the provided params.
101 if ( $this->key === '$1' ) {
102 return $this->parameters;
103 }
104 // If there are no provided params, return the provided text as the single param.
105 if ( !$this->parameters ) {
106 return [ $this->key ];
107 }
108 // As a last resort, substitute the provided params into the single param accepted by
109 // 'rawmessage'. This may access global state.
110 return [ $this->plain() ];
111 }
112
113}
114
116class_alias( RawMessage::class, 'RawMessage' );
array $params
The job parameters.
Variant of the Message class.
__construct( $text, $params=[])
Call the parent constructor, then store the key as the message.
fetchMessage()
Fetch the message (in this case, the key).
getKey()
To conform to the MessageSpecifier interface, always return 'rawmessage', which is a real message key...
getParams()
To conform to the MessageSpecifier interface, return parameters that are valid with the 'rawmessage' ...
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:158
string $key
The message key.
Definition Message.php:206
plain()
Returns the message text as-is, only parameters are substituted.
Definition Message.php:1136
array $parameters
List of parameters which will be substituted into the message.
Definition Message.php:223
string null false $message
Definition Message.php:244