*
* @since 1.17
*/
-class Message {
+class Message implements MessageSpecifier {
/**
* In which language to get this message. True, which is the default,
$this->key = reset( $this->keysToTry );
$this->parameters = array_values( $params );
- $this->language = $language ? $language : $wgLang;
+ $this->language = $language ?: $wgLang;
}
/**
* Returns the message key.
*
* If a list of multiple possible keys was supplied to the constructor, this method may
- * return any of these keys. After the message ahs been fetched, this method will return
+ * return any of these keys. After the message has been fetched, this method will return
* the key that was actually used to fetch the message.
*
* @since 1.21
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.
*
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 {