Fixed inappropriate access of $wgTitle from LanguageConverter.php.
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 1 Mar 2006 01:57:53 +0000 (01:57 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 1 Mar 2006 01:57:53 +0000 (01:57 +0000)
includes/Parser.php
languages/Language.php
languages/LanguageConverter.php

index 3cc201d..b3f13aa 100644 (file)
@@ -73,7 +73,7 @@ define( 'EXT_IMAGE_REGEX',
  *   performs brace substitution on MediaWiki messages
  *
  * Globals used:
- *    objects:   $wgLang
+ *    objects:   $wgLang, $wgContLang
  *
  * NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
  *
@@ -236,17 +236,11 @@ class Parser
 
                $this->replaceLinkHolders( $text );
 
-               # the position of the convert() call should not be changed. it
+               # the position of the parserConvert() call should not be changed. it
                # assumes that the links are all replaced and the only thing left
                # is the <nowiki> mark.
-               $text = $wgContLang->convert($text);
-
-               # FIXME: Unexpected data flow
-               # Set the title text in mOutput to a converted version of the global 
-               # title. The title is stored in $wgContLang from a previous call to 
-               # OutputPage::setPageTitle(). If no call has been made, this will be 
-               # blank, a condition which Parser callers are expected to ignore.
-               $this->mOutput->setTitleText($wgContLang->getParsedTitle());
+               # Side-effects: this calls $this->mOutput->setTitleText()
+               $text = $wgContLang->parserConvert( $text, $this );
 
                $text = $this->unstripNoWiki( $text, $this->mStripState );
 
index 96753f0..f152146 100644 (file)
@@ -271,6 +271,7 @@ class fakeConverter {
        var $mLang;
        function fakeConverter($langobj) {$this->mLang = $langobj;}
        function convert($t, $i) {return $t;}
+       function parserConvert($t, $p) {return $t;}
        function getVariants() { return array( $this->mLang->getCode() ); }
        function getPreferredVariant() {return $this->mLang->getCode(); }
        function findVariantLink(&$l, &$n) {}
@@ -1034,6 +1035,11 @@ class Language {
                return $this->mConverter->convert($text, $isTitle);
        }
 
+       # Convert text from within Parser
+       function parserConvert( $text, &$parser ) {
+               return $this->mConverter->parserConvert( $text, $parser );
+       }
+
        /**
         * Perform output conversion on a string, and encode for safe HTML output.
         * @param string $text
index 1992d7e..38cb3dc 100644 (file)
@@ -182,6 +182,26 @@ class LanguageConverter {
                return $ret;
        }
 
+       /**
+        * Convert text using a parser object for context
+        */
+       function parserConvert( $text, &$parser ) {
+               global $wgDisableLangConversion;
+               /* don't do anything if this is the conversion table */
+               if ( $parser->mTitle->getNamespace() == NS_MEDIAWIKI &&
+                       strpos($parser->mTitle->getText, "Conversiontable") !== false ) 
+               {
+                       return $text;
+               }
+
+               if($wgDisableLangConversion)
+                       return $text;
+
+               $text = $this->convert( $text );
+               $parser->mOutput->setTitleText( $this->mTitleDisplay );
+               return $text;
+       }
+
        /**
         * convert text to different variants of a language. the automatic
         * conversion is done in autoConvert(). here we parse the text
@@ -198,17 +218,6 @@ class LanguageConverter {
      * @access public
      */
        function convert( $text , $isTitle=false) {
-               global $wgDisableLangConversion;
-               global $wgTitle;
-
-               /* don't do anything if this is the conversion table */
-               if($wgTitle->getNamespace() == NS_MEDIAWIKI &&
-                  strpos($wgTitle->getText(), "Conversiontable")!==false)
-                       return $text;
-
-               if($wgDisableLangConversion)
-                       return $text;
-
                $mw =& MagicWord::get( MAG_NOTITLECONVERT );
                if( $mw->matchAndRemove( $text ) )
                        $this->mDoTitleConvert = false;