* Use wfMessage() instead of wfMsgGetKey() and wfEmptyMsg()
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 3 Feb 2011 15:29:13 +0000 (15:29 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 3 Feb 2011 15:29:13 +0000 (15:29 +0000)
* Factorise common code

includes/Article.php
includes/EditPage.php

index 726797e..7812e35 100644 (file)
@@ -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 );
index 65df005..8ed9167 100644 (file)
@@ -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 );