r97047 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97046‎ | r97047 | r97048 >
Date:11:23, 14 September 2011
Author:nikerabbit
Status:ok (Comments)
Tags:
Comment:
Revert r96798 - makes parser go infinite loop somewhere
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SkinLegacy.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserCache.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -59,8 +59,6 @@
6060 * Conversion script between Tifinagh and Latin for the Tachelhit language
6161 * (bug 16755) Add options 'noreplace' and 'noerror' to {{DEFAULTSORT:...}}
6262 to stop it from replace an already existing default sort, and suppress error.
63 -* (bug 30364) LanguageConverter now depends on the page content language
64 - instead of the wiki content language
6563 * (bug 18578) Rewrote revision delete related messages to allow better
6664 localisation
6765
Index: trunk/phase3/languages/LanguageConverter.php
@@ -158,7 +158,7 @@
159159 // not memoized (i.e. there return value is not cached) since
160160 // new information might appear during processing after this
161161 // is first called.
162 - if ( $req = $this->validateVariant( $req ) ) {
 162+ if ( $req ) {
163163 return $req;
164164 }
165165 return $this->mMainLanguageCode;
Index: trunk/phase3/includes/WikiPage.php
@@ -2562,7 +2562,7 @@
25632563 * @return mixed ParserOptions object or boolean false
25642564 */
25652565 public function getParserOptions( $canonical = false ) {
2566 - global $wgUser;
 2566+ global $wgUser, $wgLanguageCode;
25672567
25682568 if ( !$this->mParserOptions || $canonical ) {
25692569 $user = !$canonical ? $wgUser : new User;
@@ -2571,7 +2571,7 @@
25722572 $parserOptions->enableLimitReport();
25732573
25742574 if ( $canonical ) {
2575 - $parserOptions->setUserLang( $this->mTitle->getPageLanguage() ); # Must be set explicitely
 2575+ $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely
25762576 return $parserOptions;
25772577 }
25782578 $this->mParserOptions = $parserOptions;
Index: trunk/phase3/includes/Article.php
@@ -1050,14 +1050,13 @@
10511051 * @return string containing HMTL with redirect link
10521052 */
10531053 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1054 - global $wgOut, $wgStylePath;
 1054+ global $wgOut, $wgLang, $wgStylePath;
10551055
10561056 if ( !is_array( $target ) ) {
10571057 $target = array( $target );
10581058 }
10591059
1060 - $lang = $this->getTitle()->getPageLanguage();
1061 - $imageDir = $lang->getDir();
 1060+ $imageDir = $wgLang->getDir();
10621061
10631062 if ( $appendSubtitle ) {
10641063 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
@@ -1073,7 +1072,7 @@
10741073 }
10751074
10761075 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1077 - $alt = $lang->isRTL() ? '←' : '→';
 1076+ $alt = $wgLang->isRTL() ? '←' : '→';
10781077 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
10791078 foreach ( $target as $rt ) {
10801079 $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
Index: trunk/phase3/includes/parser/ParserCache.php
@@ -80,7 +80,7 @@
8181 */
8282 function getETag( $article, $popts ) {
8383 return 'W/"' . $this->getParserOutputKey( $article,
84 - $popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) ) .
 84+ $popts->optionsHash( ParserOptions::legacyOptions() ) ) .
8585 "--" . $article->getTouched() . '"';
8686 }
8787
@@ -130,7 +130,7 @@
131131 $usedOptions = ParserOptions::legacyOptions();
132132 }
133133
134 - return $this->getParserOutputKey( $article, $popts->optionsHash( $usedOptions, $article->getTitle() ) );
 134+ return $this->getParserOutputKey( $article, $popts->optionsHash( $usedOptions ) );
135135 }
136136
137137 /**
@@ -165,8 +165,7 @@
166166 $value = $this->mMemc->get( $parserOutputKey );
167167 if ( self::try116cache && !$value && strpos( $value, '*' ) !== -1 ) {
168168 wfDebug( "New format parser cache miss.\n" );
169 - $parserOutputKey = $this->getParserOutputKey( $article,
170 - $popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) );
 169+ $parserOutputKey = $this->getParserOutputKey( $article, $popts->optionsHash( ParserOptions::legacyOptions() ) );
171170 $value = $this->mMemc->get( $parserOutputKey );
172171 }
173172 if ( !$value ) {
@@ -212,7 +211,7 @@
213212 $optionsKey->setContainsOldMagic( $parserOutput->containsOldMagic() );
214213
215214 $parserOutputKey = $this->getParserOutputKey( $article,
216 - $popts->optionsHash( $optionsKey->mUsedOptions, $article->getTitle() ) );
 215+ $popts->optionsHash( $optionsKey->mUsedOptions ) );
217216
218217 // Save the timestamp so that we don't have to load the revision row on view
219218 $parserOutput->mTimestamp = $article->getTimestamp();
Index: trunk/phase3/includes/parser/Parser.php
@@ -321,7 +321,7 @@
322322 * to internalParse() which does all the real work.
323323 */
324324
325 - global $wgUseTidy, $wgAlwaysUseTidy, $wgDisableLangConversion, $wgDisableTitleConversion;
 325+ global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
