*
* @since 1.17
*/
-class Message implements MessageSpecifier {
+class Message implements MessageSpecifier, Serializable {
/**
* In which language to get this message. True, which is the default,
/**
* @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.
*
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' );
}
$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
*
*
* @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
*
* @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