Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
76.92% |
10 / 13 |
|
66.67% |
4 / 6 |
CRAP | |
0.00% |
0 / 1 |
| RawMessage | |
83.33% |
10 / 12 |
|
66.67% |
4 / 6 |
8.30 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| fetchMessage | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getTextOfRawMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParamsOfRawMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getParams | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Language; |
| 8 | |
| 9 | use MediaWiki\Message\Message; |
| 10 | |
| 11 | /** |
| 12 | * Variant of the Message class. |
| 13 | * |
| 14 | * Rather than treating the message key as a lookup |
| 15 | * value (which is passed to the MessageCache and |
| 16 | * translated as necessary), a RawMessage key is |
| 17 | * treated as the actual message. |
| 18 | * |
| 19 | * All other functionality (parsing, escaping, etc.) |
| 20 | * is preserved. |
| 21 | * |
| 22 | * @newable |
| 23 | * @since 1.21 |
| 24 | */ |
| 25 | class RawMessage extends Message { |
| 26 | |
| 27 | /** |
| 28 | * Call the parent constructor, then store the key as |
| 29 | * the message. |
| 30 | * |
| 31 | * @stable to call |
| 32 | * @see Message::__construct |
| 33 | * |
| 34 | * @param string $text Message to use. |
| 35 | * @param array $params Parameters for the message. |
| 36 | */ |
| 37 | public function __construct( string $text, $params = [] ) { |
| 38 | parent::__construct( $text, $params ); |
| 39 | |
| 40 | // The key is the message. |
| 41 | $this->message = $text; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Fetch the message (in this case, the key). |
| 46 | * |
| 47 | * @return string |
| 48 | */ |
| 49 | public function fetchMessage() { |
| 50 | // Just in case the message is unset somewhere. |
| 51 | $this->message ??= $this->key; |
| 52 | |
| 53 | return $this->message; |
| 54 | } |
| 55 | |
| 56 | public function getTextOfRawMessage(): string { |
| 57 | return $this->key; |
| 58 | } |
| 59 | |
| 60 | public function getParamsOfRawMessage(): array { |
| 61 | return $this->parameters; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * To conform to the MessageSpecifier interface, always return 'rawmessage', |
| 66 | * which is a real message key that can be used with MessageValue and other classes. |
| 67 | */ |
| 68 | public function getKey(): string { |
| 69 | return 'rawmessage'; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * To conform to the MessageSpecifier interface, return parameters that are valid with the |
| 74 | * 'rawmessage' message, and can be used with MessageValue and other classes. |
| 75 | * @return string[] |
| 76 | */ |
| 77 | public function getParams(): array { |
| 78 | // If the provided text is equivalent to 'rawmessage', return the provided params. |
| 79 | if ( $this->key === '$1' ) { |
| 80 | return $this->parameters; |
| 81 | } |
| 82 | // If there are no provided params, return the provided text as the single param. |
| 83 | if ( !$this->parameters ) { |
| 84 | return [ $this->key ]; |
| 85 | } |
| 86 | // As a last resort, substitute the provided params into the single param accepted by |
| 87 | // 'rawmessage'. This may access global state. |
| 88 | return [ $this->plain() ]; |
| 89 | } |
| 90 | |
| 91 | } |
| 92 | |
| 93 | // This alias can not be removed, because serialized instances of this class are stored in Echo |
| 94 | // tables, until we either migrate to JSON serialization (T325703) or expire those events (T383948). |
| 95 | /** @deprecated class alias since 1.40 */ |
| 96 | class_alias( RawMessage::class, 'RawMessage' ); |