From: Alexandre Emsenhuber Date: Tue, 7 Oct 2008 18:10:08 +0000 (+0000) Subject: * Display default extensions messages for language subpages when the page being edite... X-Git-Tag: 1.31.0-rc.0~44851 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=02c8f58aa31b1dee6b02bb47482850a90b430012;p=lhc%2Fweb%2Fwiklou.git * Display default extensions messages for language subpages when the page being edited doesn't exist * Fix MessageCache::figureMessage() to allow slashes in message name --- diff --git a/includes/EditPage.php b/includes/EditPage.php index 6ffa9c63c7..4133c0fac2 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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; } diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 0f2fc22196..4fd7dda455 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -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 ); } }