From a58b7f5139e45aa7174c43bc6d8909ef1cc06928 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Thu, 3 Feb 2011 15:29:13 +0000 Subject: [PATCH] * Use wfMessage() instead of wfMsgGetKey() and wfEmptyMsg() * Factorise common code --- includes/Article.php | 32 ++++++++++++++++++++++++++------ includes/EditPage.php | 6 +++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 726797e658..7812e35809 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -257,12 +257,10 @@ 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 ) { - # If this is a system message, get the default text. - list( $message, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) ); - $text = wfMsgGetKey( $message, false, $lang, false ); - - if ( wfEmptyMsg( $message, $text ) ) + $text = $this->getDefaultMessageText(); + if ( $text === false ) { $text = ''; + } } else { $text = wfMsgExt( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', 'parsemag' ); } @@ -277,6 +275,28 @@ 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... * @@ -1391,7 +1411,7 @@ class Article { wfMsgNoTrans( 'missingarticle-rev', $oldid ) ); } elseif ( $this->mTitle->getNamespace() === NS_MEDIAWIKI ) { // Use the default message text - $text = $this->getContent(); + $text = $this->getDefaultMessageText(); } else { $createErrors = $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ); $editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ); diff --git a/includes/EditPage.php b/includes/EditPage.php index 65df005ab7..8ed91673eb 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -141,10 +141,10 @@ class EditPage { if ( !$this->mTitle->exists() ) { if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { # If this is a system message, get the default text. - list( $message, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) ); - $text = wfMsgGetKey( $message, false, $lang, false ); - if( wfEmptyMsg( $message, $text ) ) + $text = $this->mArticle->getDefaultMessageText(); + if( $text === false ) { $text = $this->getPreloadedText( $preload ); + } } else { # If requested, preload some text. $text = $this->getPreloadedText( $preload ); -- 2.20.1