X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMessage.php;h=54efd261b656d6222a64e685298247c04060c8e4;hb=bedf92248c6dbf3b339a2a9e0220850b4d1aaa85;hp=134af0ed45c5d120bfb56a96c975260e4bb0f8d6;hpb=bab1f09f9c0a48949cdb5351a61917bdd7ee9397;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Message.php b/includes/Message.php index 134af0ed45..54efd261b6 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -156,7 +156,7 @@ * * @since 1.17 */ -class Message implements MessageSpecifier { +class Message implements MessageSpecifier, Serializable { /** * In which language to get this message. True, which is the default, @@ -226,8 +226,9 @@ class Message implements MessageSpecifier { /** * @since 1.17 * - * @param string|string[] $key Message key or array of message keys to try and use the first - * non-empty message for. + * @param 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. * @param array $params Message parameters. * @param Language $language Optional language of the message, defaults to $wgLang. * @@ -236,6 +237,16 @@ class Message implements MessageSpecifier { public function __construct( $key, $params = array(), Language $language = null ) { global $wgLang; + if ( $key instanceof MessageSpecifier ) { + if ( $params ) { + throw new InvalidArgumentException( + '$params must be empty if $key is a MessageSpecifier' + ); + } + $params = $key->getParams(); + $key = $key->getKey(); + } + if ( !is_string( $key ) && !is_array( $key ) ) { throw new InvalidArgumentException( '$key must be a string or an array' ); } @@ -252,6 +263,41 @@ class Message implements MessageSpecifier { $this->language = $language ?: $wgLang; } + /** + * @see Serializable::serialize() + * @since 1.26 + * @return string + */ + public function serialize() { + return serialize( array( + 'interface' => $this->interface, + 'language' => $this->language->getCode(), + 'key' => $this->key, + 'keysToTry' => $this->keysToTry, + 'parameters' => $this->parameters, + 'format' => $this->format, + 'useDatabase' => $this->useDatabase, + 'title' => $this->title, + ) ); + } + + /** + * @see Serializable::unserialize() + * @since 1.26 + * @param string $serialized + */ + public function unserialize( $serialized ) { + $data = unserialize( $serialized ); + $this->interface = $data['interface']; + $this->key = $data['key']; + $this->keysToTry = $data['keysToTry']; + $this->parameters = $data['parameters']; + $this->format = $data['format']; + $this->useDatabase = $data['useDatabase']; + $this->language = Language::factory( $data['language'] ); + $this->title = $data['title']; + } + /** * @since 1.24 * @@ -327,7 +373,7 @@ class Message implements MessageSpecifier { * * @since 1.17 * - * @param string|string[] $key Message key or array of keys. + * @param string|string[]|MessageSpecifier $key * @param mixed $param,... Parameters as strings. * * @return Message @@ -364,12 +410,37 @@ class Message implements MessageSpecifier { return new self( $keys ); } + /** + * 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 $wgForceUIMsgAsContentMsg + * @return Title + * @since 1.26 + */ + public function getTitle() { + global $wgContLang, $wgForceUIMsgAsContentMsg; + + $code = $this->language->getCode(); + $title = $this->key; + if ( + $wgContLang->getCode() !== $code + && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) + ) { + $title .= '/' . $code; + } + + return Title::makeTitle( NS_MEDIAWIKI, $wgContLang->ucfirst( strtr( $title, ' ', '_' ) ) ); + } + /** * Adds parameters to the parameter list of this message. * * @since 1.17 * - * @param mixed $params,... Parameters as strings, or a single argument that is + * @param mixed ... Parameters as strings, or a single argument that is * an array of strings. * * @return Message $this @@ -597,7 +668,7 @@ class Message implements MessageSpecifier { if ( $lang instanceof Language || $lang instanceof StubUserLang ) { $this->language = $lang; } elseif ( is_string( $lang ) ) { - if ( $this->language->getCode() != $lang ) { + if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) { $this->language = Language::factory( $lang ); } } else {