Address comment by Platonides on r90320:
authorRobin Pepermans <robin@users.mediawiki.org>
Sat, 18 Jun 2011 14:49:01 +0000 (14:49 +0000)
committerRobin Pepermans <robin@users.mediawiki.org>
Sat, 18 Jun 2011 14:49:01 +0000 (14:49 +0000)
* undefined variable $list in CategoryPage.php
* move code in ParserOptions to a new member of Title class, which falls back to $wgContLang

includes/CategoryPage.php
includes/EditPage.php
includes/SkinTemplate.php
includes/Title.php
includes/diff/DifferenceEngine.php
includes/parser/ParserOptions.php

index 4b8ba03..989e9e9 100644 (file)
@@ -506,19 +506,18 @@ class CategoryViewer {
         * @private
         */
        function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
+               $list = '';
                if ( count ( $articles ) > $cutoff ) {
                        $list = self::columnList( $articles, $articles_start_char );
                } elseif ( count( $articles ) > 0 ) {
                        // for short lists of articles in categories.
                        $list = self::shortList( $articles, $articles_start_char );
                }
-               global $wgBetterDirectionality;
+               global $wgBetterDirectionality, $wgTitle;
                if( $wgBetterDirectionality ) {
-                       global $wgOut, $wgContLang;
-                       $getPageLang = $wgOut->parserOptions()->getTargetLanguage();
-                       $pageLang = ( $getPageLang ? Language::factory( $getPageLang ) : $wgContLang );
-                       $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
-                       $list = Html::rawElement( 'div', $realBodyAttribs, $list );
+                       $pageLang = $wgTitle->getPageLanguage();
+                       $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
+                       $list = Html::rawElement( 'div', $attribs, $list );
                }
 
                return $list;
index ce69695..7dc1c0a 100644 (file)
@@ -1817,8 +1817,7 @@ HTML
 
                global $wgBetterDirectionality, $wgContLang;
                if( $wgBetterDirectionality ) {
-                       $getPageLang = $wgOut->parserOptions()->getTargetLanguage( $this->mTitle );
-                       $pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
+                       $pageLang = $this->mTitle->getPageLanguage();
                        $attribs['lang'] = $pageLang->getCode();
                        $attribs['dir'] = $pageLang->getDir();
                }
@@ -2066,6 +2065,12 @@ HTML
 
                                wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
 
+                               // In which language to parse the page
+                               // (Should this still be only for MediaWiki pages, or for all pages?)
+                               if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+                                       $parserOptions->setTargetLanguage( $this->mTitle->getPageLanguage() );
+                               }
+                               $parserOptions->setTargetLanguage( $this->mTitle->getPageLanguage() );
                                $parserOptions->setTidy( true );
                                $parserOptions->enableLimitReport();
                                $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
@@ -2091,12 +2096,11 @@ HTML
                        '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
                        $wgOut->parse( $note ) . $conflict . "</div>\n";
 
-               global $wgBetterDirectionality, $wgContLang;
+               global $wgBetterDirectionality;
                if( $wgBetterDirectionality ) {
-                       $getPageLang = $wgOut->parserOptions()->getTargetLanguage( $this->mTitle );
-                       $pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
-                       $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
-                       $previewHTML = Html::rawElement( 'div', $realBodyAttribs, $previewHTML );
+                       $pageLang = $this->mTitle->getPageLanguage();
+                       $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
+                       $previewHTML = Html::rawElement( 'div', $attribs, $previewHTML );
                }
                wfProfileOut( __METHOD__ );
                return $previewhead . $previewHTML . $this->previewTextAfterContent;
index fad14f5..2287bc6 100644 (file)
@@ -461,8 +461,7 @@ class SkinTemplate extends Skin {
                        if( $this->getTitle()->getNamespace() != NS_SPECIAL &&
                                in_array( $action, array( 'view', 'render', 'print' ) ) &&
                                ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) {
-                               $getPageLang = $out->parserOptions()->getTargetLanguage( $this->getTitle() );
-                               $pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
+                               $pageLang = $this->getTitle()->getPageLanguage();
                                $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
                                $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
                        }
index d06b322..1ec8454 100644 (file)
@@ -67,6 +67,7 @@ class Title {
        var $mRedirect = null;            // /< Is the article at this title a redirect?
        var $mNotificationTimestamp = array(); // /< Associative array of user ID -> timestamp/false
        var $mBacklinkCache = null;       // /< Cache of links to this title
+       var $mPageLanguage;
        // @}
 
 
@@ -4221,6 +4222,26 @@ class Title {
                }
                return $unprefixed;
        }
+
+       /**
+        * Get the language this page is written in
+        * Defaults to $wgContLang
+        *
+        * @return object Language
+        */
+       public function getPageLanguage() {
+               global $wgContLang;
+               $this->mPageLanguage = $wgContLang;
+               if ( $this->isCssOrJsPage() ) {
+                       // css/js should always be LTR and is, in fact, English
+                       $this->mPageLanguage = Language::factory( 'en' );
+               } elseif ( $this->getNamespace() == NS_MEDIAWIKI ) {
+                       // Parse mediawiki messages with correct target language
+                       list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->getText() );
+                       $this->mPageLanguage = wfGetLangObj( $lang );
+               }
+               return $this->mPageLanguage;
+       }
 }
 
 /**
index 0306e79..69d8994 100644 (file)
@@ -936,14 +936,12 @@ CONTROL;
         * @return string
         */
        static function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
-               global $wgBetterDirectionality;
+               global $wgBetterDirectionality, $wgTitle;
                $dirclass = '';
                if( $wgBetterDirectionality ) {
-                       global $wgContLang, $wgOut, $wgTitle;
                        // shared.css sets diff in interface language/dir,
                        // but the actual content should be in the page language/dir
-                       $getPageLang = $wgOut->parserOptions()->getTargetLanguage( $wgTitle );
-                       $pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
+                       $pageLang = $wgTitle->getPageLanguage();
                        $dirclass = ' diff-contentalign-'.$pageLang->alignStart();
                }
                $header = "<table class='diff $dirclass'>";
index 49473ca..3b9b2d7 100644 (file)
@@ -66,17 +66,7 @@ class ParserOptions {
        function getAllowSpecialInclusion()         { return $this->mAllowSpecialInclusion; }
        function getTidy()                          { return $this->mTidy; }
        function getInterfaceMessage()              { return $this->mInterfaceMessage; }
-       function getTargetLanguage( $title = null ) {
-               if ( $title && $title->isCssOrJsPage() ) {
-                       return Language::factory( 'en' ); // css/js should always be LTR
-               } elseif ( $title && $title->getNamespace() == NS_MEDIAWIKI ) {
-                       // Parse mediawiki messages with correct target language
-                       list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() );
-                       $obj = wfGetLangObj( $lang );
-                       return $obj;
-               }
-       return $this->mTargetLanguage;
-}
+       function getTargetLanguage()                { return $this->mTargetLanguage; }
        function getMaxIncludeSize()                { return $this->mMaxIncludeSize; }
        function getMaxPPNodeCount()                { return $this->mMaxPPNodeCount; }
        function getMaxPPExpandDepth()              { return $this->mMaxPPExpandDepth; }