* Display default extensions messages for language subpages when the page being edite...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 7 Oct 2008 18:10:08 +0000 (18:10 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 7 Oct 2008 18:10:08 +0000 (18:10 +0000)
* Fix MessageCache::figureMessage() to allow slashes in message name

includes/EditPage.php
includes/MessageCache.php

index 6ffa9c6..4133c0f 100644 (file)
@@ -110,7 +110,7 @@ class EditPage {
         * @private
         */
        function getContent( $def_text = '' ) {
-               global $wgOut, $wgRequest, $wgParser, $wgMessageCache;
+               global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
 
                wfProfileIn( __METHOD__ );
                # Get variables from query string :P
@@ -124,9 +124,12 @@ class EditPage {
                // For other non-existent articles, use preload text if any.
                if ( !$this->mTitle->exists() ) {
                        if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
-                               $wgMessageCache->loadAllMessages();
                                # If this is a system message, get the default text.
-                               $text = wfMsgWeirdKey( $this->mTitle->getText() ) ;
+                               list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
+                               $wgMessageCache->loadAllMessages( $lang );
+                               $text = wfMsgGetKey( $message, false, $lang, false );
+                               if( wfEmptyMsg( $message, $text ) )
+                                       $text = '';
                        } else {
                                # If requested, preload some text.
                                $text = $this->getPreloadedText( $preload );
@@ -1044,11 +1047,8 @@ class EditPage {
         */
        function initialiseForm() {
                $this->edittime = $this->mArticle->getTimestamp();
-               $this->textbox1 = $this->getContent(false);
-               if ( $this->textbox1 === false) return false;
-
-               if ( !$this->mArticle->exists() && $this->mTitle->getNamespace() == NS_MEDIAWIKI )
-                       $this->textbox1 = wfMsgWeirdKey( $this->mTitle->getText() );
+               $this->textbox1 = $this->getContent( false );
+               if ( $this->textbox1 === false ) return false;
                wfProxyCheck();
                return true;
        }
index 0f2fc22..4fd7dda 100644 (file)
@@ -25,7 +25,7 @@ class MessageCache {
        var $mKeys, $mParserOptions, $mParser;
        var $mExtensionMessages = array();
        var $mInitialised = false;
-       var $mAllMessagesLoaded; // Extension messages
+       var $mAllMessagesLoaded = array(); // Extension messages
 
        // Variable for tracking which variables are loaded
        var $mLoadedLanguages = array();
@@ -766,12 +766,13 @@ class MessageCache {
                }
        }
 
-       function loadAllMessages() {
+       function loadAllMessages( $lang = false ) {
                global $wgExtensionMessagesFiles;
-               if ( $this->mAllMessagesLoaded ) {
+               $key = $lang === false ? '*' : $lang;
+               if ( isset( $this->mAllMessagesLoaded[$key] ) ) {
                        return;
                }
-               $this->mAllMessagesLoaded = true;
+               $this->mAllMessagesLoaded[$key] = true;
 
                # Some extensions will load their messages when you load their class file
                wfLoadAllExtensions();
@@ -779,7 +780,7 @@ class MessageCache {
                wfRunHooks( 'LoadAllMessages' );
                # Some register their messages in $wgExtensionMessagesFiles
                foreach ( $wgExtensionMessagesFiles as $name => $file ) {
-                       wfLoadExtensionMessages( $name );
+                       wfLoadExtensionMessages( $name, $lang );
                }
                # Still others will respond to neither, they are EVIL. We sometimes need to know!
        }
@@ -840,13 +841,17 @@ class MessageCache {
 
        public function figureMessage( $key ) {
                global $wgContLanguageCode;
-               $pieces = explode('/', $key, 2);
+               $pieces = explode( '/', $key );
+               if( count( $pieces ) < 2 )
+                       return array( $key, $wgContLanguageCode );
 
-               $key = $pieces[0];
+               $lang = array_pop( $pieces );
+               $validCodes = Language::getLanguageNames();
+               if( !array_key_exists( $lang, $validCodes ) )
+                       return array( $key, $wgContLanguageCode );
 
-               # Language the user is translating to
-               $langCode = isset($pieces[1]) ? $pieces[1] : $wgContLanguageCode;
-               return array( $key, $langCode );
+               $message = implode( '/', $pieces );
+               return array( $message, $lang );
        }
 
 }