https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113001

Revision: 113001
Author:   tstarling
Date:     2012-03-05 05:53:12 +0000 (Mon, 05 Mar 2012)
Log Message:
-----------
* Fix for r41340, r96405, r97849: introduce a function which gets the current 
content language, called Parser::getTargetLanguage() following the 
ParserOptions terminology, and added doc comments, to improve the chances of a 
human being able to work out what is going on. Just because a function happens 
to do the thing you want doesn't mean you should call it. 
* The language object used for lc() in Parser::braceSubstitution() must match 
the one used in setFunctionHook() during firstCallInit(). It can't change 
depending on what message you are parsing. Use $wgContLang like before r97849.

Modified Paths:
--------------
    trunk/phase3/includes/parser/Parser.php

Modified: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php     2012-03-05 05:41:01 UTC (rev 
113000)
+++ trunk/phase3/includes/parser/Parser.php     2012-03-05 05:53:12 UTC (rev 
113001)
@@ -376,7 +376,7 @@
                        # The position of the convert() call should not be 
changed. it
                        # assumes that the links are all replaced and the only 
thing left
                        # is the <nowiki> mark.
-                       $text = $this->getFunctionLang()->convert( $text );
+                       $text = $this->getTargetLanguage()->convert( $text );
                }
 
                /**
@@ -392,11 +392,11 @@
                                || isset( 
$this->mDoubleUnderscores['notitleconvert'] )
                                || $this->mOutput->getDisplayTitle() !== false 
) )
                {
-                       $convruletitle = 
$this->getFunctionLang()->getConvRuleTitle();
+                       $convruletitle = 
$this->getTargetLanguage()->getConvRuleTitle();
                        if ( $convruletitle ) {
                                $this->mOutput->setTitleText( $convruletitle );
                        } else {
-                               $titleText = 
$this->getFunctionLang()->convertTitle( $title );
+                               $titleText = 
$this->getTargetLanguage()->convertTitle( $title );
                                $this->mOutput->setTitleText( $titleText );
                        }
                }
@@ -693,9 +693,18 @@
        }
 
        /**
+        * Get a language object for use in parser functions such as 
{{FORMATNUM:}}
         * @return Language
         */
        function getFunctionLang() {
+               return $this->getTargetLanguage();
+       }
+
+       /**
+        * Get the target language for the content being parsed. This is 
usually the 
+        * language that the content is in. 
+        */
+       function getTargetLanguage() {
                $target = $this->mOptions->getTargetLanguage();
                if ( $target !== null ) {
                        return $target;
@@ -1227,7 +1236,8 @@
                $text = $this->maybeMakeExternalImage( $url );
                if ( $text === false ) {
                        # Not an image, make a link
-                       $text = Linker::makeExternalLink( $url, 
$this->getFunctionLang()->markNoConversion($url), true, 'free',
+                       $text = Linker::makeExternalLink( $url, 
+                               
$this->getTargetLanguage()->markNoConversion($url), true, 'free',
                                $this->getExternalLinkAttribs( $url ) );
                        # Register it in the output object...
                        # Replace unnecessary URL escape codes with their 
equivalent characters
@@ -1491,7 +1501,7 @@
                        # No link text, e.g. [http://domain.tld/some.link]
                        if ( $text == '' ) {
                                # Autonumber
-                               $langObj = $this->getFunctionLang();
+                               $langObj = $this->getTargetLanguage();
                                $text = '[' . $langObj->formatNum( 
++$this->mAutonumber ) . ']';
                                $linktype = 'autonumber';
                        } else {
@@ -1500,7 +1510,7 @@
                                list( $dtrail, $trail ) = Linker::splitTrail( 
$trail );
                        }
 
-                       $text = $this->getFunctionLang()->markNoConversion( 
$text );
+                       $text = $this->getTargetLanguage()->markNoConversion( 
$text );
 
                        $url = Sanitizer::cleanUrl( $url );
 
@@ -1680,7 +1690,7 @@
                $line = $a->current(); # Workaround for broken 
ArrayIterator::next() that returns "void"
                $s = substr( $s, 1 );
 
-               $useLinkPrefixExtension = 
$this->getFunctionLang()->linkPrefixExtension();
+               $useLinkPrefixExtension = 
$this->getTargetLanguage()->linkPrefixExtension();
                $e2 = null;
                if ( $useLinkPrefixExtension ) {
                        # Match the end of a line for a word that's not 
followed by whitespace,
@@ -1706,8 +1716,9 @@
                        $prefix = '';
                }
 
-               if ( $this->getFunctionLang()->hasVariants() ) {
-                       $selflink = 
$this->getFunctionLang()->autoConvertToAllVariants( 
$this->mTitle->getPrefixedText() );
+               if ( $this->getTargetLanguage()->hasVariants() ) {
+                       $selflink = 
$this->getTargetLanguage()->autoConvertToAllVariants( 
+                               $this->mTitle->getPrefixedText() );
                } else {
                        $selflink = array( $this->mTitle->getPrefixedText() );
                }
@@ -1925,7 +1936,7 @@
                                        }
                                        $sortkey = 
Sanitizer::decodeCharReferences( $sortkey );
                                        $sortkey = str_replace( "\n", '', 
$sortkey );
-                                       $sortkey = 
$this->getFunctionLang()->convertCategoryKey( $sortkey );
+                                       $sortkey = 
$this->getTargetLanguage()->convertCategoryKey( $sortkey );
                                        $this->mOutput->addCategory( 
$nt->getDBkey(), $sortkey );
 
                                        /**
@@ -3024,7 +3035,7 @@
         * @private
         */
        function braceSubstitution( $piece, $frame ) {
-               global $wgNonincludableNamespaces;
+               global $wgNonincludableNamespaces, $wgContLang;
                wfProfileIn( __METHOD__ );
                wfProfileIn( __METHOD__.'-setup' );
 
@@ -3127,7 +3138,7 @@
                                        $function = 
$this->mFunctionSynonyms[1][$function];
                                } else {
                                        # Case insensitive functions
-                                       $function = 
$this->getFunctionLang()->lc( $function );
+                                       $function = $wgContLang->lc( $function 
);
                                        if ( isset( 
$this->mFunctionSynonyms[0][$function] ) ) {
                                                $function = 
$this->mFunctionSynonyms[0][$function];
                                        } else {
@@ -3203,8 +3214,8 @@
                        if ( $title ) {
                                $titleText = $title->getPrefixedText();
                                # Check for language variants if the template 
is not found
-                               if ( $this->getFunctionLang()->hasVariants() && 
$title->getArticleID() == 0 ) {
-                                       
$this->getFunctionLang()->findVariantLink( $part1, $title, true );
+                               if ( $this->getTargetLanguage()->hasVariants() 
&& $title->getArticleID() == 0 ) {
+                                       
$this->getTargetLanguage()->findVariantLink( $part1, $title, true );
                                }
                                # Do recursion depth check
                                $limit = $this->mOptions->getMaxTemplateDepth();
@@ -4036,7 +4047,7 @@
                                        if ( $dot ) {
                                                $numbering .= '.';
                                        }
-                                       $numbering .= 
$this->getFunctionLang()->formatNum( $sublevelCount[$i] );
+                                       $numbering .= 
$this->getTargetLanguage()->formatNum( $sublevelCount[$i] );
                                        $dot = 1;
                                }
                        }


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to