diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
commit | 6dc1997577fab2c366781fd7048144935afa0012 (patch) | |
tree | 8918d28c7ab4342f0738985e37af1dfc42d0e93a /includes/Message.php | |
parent | 150f94f051128f367bc89f6b7e5f57eb2a69fc62 (diff) | |
parent | fa89acd685cb09cdbe1c64cbb721ec64975bbbc1 (diff) |
Merge commit 'fa89acd'
# Conflicts:
# .gitignore
# extensions/ArchInterWiki.sql
Diffstat (limited to 'includes/Message.php')
-rw-r--r-- | includes/Message.php | 81 |
1 files changed, 76 insertions, 5 deletions
diff --git a/includes/Message.php b/includes/Message.php index 134af0ed..54abfd15 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' ); } @@ -253,6 +264,41 @@ class Message implements MessageSpecifier { } /** + * @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 * * @return bool True if this is a multi-key message, that is, if the key provided to the @@ -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 @@ -365,6 +411,31 @@ class Message implements MessageSpecifier { } /** + * 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 @@ -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 { |