326326 $fname = __METHOD__.'-' . wfGetCaller();
327327 wfProfileIn( __METHOD__ );
328328 wfProfileIn( $fname );
@@ -376,7 +376,8 @@
377377 # The position of the convert() call should not be changed. it
378378 # assumes that the links are all replaced and the only thing left
379379 # is the <nowiki> mark.
380 - $text = $this->getFunctionLang()->convert( $text );
 380+
 381+ $text = $wgContLang->convert( $text );
381382 }
382383
383384 /**
@@ -392,11 +393,11 @@
393394 || isset( $this->mDoubleUnderscores['notitleconvert'] )
394395 || $this->mOutput->getDisplayTitle() !== false ) )
395396 {
396 - $convruletitle = $this->getFunctionLang()->getConvRuleTitle();
 397+ $convruletitle = $wgContLang->getConvRuleTitle();
397398 if ( $convruletitle ) {
398399 $this->mOutput->setTitleText( $convruletitle );
399400 } else {
400 - $titleText = $this->getFunctionLang()->convertTitle( $title );
 401+ $titleText = $wgContLang->convertTitle( $title );
401402 $this->mOutput->setTitleText( $titleText );
402403 }
403404 }
@@ -1316,6 +1317,7 @@
13171318 * @private
13181319 */
13191320 function makeFreeExternalLink( $url ) {
 1321+ global $wgContLang;
13201322 wfProfileIn( __METHOD__ );
13211323
13221324 $trail = '';
@@ -1348,7 +1350,7 @@
13491351 $text = $this->maybeMakeExternalImage( $url );
13501352 if ( $text === false ) {
13511353 # Not an image, make a link
1352 - $text = Linker::makeExternalLink( $url, $this->getFunctionLang()->markNoConversion($url), true, 'free',
 1354+ $text = Linker::makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
13531355 $this->getExternalLinkAttribs( $url ) );
13541356 # Register it in the output object...
13551357 # Replace unnecessary URL escape codes with their equivalent characters
@@ -1576,6 +1578,7 @@
15771579 * @return string
15781580 */
15791581 function replaceExternalLinks( $text ) {
 1582+ global $wgContLang;
15801583 wfProfileIn( __METHOD__ );
15811584
15821585 $bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
@@ -1621,7 +1624,7 @@
16221625 list( $dtrail, $trail ) = Linker::splitTrail( $trail );
16231626 }
16241627
1625 - $text = $this->getFunctionLang()->markNoConversion( $text );
 1628+ $text = $wgContLang->markNoConversion( $text );
16261629
16271630 $url = Sanitizer::cleanUrl( $url );
16281631
@@ -1778,6 +1781,8 @@
17791782 * @private
17801783 */
17811784 function replaceInternalLinks2( &$s ) {
 1785+ global $wgContLang;
 1786+
17821787 wfProfileIn( __METHOD__ );
17831788
17841789 wfProfileIn( __METHOD__.'-setup' );
@@ -1801,7 +1806,7 @@
18021807 $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
18031808 $s = substr( $s, 1 );
18041809
1805 - $useLinkPrefixExtension = $this->getFunctionLang()->linkPrefixExtension();
 1810+ $useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
18061811 $e2 = null;
18071812 if ( $useLinkPrefixExtension ) {
18081813 # Match the end of a line for a word that's not followed by whitespace,
@@ -1827,8 +1832,8 @@
18281833 $prefix = '';
18291834 }
18301835
1831 - if ( $this->getFunctionLang()->hasVariants() ) {
1832 - $selflink = $this->getFunctionLang()->autoConvertToAllVariants( $this->mTitle->getPrefixedText() );
 1836+ if ( $wgContLang->hasVariants() ) {
 1837+ $selflink = $wgContLang->autoConvertToAllVariants( $this->mTitle->getPrefixedText() );
18331838 } else {
18341839 $selflink = array( $this->mTitle->getPrefixedText() );
18351840 }
@@ -1996,7 +2001,6 @@
19972002
19982003 # Link not escaped by : , create the various objects
19992004 if ( $noforce ) {
2000 - global $wgContLang;
20012005
20022006 # Interwikis
20032007 wfProfileIn( __METHOD__."-interwiki" );
@@ -2046,7 +2050,7 @@
20472051 }
20482052 $sortkey = Sanitizer::decodeCharReferences( $sortkey );
20492053 $sortkey = str_replace( "\n", '', $sortkey );
2050 - $sortkey = $this->getFunctionLang()->convertCategoryKey( $sortkey );
 2054+ $sortkey = $wgContLang->convertCategoryKey( $sortkey );
20512055 $this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
20522056
20532057 /**
@@ -3248,7 +3252,7 @@
32493253 $function = $this->mFunctionSynonyms[1][$function];
32503254 } else {
32513255 # Case insensitive functions
3252 - $function = $this->getFunctionLang()->lc( $function );
 3256+ $function = $wgContLang->lc( $function );
32533257 if ( isset( $this->mFunctionSynonyms[0][$function] ) ) {
32543258 $function = $this->mFunctionSynonyms[0][$function];
32553259 } else {
@@ -3324,8 +3328,8 @@
33253329 }
33263330 $titleText = $title->getPrefixedText();
33273331 # Check for language variants if the template is not found
3328 - if ( $this->getFunctionLang()->hasVariants() && $title->getArticleID() == 0 ) {
3329 - $this->getFunctionLang()->findVariantLink( $part1, $title, true );
 3332+ if ( $wgContLang->hasVariants() && $title->getArticleID() == 0 ) {
 3333+ $wgContLang->findVariantLink( $part1, $title, true );
33303334 }
33313335 # Do recursion depth check
33323336 $limit = $this->mOptions->getMaxTemplateDepth();
Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -274,12 +274,10 @@
275275 * settings.
276276 *
277277 * @since 1.17
278 - * @param $forOptions Array
279 - * @param $title Title: used to get the content language of the page
280278 * @return \string Page rendering hash
281279 */
282 - public function optionsHash( $forOptions, $title = null ) {
283 - global $wgRenderHashAppend, $wgTitle;
 280+ public function optionsHash( $forOptions ) {
 281+ global $wgContLang, $wgRenderHashAppend;
284282
285283 $confstr = '';
286284
@@ -323,12 +321,7 @@
324322
325323 // add in language specific options, if any
326324 // @todo FIXME: This is just a way of retrieving the url/user preferred variant
327 - if( !is_null( $title ) ) {
328 - $confstr .= $title->getPageLanguage()->getExtraHashOptions();
329 - } else {
330 - global $wgContLang;
331 - $confstr .= $wgContLang->getExtraHashOptions();
332 - }
 325+ $confstr .= $wgContLang->getExtraHashOptions();
333326
334327 $confstr .= $wgRenderHashAppend;
335328
Index: trunk/phase3/includes/OutputPage.php
@@ -1654,12 +1654,12 @@
16551655 * /w/index.php?title=Main_page&variant=zh-cn should never be served.
16561656 */
16571657 function addAcceptLanguage() {
1658 - $lang = $this->getTitle()->getPageLanguage();
1659 - if( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
1660 - $variants = $lang->getVariants();
 1658+ global $wgContLang;
 1659+ if( !$this->getRequest()->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
 1660+ $variants = $wgContLang->getVariants();
16611661 $aloption = array();
16621662 foreach ( $variants as $variant ) {
1663 - if( $variant === $lang->getCode() ) {
 1663+ if( $variant === $wgContLang->getCode() ) {
16641664 continue;
16651665 } else {
16661666 $aloption[] = 'string-contains=' . $variant;
@@ -2614,7 +2614,7 @@
26152615 * have to be purged on configuration changes.
26162616 */
26172617 protected function getJSVars() {
2618 - global $wgUseAjax, $wgEnableMWSuggest;
 2618+ global $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
26192619
26202620 $title = $this->getTitle();
26212621 $ns = $title->getNamespace();
@@ -2640,9 +2640,8 @@
26412641 'wgCategories' => $this->getCategories(),
26422642 'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
26432643 );
2644 - $lang = $this->getTitle()->getPageLanguage();
2645 - if ( $lang->hasVariants() ) {
2646 - $vars['wgUserVariant'] = $lang->getPreferredVariant();
 2644+ if ( $wgContLang->hasVariants() ) {
 2645+ $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
26472646 }
26482647 foreach ( $title->getRestrictionTypes() as $type ) {
26492648 $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
@@ -2694,7 +2693,7 @@
26952694 global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
26962695 $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
26972696 $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
2698 - $wgDisableLangConversion, $wgCanonicalLanguageLinks,
 2697+ $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang,
26992698 $wgRightsPage, $wgRightsUrl;
27002699
27012700 $tags = array();
@@ -2820,16 +2819,14 @@
28212820 ) );
28222821 }
28232822
2824 - $lang = $this->getTitle()->getPageLanguage();
2825 -
28262823 # Language variants
28272824 if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
2828 - && $lang->hasVariants() ) {
 2825+ && $wgContLang->hasVariants() ) {
28292826
2830 - $urlvar = $lang->getURLVariant();
 2827+ $urlvar = $wgContLang->getURLVariant();
28312828
28322829 if ( !$urlvar ) {
2833 - $variants = $lang->getVariants();
 2830+ $variants = $wgContLang->getVariants();
28342831 foreach ( $variants as $_v ) {
28352832 $tags[] = Html::element( 'link', array(
28362833 'rel' => 'alternate',
Index: trunk/phase3/includes/SkinTemplate.php
@@ -1012,21 +1012,16 @@
10131013 array( &$this, &$content_navigation ) );
10141014 }
10151015
1016 - $pageLang = $title->getPageLanguage();
1017 -
10181016 // Gets list of language variants
1019 - $variants = $pageLang->getVariants();
 1017+ $variants = $wgContLang->getVariants();
10201018 // Checks that language conversion is enabled and variants exist
1021 - // And if it is not in the special namespace
1022 - if( !$wgDisableLangConversion && count( $variants ) > 1
1023 - && $title->getNamespace() != NS_SPECIAL ) {
1024 - // Gets preferred variant (note that user preference is
1025 - // only possible for wiki content language variant)
1026 - $preferred = $pageLang->getPreferredVariant();
 1019+ if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
 1020+ // Gets preferred variant
 1021+ $preferred = $wgContLang->getPreferredVariant();
10271022 // Loops over each variant
10281023 foreach( $variants as $code ) {
10291024 // Gets variant name from language code
1030 - $varname = $pageLang->getVariantname( $code );
 1025+ $varname = $wgContLang->getVariantname( $code );
10311026 // Checks if the variant is marked as disabled
10321027 if( $varname == 'disable' ) {
10331028 // Skips this variant
Index: trunk/phase3/includes/SkinLegacy.php
@@ -279,14 +279,13 @@
280280 $s = '';
281281
282282 /* show links to different language variants */
283 - global $wgDisableLangConversion, $wgLang;
 283+ global $wgDisableLangConversion, $wgLang, $wgContLang;
284284
285 - $lang = $this->getSkin()->getTitle()->getPageLanguage();
286 - $variants = $lang->getVariants();
 285+ $variants = $wgContLang->getVariants();
287286
288287 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
289288 foreach ( $variants as $code ) {
290 - $varname = $lang->getVariantname( $code );
 289+ $varname = $wgContLang->getVariantname( $code );
291290
292291 if ( $varname == 'disable' ) {
293292 continue;
Index: trunk/phase3/includes/Title.php
@@ -877,7 +877,7 @@
878878 */
879879 public function getLocalURL( $query = '', $variant = false ) {
880880 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
881 - global $wgVariantArticlePath;
 881+ global $wgVariantArticlePath, $wgContLang;
882882
883883 if ( is_array( $query ) ) {
884884 $query = wfArrayToCGI( $query );
@@ -896,7 +896,7 @@
897897 } else {
898898 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
899899 if ( $query == '' ) {
900 - if ( $variant != false && $this->getPageLanguage()->hasVariants() ) {
 900+ if ( $variant != false && $wgContLang->hasVariants() ) {
901901 if ( !$wgVariantArticlePath ) {
902902 $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
903903 } else {
@@ -4384,6 +4384,9 @@
43854385 if ( $this->getNamespace() == NS_SPECIAL ) {
43864386 // special pages are in the user language
43874387 return $wgLang;
 4388+ } elseif ( $this->isRedirect() ) {
 4389+ // the arrow on a redirect page is aligned according to the user language
 4390+ return $wgLang;
43884391 } elseif ( $this->isCssOrJsPage() ) {
43894392 // css/js should always be LTR and is, in fact, English
43904393 return wfGetLangObj( 'en' );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96798(Bug 30364) LanguageConverter should depend on the page content language inst...robin17:56, 11 September 2011

Comments

#Comment by Platonides (talk | contribs)   17:32, 15 September 2011

Really? Do you have a test case?

#Comment by Nikerabbit (talk | contribs)   17:42, 15 September 2011

Yes, really. See comments on r97047. I can try to provide help if someone wants to dig into it.

#Comment by Nikerabbit (talk | contribs)   17:43, 15 September 2011

Meant r96798 of course.

Status & tagging log