X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FMessage.php;h=976f144e7041da14398afa1e8f0994727d0f12ae;hb=21b7b27f0379cff1b06efa95d27fa88684b65c57;hp=2feaed2b715dcfd0c34ade2116303997e3be1a85;hpb=881c1d30e418ebf85c24ae739ed22de397634932;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Message.php b/includes/Message.php index 2feaed2b71..976f144e70 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -606,7 +606,6 @@ class Message { * @since 1.18 * @param $param String|Array: Parameter as defined in this class. * @return Tuple(type, value) - * @throws MWException */ protected function extractParam( $param ) { if ( is_array( $param ) && isset( $param['raw'] ) ) { @@ -618,7 +617,11 @@ class Message { } elseif ( !is_array( $param ) ) { return array( 'before', $param ); } else { - throw new MWException( "Invalid message parameter: " . serialize( $param ) ); + trigger_error( + "Invalid message parameter: " . htmlspecialchars( serialize( $param ) ), + E_USER_WARNING + ); + return array( 'before', '[INVALID]' ); } } @@ -629,7 +632,8 @@ class Message { * @return string Wikitext parsed into HTML */ protected function parseText( $string ) { - return MessageCache::singleton()->parse( $string, $this->title, /*linestart*/true, $this->interface, $this->language )->getText(); + $out = MessageCache::singleton()->parse( $string, $this->title, /*linestart*/true, $this->interface, $this->language ); + return is_object( $out ) ? $out->getText() : $out; } /** @@ -670,3 +674,45 @@ class Message { } } + +/** + * Variant of the Message class. + * + * Rather than treating the message key as a lookup + * value (which is passed to the MessageCache and + * translated as necessary), a RawMessage key is + * treated as the actual message. + * + * All other functionality (parsing, escaping, etc.) + * is preserved. + * + * @since 1.21 + */ +class RawMessage extends Message { + /** + * Call the parent constructor, then store the key as + * the message. + * + * @param $key Message to use + * @param $params Parameters for the message + * @see Message::__construct + */ + public function __construct( $key, $params = array() ) { + parent::__construct( $key, $params ); + // The key is the message. + $this->message = $key; + } + + /** + * Fetch the message (in this case, the key). + * + * @return string + */ + public function fetchMessage() { + // Just in case the message is unset somewhere. + if( !isset( $this->message ) ) { + $this->message = $this->key; + } + return $this->message; + } +}