(Bug 30364) LanguageConverter should depend on the page content language instead...
authorRobin Pepermans <robin@users.mediawiki.org>
Sun, 11 Sep 2011 17:56:27 +0000 (17:56 +0000)
committerRobin Pepermans <robin@users.mediawiki.org>
Sun, 11 Sep 2011 17:56:27 +0000 (17:56 +0000)
* Made variant tabs hidden on special pages (has no or sometimes wrong/inconsistent effect there; plus it's mainly in the user language)
* Made redirects be in content language again (remove from Title->getPageLanguage())

RELEASE-NOTES-1.19
includes/Article.php
includes/OutputPage.php
includes/SkinLegacy.php
includes/SkinTemplate.php
includes/Title.php
includes/WikiPage.php
includes/parser/Parser.php
includes/parser/ParserCache.php
includes/parser/ParserOptions.php
languages/LanguageConverter.php

index a88fd1c..fe55c98 100644 (file)
@@ -59,6 +59,8 @@ 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 fixes in 1.19 ===
 * $wgUploadNavigationUrl should be used for file redlinks if
index 49beeb8..24cadc0 100644 (file)
@@ -1050,13 +1050,14 @@ class Article extends Page {
         * @return string containing HMTL with redirect link
         */
        public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
-               global $wgOut, $wgLang, $wgStylePath;
+               global $wgOut, $wgStylePath;
 
                if ( !is_array( $target ) ) {
                        $target = array( $target );
                }
 
-               $imageDir = $wgLang->getDir();
+               $lang = $this->getTitle()->getPageLanguage();
+               $imageDir = $lang->getDir();
 
                if ( $appendSubtitle ) {
                        $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
@@ -1072,7 +1073,7 @@ class Article extends Page {
                }
 
                $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
-               $alt = $wgLang->isRTL() ? '←' : '→';
+               $alt = $lang->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 ) );
index 5124ba1..8821465 100644 (file)
@@ -1653,12 +1653,12 @@ class OutputPage extends ContextSource {
         *   /w/index.php?title=Main_page&variant=zh-cn should never be served.
         */
        function addAcceptLanguage() {
-               global $wgContLang;
-               if( !$this->getRequest()->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
-                       $variants = $wgContLang->getVariants();
+               $lang = $this->getTitle()->getPageLanguage();
+               if( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
+                       $variants = $lang->getVariants();
                        $aloption = array();
                        foreach ( $variants as $variant ) {
-                               if( $variant === $wgContLang->getCode() ) {
+                               if( $variant === $lang->getCode() ) {
                                        continue;
                                } else {
                                        $aloption[] = 'string-contains=' . $variant;
@@ -2613,7 +2613,7 @@ $distantTemplates
         * have to be purged on configuration changes.
         */
        protected function getJSVars() {
-               global $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
+               global $wgUseAjax, $wgEnableMWSuggest;
 
                $title = $this->getTitle();
                $ns = $title->getNamespace();
@@ -2639,8 +2639,9 @@ $distantTemplates
                        'wgCategories' => $this->getCategories(),
                        'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
                );
-               if ( $wgContLang->hasVariants() ) {
-                       $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
+               $lang = $this->getTitle()->getPageLanguage();
+               if ( $lang->hasVariants() ) {
+                       $vars['wgUserVariant'] = $lang->getPreferredVariant();
                }
                foreach ( $title->getRestrictionTypes() as $type ) {
                        $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
@@ -2692,7 +2693,7 @@ $distantTemplates
                global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
                        $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
                        $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
-                       $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang,
+                       $wgDisableLangConversion, $wgCanonicalLanguageLinks,
                        $wgRightsPage, $wgRightsUrl;
 
                $tags = array();
@@ -2818,14 +2819,16 @@ $distantTemplates
                        ) );
                }
 
+               $lang = $this->getTitle()->getPageLanguage();
+
                # Language variants
                if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
-                       && $wgContLang->hasVariants() ) {
+                       && $lang->hasVariants() ) {
 
-                       $urlvar = $wgContLang->getURLVariant();
+                       $urlvar = $lang->getURLVariant();
 
                        if ( !$urlvar ) {
-                               $variants = $wgContLang->getVariants();
+                               $variants = $lang->getVariants();
                                foreach ( $variants as $_v ) {
                                        $tags[] = Html::element( 'link', array(
                                                'rel' => 'alternate',
index f8ff1e3..225f849 100644 (file)
@@ -279,13 +279,14 @@ class LegacyTemplate extends BaseTemplate {
                $s = '';
 
                /* show links to different language variants */
-               global $wgDisableLangConversion, $wgLang, $wgContLang;
+               global $wgDisableLangConversion, $wgLang;
 
-               $variants = $wgContLang->getVariants();
+               $lang = $this->getSkin()->getTitle()->getPageLanguage();
+               $variants = $lang->getVariants();
 
                if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
                        foreach ( $variants as $code ) {
-                               $varname = $wgContLang->getVariantname( $code );
+                               $varname = $lang->getVariantname( $code );
 
                                if ( $varname == 'disable' ) {
                                        continue;
index 82d4ace..09fce56 100644 (file)
@@ -1012,16 +1012,21 @@ class SkinTemplate extends Skin {
                                array( &$this, &$content_navigation ) );
                }
 
+               $pageLang = $title->getPageLanguage();
+
                // Gets list of language variants
-               $variants = $wgContLang->getVariants();
+               $variants = $pageLang->getVariants();
                // Checks that language conversion is enabled and variants exist
-               if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
-                       // Gets preferred variant
-                       $preferred = $wgContLang->getPreferredVariant();
+               // 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();
                        // Loops over each variant
                        foreach( $variants as $code ) {
                                // Gets variant name from language code
-                               $varname = $wgContLang->getVariantname( $code );
+                               $varname = $pageLang->getVariantname( $code );
                                // Checks if the variant is marked as disabled
                                if( $varname == 'disable' ) {
                                        // Skips this variant
index 4e21f51..1a4456d 100644 (file)
@@ -877,7 +877,7 @@ class Title {
         */
        public function getLocalURL( $query = '', $variant = false ) {
                global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
-               global $wgVariantArticlePath, $wgContLang;
+               global $wgVariantArticlePath;
 
                if ( is_array( $query ) ) {
                        $query = wfArrayToCGI( $query );
@@ -896,7 +896,7 @@ class Title {
                } else {
                        $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
                        if ( $query == '' ) {
-                               if ( $variant != false && $wgContLang->hasVariants() ) {
+                               if ( $variant != false && $this->getPageLanguage()->hasVariants() ) {
                                        if ( !$wgVariantArticlePath ) {
                                                $variantArticlePath =  "$wgScript?title=$1&variant=$2"; // default
                                        } else {
@@ -4369,9 +4369,6 @@ 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' );
index 88182e9..d13c60a 100644 (file)
@@ -2559,7 +2559,7 @@ class WikiPage extends Page {
         * @return mixed ParserOptions object or boolean false
         */
        public function getParserOptions( $canonical = false ) {
-               global $wgUser, $wgLanguageCode;
+               global $wgUser;
 
                if ( !$this->mParserOptions || $canonical ) {
                        $user = !$canonical ? $wgUser : new User;
@@ -2568,7 +2568,7 @@ class WikiPage extends Page {
                        $parserOptions->enableLimitReport();
 
                        if ( $canonical ) {
-                               $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely
+                               $parserOptions->setUserLang( $this->mTitle->getPageLanguage() ); # Must be set explicitely
                                return $parserOptions;
                        }
                        $this->mParserOptions = $parserOptions;
index 02cef7d..1f6f716 100644 (file)
@@ -321,7 +321,7 @@ class Parser {
                 * to internalParse() which does all the real work.
                 */
 
-               global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
+               global $wgUseTidy, $wgAlwaysUseTidy, $wgDisableLangConversion, $wgDisableTitleConversion;
                $fname = __METHOD__.'-' . wfGetCaller();
                wfProfileIn( __METHOD__ );
                wfProfileIn( $fname );
@@ -376,8 +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 <nowiki> mark.
-
-                       $text = $wgContLang->convert( $text );
+                       $text = $this->getFunctionLang()->convert( $text );
                }
 
                /**
@@ -393,11 +392,11 @@ class Parser {
                                || isset( $this->mDoubleUnderscores['notitleconvert'] )
                                || $this->mOutput->getDisplayTitle() !== false ) )
                {
-                       $convruletitle = $wgContLang->getConvRuleTitle();
+                       $convruletitle = $this->getFunctionLang()->getConvRuleTitle();
                        if ( $convruletitle ) {
                                $this->mOutput->setTitleText( $convruletitle );
                        } else {
-                               $titleText = $wgContLang->convertTitle( $title );
+                               $titleText = $this->getFunctionLang()->convertTitle( $title );
                                $this->mOutput->setTitleText( $titleText );
                        }
                }
@@ -1309,7 +1308,6 @@ class Parser {
         * @private
         */
        function makeFreeExternalLink( $url ) {
-               global $wgContLang;
                wfProfileIn( __METHOD__ );
 
                $trail = '';
@@ -1342,7 +1340,7 @@ class Parser {
                $text = $this->maybeMakeExternalImage( $url );
                if ( $text === false ) {
                        # Not an image, make a link
-                       $text = Linker::makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
+                       $text = Linker::makeExternalLink( $url, $this->getFunctionLang()->markNoConversion($url), true, 'free',
                                $this->getExternalLinkAttribs( $url ) );
                        # Register it in the output object...
                        # Replace unnecessary URL escape codes with their equivalent characters
@@ -1570,7 +1568,6 @@ class Parser {
         * @return string
         */
        function replaceExternalLinks( $text ) {
-               global $wgContLang;
                wfProfileIn( __METHOD__ );
 
                $bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
@@ -1616,7 +1613,7 @@ class Parser {
                                list( $dtrail, $trail ) = Linker::splitTrail( $trail );
                        }
 
-                       $text = $wgContLang->markNoConversion( $text );
+                       $text = $this->getFunctionLang()->markNoConversion( $text );
 
                        $url = Sanitizer::cleanUrl( $url );
 
@@ -1773,8 +1770,6 @@ class Parser {
         * @private
         */
        function replaceInternalLinks2( &$s ) {
-               global $wgContLang;
-
                wfProfileIn( __METHOD__ );
 
                wfProfileIn( __METHOD__.'-setup' );
@@ -1798,7 +1793,7 @@ class Parser {
                $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
                $s = substr( $s, 1 );
 
-               $useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
+               $useLinkPrefixExtension = $this->getFunctionLang()->linkPrefixExtension();
                $e2 = null;
                if ( $useLinkPrefixExtension ) {
                        # Match the end of a line for a word that's not followed by whitespace,
@@ -1824,8 +1819,8 @@ class Parser {
                        $prefix = '';
                }
 
-               if ( $wgContLang->hasVariants() ) {
-                       $selflink = $wgContLang->autoConvertToAllVariants( $this->mTitle->getPrefixedText() );
+               if ( $this->getFunctionLang()->hasVariants() ) {
+                       $selflink = $this->getFunctionLang()->autoConvertToAllVariants( $this->mTitle->getPrefixedText() );
                } else {
                        $selflink = array( $this->mTitle->getPrefixedText() );
                }
@@ -1993,6 +1988,7 @@ class Parser {
 
                        # Link not escaped by : , create the various objects
                        if ( $noforce ) {
+                               global $wgContLang;
 
                                # Interwikis
                                wfProfileIn( __METHOD__."-interwiki" );
@@ -2042,7 +2038,7 @@ class Parser {
                                        }
                                        $sortkey = Sanitizer::decodeCharReferences( $sortkey );
                                        $sortkey = str_replace( "\n", '', $sortkey );
-                                       $sortkey = $wgContLang->convertCategoryKey( $sortkey );
+                                       $sortkey = $this->getFunctionLang()->convertCategoryKey( $sortkey );
                                        $this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
 
                                        /**
@@ -3244,7 +3240,7 @@ class Parser {
                                        $function = $this->mFunctionSynonyms[1][$function];
                                } else {
                                        # Case insensitive functions
-                                       $function = $wgContLang->lc( $function );
+                                       $function = $this->getFunctionLang()->lc( $function );
                                        if ( isset( $this->mFunctionSynonyms[0][$function] ) ) {
                                                $function = $this->mFunctionSynonyms[0][$function];
                                        } else {
@@ -3320,8 +3316,8 @@ class Parser {
                                }
                                $titleText = $title->getPrefixedText();
                                # Check for language variants if the template is not found
-                               if ( $wgContLang->hasVariants() && $title->getArticleID() == 0 ) {
-                                       $wgContLang->findVariantLink( $part1, $title, true );
+                               if ( $this->getFunctionLang()->hasVariants() && $title->getArticleID() == 0 ) {
+                                       $this->getFunctionLang()->findVariantLink( $part1, $title, true );
                                }
                                # Do recursion depth check
                                $limit = $this->mOptions->getMaxTemplateDepth();
index b8cf1bb..ec780cb 100644 (file)
@@ -80,7 +80,7 @@ class ParserCache {
         */
        function getETag( $article, $popts ) {
                return 'W/"' . $this->getParserOutputKey( $article,
-                       $popts->optionsHash( ParserOptions::legacyOptions() ) ) .
+                       $popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) ) .
                                "--" . $article->getTouched() . '"';
        }
 
@@ -130,7 +130,7 @@ class ParserCache {
                        $usedOptions = ParserOptions::legacyOptions();
                }
 
-               return $this->getParserOutputKey( $article, $popts->optionsHash( $usedOptions ) );
+               return $this->getParserOutputKey( $article, $popts->optionsHash( $usedOptions, $article->getTitle() ) );
        }
 
        /**
@@ -165,7 +165,8 @@ 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() ) );
+                       $parserOutputKey = $this->getParserOutputKey( $article,
+                               $popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) );
                        $value = $this->mMemc->get( $parserOutputKey );
                }
                if ( !$value ) {
@@ -211,7 +212,7 @@ class ParserCache {
                        $optionsKey->setContainsOldMagic( $parserOutput->containsOldMagic() );
 
                        $parserOutputKey = $this->getParserOutputKey( $article,
-                               $popts->optionsHash( $optionsKey->mUsedOptions ) );
+                               $popts->optionsHash( $optionsKey->mUsedOptions, $article->getTitle() ) );
 
                        // Save the timestamp so that we don't have to load the revision row on view
                        $parserOutput->mTimestamp = $article->getTimestamp();
index 0775276..baf60ed 100644 (file)
@@ -274,10 +274,12 @@ 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 ) {
-               global $wgContLang, $wgRenderHashAppend;
+       public function optionsHash( $forOptions, $title = null ) {
+               global $wgRenderHashAppend, $wgTitle;
 
                $confstr = '';
 
@@ -321,7 +323,12 @@ class ParserOptions {
 
                // add in language specific options, if any
                // @todo FIXME: This is just a way of retrieving the url/user preferred variant
-               $confstr .= $wgContLang->getExtraHashOptions();
+               if( !is_null( $title ) ) {
+                       $confstr .= $title->getPageLanguage()->getExtraHashOptions();
+               } else {
+                       global $wgContLang;
+                       $confstr .= $wgContLang->getExtraHashOptions();
+               }
 
                $confstr .= $wgRenderHashAppend;
 
index ba89be7..23c7cb0 100644 (file)
@@ -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 ) {
+               if ( $req = $this->validateVariant( $req ) ) {
                        return $req;
                }
                return $this->mMainLanguageCode;