r113119 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113118‎ | r113119 | r113120 >
Date:02:09, 6 March 2012
Author:tstarling
Status:ok
Tags:
Comment:
MFT r112872, r112873, r113001, r113024: language converter fixes
Modified paths:
  • /branches/wmf/1.19wmf1/includes/DefaultSettings.php (modified) (history)
  • /branches/wmf/1.19wmf1/includes/cache/MessageCache.php (modified) (history)
  • /branches/wmf/1.19wmf1/includes/parser/Parser.php (modified) (history)
  • /branches/wmf/1.19wmf1/includes/specials/SpecialRecentchanges.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/includes/parser/Parser.php
@@ -370,13 +370,16 @@
371371 */
372372 if ( !( $wgDisableLangConversion
373373 || isset( $this->mDoubleUnderscores['nocontentconvert'] )
374 - || $this->mTitle->isConversionTable()
375 - || $this->mOptions->getInterfaceMessage() ) ) {
376 -
377 - # The position of the convert() call should not be changed. it
378 - # assumes that the links are all replaced and the only thing left
379 - # is the <nowiki> mark.
380 - $text = $this->getFunctionLang()->convert( $text );
 374+ || $this->mTitle->isConversionTable() ) )
 375+ {
 376+ # Run convert unconditionally in 1.18-compatible mode
 377+ global $wgBug34832TransitionalRollback;
 378+ if ( $wgBug34832TransitionalRollback || !$this->mOptions->getInterfaceMessage() ) {
 379+ # The position of the convert() call should not be changed. it
 380+ # assumes that the links are all replaced and the only thing left
 381+ # is the <nowiki> mark.
 382+ $text = $this->getConverterLanguage()->convert( $text );
 383+ }
381384 }
382385
383386 /**
@@ -392,11 +395,11 @@
393396 || isset( $this->mDoubleUnderscores['notitleconvert'] )
394397 || $this->mOutput->getDisplayTitle() !== false ) )
395398 {
396 - $convruletitle = $this->getFunctionLang()->getConvRuleTitle();
 399+ $convruletitle = $this->getConverterLanguage()->getConvRuleTitle();
397400 if ( $convruletitle ) {
398401 $this->mOutput->setTitleText( $convruletitle );
399402 } else {
400 - $titleText = $this->getFunctionLang()->convertTitle( $title );
 403+ $titleText = $this->getConverterLanguage()->convertTitle( $title );
401404 $this->mOutput->setTitleText( $titleText );
402405 }
403406 }
@@ -692,9 +695,18 @@
693696 }
694697
695698 /**
 699+ * Get a language object for use in parser functions such as {{FORMATNUM:}}
696700 * @return Language
697701 */
698702 function getFunctionLang() {
 703+ return $this->getTargetLanguage();
 704+ }
 705+
 706+ /**
 707+ * Get the target language for the content being parsed. This is usually the
 708+ * language that the content is in.
 709+ */
 710+ function getTargetLanguage() {
699711 $target = $this->mOptions->getTargetLanguage();
700712 if ( $target !== null ) {
701713 return $target;
@@ -707,6 +719,18 @@
708720 }
709721
710722 /**
 723+ * Get the language object for language conversion
 724+ */
 725+ function getConverterLanguage() {
 726+ global $wgBug34832TransitionalRollback, $wgContLang;
 727+ if ( $wgBug34832TransitionalRollback ) {
 728+ return $wgContLang;
 729+ } else {
 730+ return $this->getTargetLanguage();
 731+ }
 732+ }
 733+
 734+ /**
711735 * Get a User object either from $this->mUser, if set, or from the
712736 * ParserOptions object otherwise
713737 *
@@ -1225,7 +1249,8 @@
12261250 $text = $this->maybeMakeExternalImage( $url );
12271251 if ( $text === false ) {
12281252 # Not an image, make a link
1229 - $text = Linker::makeExternalLink( $url, $this->getFunctionLang()->markNoConversion($url), true, 'free',
 1253+ $text = Linker::makeExternalLink( $url,
 1254+ $this->getConverterLanguage()->markNoConversion($url), true, 'free',
12301255 $this->getExternalLinkAttribs( $url ) );
12311256 # Register it in the output object...
12321257 # Replace unnecessary URL escape codes with their equivalent characters
@@ -1489,7 +1514,7 @@
14901515 # No link text, e.g. [http://domain.tld/some.link]
14911516 if ( $text == '' ) {
14921517 # Autonumber
1493 - $langObj = $this->getFunctionLang();
 1518+ $langObj = $this->getTargetLanguage();
14941519 $text = '[' . $langObj->formatNum( ++$this->mAutonumber ) . ']';
14951520 $linktype = 'autonumber';
14961521 } else {
@@ -1498,7 +1523,7 @@
14991524 list( $dtrail, $trail ) = Linker::splitTrail( $trail );
15001525 }
15011526
1502 - $text = $this->getFunctionLang()->markNoConversion( $text );
 1527+ $text = $this->getConverterLanguage()->markNoConversion( $text );
15031528
15041529 $url = Sanitizer::cleanUrl( $url );
15051530
@@ -1678,7 +1703,7 @@
16791704 $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
16801705 $s = substr( $s, 1 );
16811706
1682 - $useLinkPrefixExtension = $this->getFunctionLang()->linkPrefixExtension();
 1707+ $useLinkPrefixExtension = $this->getTargetLanguage()->linkPrefixExtension();
16831708 $e2 = null;
16841709 if ( $useLinkPrefixExtension ) {
16851710 # Match the end of a line for a word that's not followed by whitespace,
@@ -1704,8 +1729,9 @@
17051730 $prefix = '';
17061731 }
17071732
1708 - if ( $this->getFunctionLang()->hasVariants() ) {
1709 - $selflink = $this->getFunctionLang()->autoConvertToAllVariants( $this->mTitle->getPrefixedText() );
 1733+ if ( $this->getConverterLanguage()->hasVariants() ) {
 1734+ $selflink = $this->getConverterLanguage()->autoConvertToAllVariants(
 1735+ $this->mTitle->getPrefixedText() );
17101736 } else {
17111737 $selflink = array( $this->mTitle->getPrefixedText() );
17121738 }
@@ -1923,7 +1949,7 @@
19241950 }
19251951 $sortkey = Sanitizer::decodeCharReferences( $sortkey );
19261952 $sortkey = str_replace( "\n", '', $sortkey );
1927 - $sortkey = $this->getFunctionLang()->convertCategoryKey( $sortkey );
 1953+ $sortkey = $this->getConverterLanguage()->convertCategoryKey( $sortkey );
19281954 $this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
19291955
19301956 /**
@@ -3022,7 +3048,7 @@
30233049 * @private
30243050 */
30253051 function braceSubstitution( $piece, $frame ) {
3026 - global $wgNonincludableNamespaces;
 3052+ global $wgNonincludableNamespaces, $wgContLang;
30273053 wfProfileIn( __METHOD__ );
30283054 wfProfileIn( __METHOD__.'-setup' );
30293055
@@ -3125,7 +3151,7 @@
31263152 $function = $this->mFunctionSynonyms[1][$function];
31273153 } else {
31283154 # Case insensitive functions
3129 - $function = $this->getFunctionLang()->lc( $function );
 3155+ $function = $wgContLang->lc( $function );
31303156 if ( isset( $this->mFunctionSynonyms[0][$function] ) ) {
31313157 $function = $this->mFunctionSynonyms[0][$function];
31323158 } else {
@@ -3201,8 +3227,8 @@
32023228 if ( $title ) {
32033229 $titleText = $title->getPrefixedText();
32043230 # Check for language variants if the template is not found
3205 - if ( $this->getFunctionLang()->hasVariants() && $title->getArticleID() == 0 ) {
3206 - $this->getFunctionLang()->findVariantLink( $part1, $title, true );
 3231+ if ( $this->getConverterLanguage()->hasVariants() && $title->getArticleID() == 0 ) {
 3232+ $this->getConverterLanguage()->findVariantLink( $part1, $title, true );
32073233 }
32083234 # Do recursion depth check
32093235 $limit = $this->mOptions->getMaxTemplateDepth();
@@ -4033,7 +4059,7 @@
40344060 if ( $dot ) {
40354061 $numbering .= '.';
40364062 }
4037 - $numbering .= $this->getFunctionLang()->formatNum( $sublevelCount[$i] );
 4063+ $numbering .= $this->getTargetLanguage()->formatNum( $sublevelCount[$i] );
40384064 $dot = 1;
40394065 }
40404066 }
Index: branches/wmf/1.19wmf1/includes/cache/MessageCache.php
@@ -833,14 +833,9 @@
834834
835835 $parser = $this->getParser();
836836 $popts = $this->getParserOptions();
 837+ $popts->setInterfaceMessage( $interface );
 838+ $popts->setTargetLanguage( $language );
837839
838 - if ( $interface ) {
839 - $popts->setInterfaceMessage( true );
840 - }
841 - if ( $language !== null ) {
842 - $popts->setTargetLanguage( $language );
843 - }
844 -
845840 wfProfileIn( __METHOD__ );
846841 if ( !$title || !$title instanceof Title ) {
847842 global $wgTitle;
Property changes on: branches/wmf/1.19wmf1/includes/cache/MessageCache.php
___________________________________________________________________
Modified: svn:mergeinfo
848843 Merged /trunk/phase3/includes/cache/MessageCache.php:r112872-112873,113001,113024
Index: branches/wmf/1.19wmf1/includes/DefaultSettings.php
@@ -2177,6 +2177,17 @@
21782178 */
21792179 $wgLocalTZoffset = null;
21802180
 2181+/**
 2182+ * If set to true, this will roll back a few bug fixes introduced in 1.19,
 2183+ * emulating the 1.18 behaviour, to avoid introducing bug 34832. In 1.19,
 2184+ * language variant conversion is disabled in interface messages. Setting this
 2185+ * to true re-enables it.
 2186+ *
 2187+ * This variable should be removed (implicitly false) in 1.20 or earlier.
 2188+ */
 2189+$wgBug34832TransitionalRollback = true;
 2190+
 2191+
21812192 /** @} */ # End of language/charset settings
21822193
21832194 /*************************************************************************//**
Index: branches/wmf/1.19wmf1/includes/specials/SpecialRecentchanges.php
@@ -633,10 +633,13 @@
634634 function setTopText( FormOptions $opts ) {
635635 global $wgContLang;
636636 $this->getOutput()->addWikiText(
637 - Html::rawElement( 'p',
638 - array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
639 - "\n" . wfMsgForContentNoTrans( 'recentchangestext' ) . "\n"
640 - ), false );
 637+ Html::rawElement( 'p',
 638+ array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
 639+ "\n" . wfMsgForContentNoTrans( 'recentchangestext' ) . "\n"
 640+ ),
 641+ /* $lineStart */ false,
 642+ /* $interface */ false
 643+ );
641644 }
642645
643646 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r112872Fix for r86304: if MessageCache::parse() is called twice, once with $interfac...tstarling04:00, 2 March 2012
r112873(bug 34832) Parse recentchangestext with the interface option off, since it c...tstarling04:52, 2 March 2012
r113001* Fix for r41340, r96405, r97849: introduce a function which gets the current...tstarling05:53, 5 March 2012
r113024Transitional patch for bug 34832: introduce a CI-style option to allow deploy...tstarling12:14, 5 March 2012

Status & tagging log