From 136f4c06fa97ca00b2f4ed00822358c8a1dc1961 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 5 Feb 2011 15:11:52 +0000 Subject: [PATCH] Deprecated wfMsgWeirdKey(), use wfMessage() instead. Moved getDefaultMessageText() from Article to Title so that it can be used there instead of duplicating code. No usage in extensions. --- includes/Article.php | 28 +++------------------------- includes/EditPage.php | 2 +- includes/GlobalFunctions.php | 4 +++- includes/Title.php | 34 ++++++++++++++++++++++++---------- maintenance/addwiki.php | 2 +- 5 files changed, 32 insertions(+), 38 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 59e4c85e92..666b2ddb65 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -257,7 +257,7 @@ class Article { # If this is a MediaWiki:x message, then load the messages # and return the message value for x. if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - $text = $this->getDefaultMessageText(); + $text = $this->mTitle->getDefaultMessageText(); if ( $text === false ) { $text = ''; } @@ -275,28 +275,6 @@ class Article { } } - /** - * Get the default message text or false if the message doesn't exist - * - * @return String or false - */ - public function getDefaultMessageText() { - global $wgContLang; - - if ( $this->mTitle->getNamespace() != NS_MEDIAWIKI ) { // Just in case - return false; - } - - list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) ); - $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false ); - - if ( $message->exists() ) { - return $message->plain(); - } else { - return false; - } - } - /** * Get the text of the current revision. No side-effects... * @@ -1411,7 +1389,7 @@ class Article { wfMsgNoTrans( 'missingarticle-rev', $oldid ) ); } elseif ( $this->mTitle->getNamespace() === NS_MEDIAWIKI ) { // Use the default message text - $text = $this->getDefaultMessageText(); + $text = $this->mTitle->getDefaultMessageText(); } else { $createErrors = $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ); $editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ); @@ -4162,7 +4140,7 @@ class Article { if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { // This doesn't quite make sense; the user is asking for // information about the _page_, not the message... -- RC - $wgOut->addHTML( htmlspecialchars( wfMsgWeirdKey( $this->mTitle->getText() ) ) ); + $wgOut->addHTML( htmlspecialchars( $this->mTitle->getDefaultMessageText() ) ); } else { $msg = $wgUser->isLoggedIn() ? 'noarticletext' diff --git a/includes/EditPage.php b/includes/EditPage.php index 8ed91673eb..57d2590ce0 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -141,7 +141,7 @@ class EditPage { if ( !$this->mTitle->exists() ) { if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { # If this is a system message, get the default text. - $text = $this->mArticle->getDefaultMessageText(); + $text = $this->mTitle->getDefaultMessageText(); if( $text === false ) { $text = $this->getPreloadedText( $preload ); } diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 334ad86b93..9af9b92000 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -607,7 +607,9 @@ function wfMsgReal( $key, $args, $useDB = true, $forContent = false, $transform /** * This function provides the message source for messages to be edited which are *not* stored in the database. - * @param $key String: + * + * @deprecated in 1.18; use wfMessage() + * @param $key String */ function wfMsgWeirdKey( $key ) { $source = wfMsgGetKey( $key, false, true, false ); diff --git a/includes/Title.php b/includes/Title.php index 38cc32790f..ca5aa661c6 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3760,12 +3760,8 @@ class Title { // selflink, possibly with fragment return $this->mDbkeyform == ''; case NS_MEDIAWIKI: - // If the page is form Mediawiki:message/lang, calling wfMsgWeirdKey causes - // the full l10n of that language to be loaded. That takes much memory and - // isn't needed. So we strip the language part away. - list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 ); // known system message - return (bool)wfMsgWeirdKey( $basename ); + return $this->getDefaultMessageText() !== false; default: return false; } @@ -3796,16 +3792,34 @@ class Title { if ( $this->mNamespace == NS_MEDIAWIKI ) { // If the page doesn't exist but is a known system message, default // message content will be displayed, same for language subpages - // Also, if the page is form Mediawiki:message/lang, calling wfMsgWeirdKey - // causes the full l10n of that language to be loaded. That takes much - // memory and isn't needed. So we strip the language part away. - list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 ); - return (bool)wfMsgWeirdKey( $basename ); + return $this->getDefaultMessageText() !== false; } return false; } + /** + * Get the default message text or false if the message doesn't exist + * + * @return String or false + */ + public function getDefaultMessageText() { + global $wgContLang; + + if ( $this->getNamespace() != NS_MEDIAWIKI ) { // Just in case + return false; + } + + list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) ); + $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false ); + + if ( $message->exists() ) { + return $message->plain(); + } else { + return false; + } + } + /** * Is this in a namespace that allows actual pages? * diff --git a/maintenance/addwiki.php b/maintenance/addwiki.php index cccef15ad0..73e2ebe035 100644 --- a/maintenance/addwiki.php +++ b/maintenance/addwiki.php @@ -129,7 +129,7 @@ class AddWiki extends Maintenance { } } - $title = Title::newFromText( wfMsgWeirdKey( "mainpage/$lang" ) ); + $title = Title::newFromText( wfMessage( 'mainpage' )->inLanguage( $lang )->useDatabase( false )->plain() ); $this->output( "Writing main page to " . $title->getPrefixedDBkey() . "\n" ); $article = new Article( $title ); $ucsite = ucfirst( $site ); -- 2.20.1