* Parse MediaWiki message translations with a correct language setting on preview
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Fri, 7 Mar 2008 14:02:12 +0000 (14:02 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Fri, 7 Mar 2008 14:02:12 +0000 (14:02 +0000)
RELEASE-NOTES
includes/EditPage.php
includes/Parser.php
includes/ParserOptions.php

index 07610f5..8827371 100644 (file)
@@ -74,6 +74,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13274) Change links for messages to ucfirst
 * (bug 13273) "Categories:" message at the bottom of the page shouldn't have
   hardcoded colon, use new 'colon-separator' message instead
+* Parse MediaWiki message translations with a correct language setting on preview
 
 === API changes in 1.13 ===
 
index 33bac6a..25f1e02 100644 (file)
@@ -1494,7 +1494,7 @@ END
         * @todo document
         */
        function getPreviewText() {
-               global $wgOut, $wgUser, $wgTitle, $wgParser;
+               global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang;
 
                $fname = 'EditPage::getPreviewText';
                wfProfileIn( $fname );
@@ -1542,7 +1542,26 @@ END
                                $toparse="== {$this->summary} ==\n\n".$toparse;
                        }
 
-                       if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData ;
+                       if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
+
+                       // Parse mediawiki messages with correct target language
+                       if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+                               $pos = strrpos( $this->mTitle->getText(), '/' );
+                               if ( $pos !== false ) {
+                                       $code = substr( $this->mTitle->getText(), $pos+1 );
+                                       switch ($code) {
+                                               case $wgLang->getCode():
+                                                       $obj = $wgLang; break;
+                                               case $wgContLang->getCode():
+                                                       $obj = $wgContLang; break;
+                                               default:
+                                                       $obj = Language::factory( $code );
+                                       }
+                                       $parserOptions->setTargetLanguage( $obj );
+                               }
+                       }
+
+
                        $parserOptions->setTidy(true);
                        $parserOptions->enableLimitReport();
                        $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ) ."\n\n",
index fde3351..acefb8d 100644 (file)
@@ -459,7 +459,13 @@ class Parser
 
        function getFunctionLang() {
                global $wgLang, $wgContLang;
-               return $this->mOptions->getInterfaceMessage() ? $wgLang : $wgContLang;
+
+               $target = $this->mOptions->getTargetLanguage();
+               if ( $target !== null ) {
+                       return $target;
+               } else {
+                       return $this->mOptions->getInterfaceMessage() ? $wgLang : $wgContLang;
+               }
        }
 
        /**
index 996bba2..7be42ab 100644 (file)
@@ -20,6 +20,7 @@ class ParserOptions
        var $mAllowSpecialInclusion;     # Allow inclusion of special pages
        var $mTidy;                      # Ask for tidy cleanup
        var $mInterfaceMessage;          # Which lang to call for PLURAL and GRAMMAR
+       var $mTargetLanguage;            # Overrides above setting with arbitrary language
        var $mMaxIncludeSize;            # Maximum size of template expansions, in bytes
        var $mMaxPPNodeCount;            # Maximum number of nodes touched by PPFrame::expand()
        var $mMaxTemplateDepth;          # Maximum recursion depth for templates within templates
@@ -40,6 +41,7 @@ class ParserOptions
        function getAllowSpecialInclusion()         { return $this->mAllowSpecialInclusion; }
        function getTidy()                          { return $this->mTidy; }
        function getInterfaceMessage()              { return $this->mInterfaceMessage; }
+       function getTargetLanguage()                { return $this->mTargetLanguage; }
        function getMaxIncludeSize()                { return $this->mMaxIncludeSize; }
        function getMaxPPNodeCount()                { return $this->mMaxPPNodeCount; }
        function getMaxTemplateDepth()              { return $this->mMaxTemplateDepth; }
@@ -80,6 +82,7 @@ class ParserOptions
        function setTidy( $x )                      { return wfSetVar( $this->mTidy, $x); }
        function setSkin( $x )                      { $this->mSkin = $x; }
        function setInterfaceMessage( $x )          { return wfSetVar( $this->mInterfaceMessage, $x); }
+       function setTargetLanguage( $x )            { return wfSetVar( $this->mTargetLanguage, $x); }
        function setMaxIncludeSize( $x )            { return wfSetVar( $this->mMaxIncludeSize, $x ); }
        function setMaxPPNodeCount( $x )            { return wfSetVar( $this->mMaxPPNodeCount, $x ); }
        function setMaxTemplateDepth( $x )          { return wfSetVar( $this->mMaxTemplateDepth, $x ); }
@@ -132,6 +135,7 @@ class ParserOptions
                $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
                $this->mTidy = false;
                $this->mInterfaceMessage = false;
+               $this->mTargetLanguage = null; // default depends on InterfaceMessage setting
                $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
                $this->mMaxPPNodeCount = $wgMaxPPNodeCount;
                $this->mMaxTemplateDepth = $wgMaxTemplateDepth;