return new self( $key, $params );
}
+ /**
+ * Transform a MessageSpecifier or a primitive value used interchangeably with
+ * specifiers (a message key string, or a key + params array) into a proper Message
+ * @param string|array|MessageSpecifier $value
+ * @return Message
+ * @throws InvalidArgumentException
+ * @since 1.27
+ */
+ public static function newFromSpecifier( $value ) {
+ if ( $value instanceof RawMessage ) {
+ $message = new RawMessage( $value->getKey(), $value->getParams() );
+ } elseif ( $value instanceof MessageSpecifier ) {
+ $message = new Message( $value );
+ } elseif ( is_array( $value ) ) {
+ $key = array_shift( $value );
+ $message = new Message( $key, $value );
+ } elseif ( is_string( $value ) ) {
+ $message = new Message( $value );
+ } else {
+ throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
+ . gettype( $value ) );
+ }
+
+ return $message;
+ }
+
/**
* Factory function accepting multiple message keys and returning a message instance
* for the first message which is non-empty. If all messages are empty then an
public function getTitle() {
global $wgContLang, $wgForceUIMsgAsContentMsg;
- $code = $this->getLanguage()->getCode();
$title = $this->key;
if (
- $wgContLang->getCode() !== $code
+ !$this->language->equals( $wgContLang )
&& in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
) {
+ $code = $this->language->getCode();
$title .= '/' . $code;
}