* (bug 26208) Mark directionality of some interlanguage links
* (bug 26034) Make the "View / Read" tab in content_navigation style tabs remain
selected when the action is "purge".
+* (bug 14267) Support a MediaWiki:Mainpage-nstab override for the subject namespace
+ tab on the mainpage of a wiki.
=== API changes in 1.18 ===
* (bug 26339) Throw warning when truncating an overlarge API result
* @since 1.18
*/
function wfMessageFallback( /*...*/ ) {
- $keys = func_get_args();
- $first = $keys[0];
- foreach ( $keys as $key ) {
- if ( wfEmptyMsg( $key ) ) {
- continue;
- }
- return wfMessage( $key );
- }
- return wfMessage( $first );
+ $args = func_get_args();
+ return call_user_func_array( array( 'Message', 'newFallbackSequence' ), $args );
}
/**
/**
* Constructor.
- * @param $key String: message key
+ * @param $key: message key, or array of message keys to try and use the first non-empty message for
* @param $params Array message parameters
* @return Message: $this
*/
return new self( $key, $params );
}
+ /**
+ * 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
+ * instance of the first message key is returned.
+ * @param Varargs: message keys
+ * @return Message: $this
+ */
+ public static function newFallbackSequence( /*...*/ ) {
+ global $wgMessageCache;
+ $keys = func_get_args();
+ if ( func_num_args() == 1 ) {
+ if ( is_array($keys[0]) ) {
+ // Allow an array to be passed as the first argument instead
+ $keys = array_values($keys[0]);
+ } else {
+ // Optimize a single string to not need special fallback handling
+ $keys = $keys[0];
+ }
+ }
+ return new self( $keys );
+ }
+
/**
* Adds parameters to the parameter list of this message.
* @param Varargs: parameters as Strings
protected function getMessageText() {
$message = $this->fetchMessage();
if ( $message === false ) {
- return '<' . htmlspecialchars( $this->key ) . '>';
+ return '<' . htmlspecialchars( is_array($this->key) ? $this->key[0] : $this->key ) . '>';
} else {
return $message;
}
protected function fetchMessage() {
if ( !isset( $this->message ) ) {
global $wgMessageCache;
- $this->message = $wgMessageCache->get( $this->key, $this->useDatabase, $this->language );
+ if ( is_array($this->key) ) {
+ foreach ( $this->key as $key ) {
+ $message = $wgMessageCache->get( $key, $this->useDatabase, $this->language );
+ if ( $message !== false && $message !== '' ) {
+ break;
+ }
+ }
+ $this->message = $message;
+ } else {
+ $this->message = $wgMessageCache->get( $this->key, $this->useDatabase, $this->language );
+ }
}
return $this->message;
}
-}
\ No newline at end of file
+}
$query = 'action=edit&redlink=1';
}
- $text = wfMsg( $message );
- if ( wfEmptyMsg( $message, $text ) ) {
+ // wfMessageFallback will nicely accept $message as an array of fallbacks
+ // or just a single key
+ $msg = wfMessageFallback( $message );
+ if ( is_array($message) ) {
+ // for hook compatibility just keep the last message name
+ $message = end($message);
+ }
+ if ( $msg->exists() ) {
+ $text = $msg->plain();
+ } else {
global $wgContLang;
$text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
}
}
// Adds namespace links
+ $subjectMsg = array( "nstab-$subjectId" );
+ if ( $subjectPage->isMainPage() ) {
+ array_unshift($subjectMsg, 'mainpage-nstab');
+ }
$content_navigation['namespaces'][$subjectId] = $this->tabAction(
- $subjectPage, 'nstab-' . $subjectId, !$isTalk && !$preventActiveTabs, '', $userCanRead
+ $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
);
$content_navigation['namespaces'][$subjectId]['context'] = 'subject';
$content_navigation['namespaces'][$talkId] = $this->tabAction(
- $talkPage, !wfEmptyMsg("nstab-$talkId") ? "nstab-$talkId" : 'talk', $isTalk && !$preventActiveTabs, '', $userCanRead
+ $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
);
$content_navigation['namespaces'][$talkId]['context'] = 'talk';
if ( $title->exists() && $userCanRead ) {
$content_navigation['views']['view'] = $this->tabAction(
$isTalk ? $talkPage : $subjectPage,
- !wfEmptyMsg( "$skname-view-view" ) ? "$skname-view-view" : 'view',
+ array( "$skname-view-view", 'view' ),
( $onPage && ($action == 'view' || $action == 'purge' ) ), '', true
);
$content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
return false;
}
+ /**
+ * Is this the mainpage?
+ * @note Title::newFromText seams to be sufficiently optimized by the title
+ * cache that we don't need to over-optimize by doing direct comparisons and
+ * acidentally creating new bugs where $title->equals( Title::newFromText() )
+ * ends up reporting something differently than $title->isMainPage();
+ *
+ * @return Bool
+ */
+ public function isMainPage() {
+ return $this->equals( Title::newMainPage() );
+ }
+
/**
* Is this a talk page of some sort?
*