From 7df3473cfea59df53debb7a9eefffed8a7f20fb3 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 5 Mar 2012 05:53:12 +0000 Subject: [PATCH] * 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. --- includes/parser/Parser.php | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index d308456599..7d60ae7516 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -376,7 +376,7 @@ class Parser { # 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 mark. - $text = $this->getFunctionLang()->convert( $text ); + $text = $this->getTargetLanguage()->convert( $text ); } /** @@ -392,11 +392,11 @@ class Parser { || 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 @@ class Parser { } /** + * 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 @@ class Parser { $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 @@ class Parser { # 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 @@ class Parser { list( $dtrail, $trail ) = Linker::splitTrail( $trail ); } - $text = $this->getFunctionLang()->markNoConversion( $text ); + $text = $this->getTargetLanguage()->markNoConversion( $text ); $url = Sanitizer::cleanUrl( $url ); @@ -1680,7 +1690,7 @@ class Parser { $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 @@ class Parser { $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 @@ class Parser { } $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 @@ class Parser { * @private */ function braceSubstitution( $piece, $frame ) { - global $wgNonincludableNamespaces; + global $wgNonincludableNamespaces, $wgContLang; wfProfileIn( __METHOD__ ); wfProfileIn( __METHOD__.'-setup' ); @@ -3127,7 +3138,7 @@ class Parser { $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 @@ class Parser { 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 @@ class Parser { if ( $dot ) { $numbering .= '.'; } - $numbering .= $this->getFunctionLang()->formatNum( $sublevelCount[$i] ); + $numbering .= $this->getTargetLanguage()->formatNum( $sublevelCount[$i] ); $dot = 1; } } -- 2.20.1