From c48b41201acd7c97ee3fd0cc5b6c8cdfe7a4c57c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Wed, 14 Sep 2011 11:23:58 +0000 Subject: [PATCH] Revert r96798 - makes parser go infinite loop somewhere --- RELEASE-NOTES-1.19 | 2 -- includes/Article.php | 7 +++---- includes/OutputPage.php | 25 +++++++++++------------- includes/SkinLegacy.php | 7 +++---- includes/SkinTemplate.php | 15 +++++---------- includes/Title.php | 7 +++++-- includes/WikiPage.php | 4 ++-- includes/parser/Parser.php | 32 +++++++++++++++++-------------- includes/parser/ParserCache.php | 9 ++++----- includes/parser/ParserOptions.php | 13 +++---------- languages/LanguageConverter.php | 2 +- 11 files changed, 55 insertions(+), 68 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 144e87984b..b3a0b86fa2 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -59,8 +59,6 @@ production. * Conversion script between Tifinagh and Latin for the Tachelhit language * (bug 16755) Add options 'noreplace' and 'noerror' to {{DEFAULTSORT:...}} to stop it from replace an already existing default sort, and suppress error. -* (bug 30364) LanguageConverter now depends on the page content language - instead of the wiki content language * (bug 18578) Rewrote revision delete related messages to allow better localisation diff --git a/includes/Article.php b/includes/Article.php index 120e21d038..e453b37a69 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1050,14 +1050,13 @@ class Article extends Page { * @return string containing HMTL with redirect link */ public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) { - global $wgOut, $wgStylePath; + global $wgOut, $wgLang, $wgStylePath; if ( !is_array( $target ) ) { $target = array( $target ); } - $lang = $this->getTitle()->getPageLanguage(); - $imageDir = $lang->getDir(); + $imageDir = $wgLang->getDir(); if ( $appendSubtitle ) { $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) ); @@ -1073,7 +1072,7 @@ class Article extends Page { } $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png'; - $alt = $lang->isRTL() ? '←' : '→'; + $alt = $wgLang->isRTL() ? '←' : '→'; // Automatically append redirect=no to each link, since most of them are redirect pages themselves. foreach ( $target as $rt ) { $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 7d0a552eb4..2c05a49e58 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1654,12 +1654,12 @@ class OutputPage extends ContextSource { * /w/index.php?title=Main_page&variant=zh-cn should never be served. */ function addAcceptLanguage() { - $lang = $this->getTitle()->getPageLanguage(); - if( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) { - $variants = $lang->getVariants(); + global $wgContLang; + if( !$this->getRequest()->getCheck( 'variant' ) && $wgContLang->hasVariants() ) { + $variants = $wgContLang->getVariants(); $aloption = array(); foreach ( $variants as $variant ) { - if( $variant === $lang->getCode() ) { + if( $variant === $wgContLang->getCode() ) { continue; } else { $aloption[] = 'string-contains=' . $variant; @@ -2614,7 +2614,7 @@ $distantTemplates * have to be purged on configuration changes. */ protected function getJSVars() { - global $wgUseAjax, $wgEnableMWSuggest; + global $wgUseAjax, $wgEnableMWSuggest, $wgContLang; $title = $this->getTitle(); $ns = $title->getNamespace(); @@ -2640,9 +2640,8 @@ $distantTemplates 'wgCategories' => $this->getCategories(), 'wgBreakFrames' => $this->getFrameOptions() == 'DENY', ); - $lang = $this->getTitle()->getPageLanguage(); - if ( $lang->hasVariants() ) { - $vars['wgUserVariant'] = $lang->getPreferredVariant(); + if ( $wgContLang->hasVariants() ) { + $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); } foreach ( $title->getRestrictionTypes() as $type ) { $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type ); @@ -2694,7 +2693,7 @@ $distantTemplates global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI, $wgSitename, $wgVersion, $wgHtml5, $wgMimeType, $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes, - $wgDisableLangConversion, $wgCanonicalLanguageLinks, + $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang, $wgRightsPage, $wgRightsUrl; $tags = array(); @@ -2820,16 +2819,14 @@ $distantTemplates ) ); } - $lang = $this->getTitle()->getPageLanguage(); - # Language variants if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks - && $lang->hasVariants() ) { + && $wgContLang->hasVariants() ) { - $urlvar = $lang->getURLVariant(); + $urlvar = $wgContLang->getURLVariant(); if ( !$urlvar ) { - $variants = $lang->getVariants(); + $variants = $wgContLang->getVariants(); foreach ( $variants as $_v ) { $tags[] = Html::element( 'link', array( 'rel' => 'alternate', diff --git a/includes/SkinLegacy.php b/includes/SkinLegacy.php index 225f849539..f8ff1e3b35 100644 --- a/includes/SkinLegacy.php +++ b/includes/SkinLegacy.php @@ -279,14 +279,13 @@ class LegacyTemplate extends BaseTemplate { $s = ''; /* show links to different language variants */ - global $wgDisableLangConversion, $wgLang; + global $wgDisableLangConversion, $wgLang, $wgContLang; - $lang = $this->getSkin()->getTitle()->getPageLanguage(); - $variants = $lang->getVariants(); + $variants = $wgContLang->getVariants(); if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) { foreach ( $variants as $code ) { - $varname = $lang->getVariantname( $code ); + $varname = $wgContLang->getVariantname( $code ); if ( $varname == 'disable' ) { continue; diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 09fce56d8b..82d4ace368 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1012,21 +1012,16 @@ class SkinTemplate extends Skin { array( &$this, &$content_navigation ) ); } - $pageLang = $title->getPageLanguage(); - // Gets list of language variants - $variants = $pageLang->getVariants(); + $variants = $wgContLang->getVariants(); // Checks that language conversion is enabled and variants exist - // And if it is not in the special namespace - if( !$wgDisableLangConversion && count( $variants ) > 1 - && $title->getNamespace() != NS_SPECIAL ) { - // Gets preferred variant (note that user preference is - // only possible for wiki content language variant) - $preferred = $pageLang->getPreferredVariant(); + if( !$wgDisableLangConversion && count( $variants ) > 1 ) { + // Gets preferred variant + $preferred = $wgContLang->getPreferredVariant(); // Loops over each variant foreach( $variants as $code ) { // Gets variant name from language code - $varname = $pageLang->getVariantname( $code ); + $varname = $wgContLang->getVariantname( $code ); // Checks if the variant is marked as disabled if( $varname == 'disable' ) { // Skips this variant diff --git a/includes/Title.php b/includes/Title.php index 796a8b5143..5211769b8b 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -877,7 +877,7 @@ class Title { */ public function getLocalURL( $query = '', $variant = false ) { global $wgArticlePath, $wgScript, $wgServer, $wgRequest; - global $wgVariantArticlePath; + global $wgVariantArticlePath, $wgContLang; if ( is_array( $query ) ) { $query = wfArrayToCGI( $query ); @@ -896,7 +896,7 @@ class Title { } else { $dbkey = wfUrlencode( $this->getPrefixedDBkey() ); if ( $query == '' ) { - if ( $variant != false && $this->getPageLanguage()->hasVariants() ) { + if ( $variant != false && $wgContLang->hasVariants() ) { if ( !$wgVariantArticlePath ) { $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default } else { @@ -4384,6 +4384,9 @@ class Title { if ( $this->getNamespace() == NS_SPECIAL ) { // special pages are in the user language return $wgLang; + } elseif ( $this->isRedirect() ) { + // the arrow on a redirect page is aligned according to the user language + return $wgLang; } elseif ( $this->isCssOrJsPage() ) { // css/js should always be LTR and is, in fact, English return wfGetLangObj( 'en' ); diff --git a/includes/WikiPage.php b/includes/WikiPage.php index a99058da31..1e750f4d89 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -2562,7 +2562,7 @@ class WikiPage extends Page { * @return mixed ParserOptions object or boolean false */ public function getParserOptions( $canonical = false ) { - global $wgUser; + global $wgUser, $wgLanguageCode; if ( !$this->mParserOptions || $canonical ) { $user = !$canonical ? $wgUser : new User; @@ -2571,7 +2571,7 @@ class WikiPage extends Page { $parserOptions->enableLimitReport(); if ( $canonical ) { - $parserOptions->setUserLang( $this->mTitle->getPageLanguage() ); # Must be set explicitely + $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely return $parserOptions; } $this->mParserOptions = $parserOptions; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index e6410468e0..1698fe7937 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -321,7 +321,7 @@ class Parser { * to internalParse() which does all the real work. */ - global $wgUseTidy, $wgAlwaysUseTidy, $wgDisableLangConversion, $wgDisableTitleConversion; + global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion; $fname = __METHOD__.'-' . wfGetCaller(); wfProfileIn( __METHOD__ ); wfProfileIn( $fname ); @@ -376,7 +376,8 @@ 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 = $wgContLang->convert( $text ); } /** @@ -392,11 +393,11 @@ class Parser { || isset( $this->mDoubleUnderscores['notitleconvert'] ) || $this->mOutput->getDisplayTitle() !== false ) ) { - $convruletitle = $this->getFunctionLang()->getConvRuleTitle(); + $convruletitle = $wgContLang->getConvRuleTitle(); if ( $convruletitle ) { $this->mOutput->setTitleText( $convruletitle ); } else { - $titleText = $this->getFunctionLang()->convertTitle( $title ); + $titleText = $wgContLang->convertTitle( $title ); $this->mOutput->setTitleText( $titleText ); } } @@ -1316,6 +1317,7 @@ class Parser { * @private */ function makeFreeExternalLink( $url ) { + global $wgContLang; wfProfileIn( __METHOD__ ); $trail = ''; @@ -1348,7 +1350,7 @@ 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, $wgContLang->markNoConversion($url), true, 'free', $this->getExternalLinkAttribs( $url ) ); # Register it in the output object... # Replace unnecessary URL escape codes with their equivalent characters @@ -1576,6 +1578,7 @@ class Parser { * @return string */ function replaceExternalLinks( $text ) { + global $wgContLang; wfProfileIn( __METHOD__ ); $bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE ); @@ -1621,7 +1624,7 @@ class Parser { list( $dtrail, $trail ) = Linker::splitTrail( $trail ); } - $text = $this->getFunctionLang()->markNoConversion( $text ); + $text = $wgContLang->markNoConversion( $text ); $url = Sanitizer::cleanUrl( $url ); @@ -1778,6 +1781,8 @@ class Parser { * @private */ function replaceInternalLinks2( &$s ) { + global $wgContLang; + wfProfileIn( __METHOD__ ); wfProfileIn( __METHOD__.'-setup' ); @@ -1801,7 +1806,7 @@ class Parser { $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void" $s = substr( $s, 1 ); - $useLinkPrefixExtension = $this->getFunctionLang()->linkPrefixExtension(); + $useLinkPrefixExtension = $wgContLang->linkPrefixExtension(); $e2 = null; if ( $useLinkPrefixExtension ) { # Match the end of a line for a word that's not followed by whitespace, @@ -1827,8 +1832,8 @@ class Parser { $prefix = ''; } - if ( $this->getFunctionLang()->hasVariants() ) { - $selflink = $this->getFunctionLang()->autoConvertToAllVariants( $this->mTitle->getPrefixedText() ); + if ( $wgContLang->hasVariants() ) { + $selflink = $wgContLang->autoConvertToAllVariants( $this->mTitle->getPrefixedText() ); } else { $selflink = array( $this->mTitle->getPrefixedText() ); } @@ -1996,7 +2001,6 @@ class Parser { # Link not escaped by : , create the various objects if ( $noforce ) { - global $wgContLang; # Interwikis wfProfileIn( __METHOD__."-interwiki" ); @@ -2046,7 +2050,7 @@ class Parser { } $sortkey = Sanitizer::decodeCharReferences( $sortkey ); $sortkey = str_replace( "\n", '', $sortkey ); - $sortkey = $this->getFunctionLang()->convertCategoryKey( $sortkey ); + $sortkey = $wgContLang->convertCategoryKey( $sortkey ); $this->mOutput->addCategory( $nt->getDBkey(), $sortkey ); /** @@ -3248,7 +3252,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 { @@ -3324,8 +3328,8 @@ class Parser { } $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 ( $wgContLang->hasVariants() && $title->getArticleID() == 0 ) { + $wgContLang->findVariantLink( $part1, $title, true ); } # Do recursion depth check $limit = $this->mOptions->getMaxTemplateDepth(); diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php index ec780cb392..b8cf1bb636 100644 --- a/includes/parser/ParserCache.php +++ b/includes/parser/ParserCache.php @@ -80,7 +80,7 @@ class ParserCache { */ function getETag( $article, $popts ) { return 'W/"' . $this->getParserOutputKey( $article, - $popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) ) . + $popts->optionsHash( ParserOptions::legacyOptions() ) ) . "--" . $article->getTouched() . '"'; } @@ -130,7 +130,7 @@ class ParserCache { $usedOptions = ParserOptions::legacyOptions(); } - return $this->getParserOutputKey( $article, $popts->optionsHash( $usedOptions, $article->getTitle() ) ); + return $this->getParserOutputKey( $article, $popts->optionsHash( $usedOptions ) ); } /** @@ -165,8 +165,7 @@ class ParserCache { $value = $this->mMemc->get( $parserOutputKey ); if ( self::try116cache && !$value && strpos( $value, '*' ) !== -1 ) { wfDebug( "New format parser cache miss.\n" ); - $parserOutputKey = $this->getParserOutputKey( $article, - $popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) ); + $parserOutputKey = $this->getParserOutputKey( $article, $popts->optionsHash( ParserOptions::legacyOptions() ) ); $value = $this->mMemc->get( $parserOutputKey ); } if ( !$value ) { @@ -212,7 +211,7 @@ class ParserCache { $optionsKey->setContainsOldMagic( $parserOutput->containsOldMagic() ); $parserOutputKey = $this->getParserOutputKey( $article, - $popts->optionsHash( $optionsKey->mUsedOptions, $article->getTitle() ) ); + $popts->optionsHash( $optionsKey->mUsedOptions ) ); // Save the timestamp so that we don't have to load the revision row on view $parserOutput->mTimestamp = $article->getTimestamp(); diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 6b4eba0f3f..2ecfce4bcc 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -274,12 +274,10 @@ class ParserOptions { * settings. * * @since 1.17 - * @param $forOptions Array - * @param $title Title: used to get the content language of the page * @return \string Page rendering hash */ - public function optionsHash( $forOptions, $title = null ) { - global $wgRenderHashAppend, $wgTitle; + public function optionsHash( $forOptions ) { + global $wgContLang, $wgRenderHashAppend; $confstr = ''; @@ -323,12 +321,7 @@ class ParserOptions { // add in language specific options, if any // @todo FIXME: This is just a way of retrieving the url/user preferred variant - if( !is_null( $title ) ) { - $confstr .= $title->getPageLanguage()->getExtraHashOptions(); - } else { - global $wgContLang; - $confstr .= $wgContLang->getExtraHashOptions(); - } + $confstr .= $wgContLang->getExtraHashOptions(); $confstr .= $wgRenderHashAppend; diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 23c7cb08e8..ba89be741b 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -158,7 +158,7 @@ class LanguageConverter { // not memoized (i.e. there return value is not cached) since // new information might appear during processing after this // is first called. - if ( $req = $this->validateVariant( $req ) ) { + if ( $req ) { return $req; } return $this->mMainLanguageCode; -- 2.20.1