http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97849

Revision: 97849
Author:   robin
Date:     2011-09-22 20:31:23 +0000 (Thu, 22 Sep 2011)
Log Message:
-----------
Re-do r96798 ("LanguageConverter now depends on the page content language"), 
without the change in WikiPage which caused an infinite loop (see bug 31098)

Modified Paths:
--------------
    trunk/phase3/RELEASE-NOTES-1.19
    trunk/phase3/includes/OutputPage.php
    trunk/phase3/includes/SkinLegacy.php
    trunk/phase3/includes/SkinTemplate.php
    trunk/phase3/includes/Title.php
    trunk/phase3/includes/parser/Parser.php
    trunk/phase3/includes/parser/ParserOptions.php

Modified: trunk/phase3/RELEASE-NOTES-1.19
===================================================================
--- trunk/phase3/RELEASE-NOTES-1.19     2011-09-22 20:24:12 UTC (rev 97848)
+++ trunk/phase3/RELEASE-NOTES-1.19     2011-09-22 20:31:23 UTC (rev 97849)
@@ -61,6 +61,8 @@
   to stop it from replace an already existing default sort, and suppress error.
 * (bug 18578) Rewrote revision delete related messages to allow better
   localisation
+* (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

Modified: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php        2011-09-22 20:24:12 UTC (rev 
97848)
+++ trunk/phase3/includes/OutputPage.php        2011-09-22 20:31:23 UTC (rev 
97849)
@@ -1654,12 +1654,12 @@
         *   /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;
@@ -2614,7 +2614,7 @@
         * have to be purged on configuration changes.
         */
        protected function getJSVars() {
-               global $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
+               global $wgUseAjax, $wgEnableMWSuggest;
 
                $title = $this->getTitle();
                $ns = $title->getNamespace();
@@ -2640,9 +2640,10 @@
                        '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 );
                }
@@ -2693,7 +2694,7 @@
                global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, 
$wgEnableAPI,
                        $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
                        $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
-                       $wgDisableLangConversion, $wgCanonicalLanguageLinks, 
$wgContLang,
+                       $wgDisableLangConversion, $wgCanonicalLanguageLinks,
                        $wgRightsPage, $wgRightsUrl;
 
                $tags = array();
@@ -2819,14 +2820,16 @@
                        ) );
                }
 
+               $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',

Modified: trunk/phase3/includes/SkinLegacy.php
===================================================================
--- trunk/phase3/includes/SkinLegacy.php        2011-09-22 20:24:12 UTC (rev 
97848)
+++ trunk/phase3/includes/SkinLegacy.php        2011-09-22 20:31:23 UTC (rev 
97849)
@@ -269,13 +269,15 @@
                $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 ) {
+               if ( !$wgDisableLangConversion && sizeof( $variants ) > 1
+                       && $title->getNamespace() != NS_SPECIAL ) {
                        foreach ( $variants as $code ) {
-                               $varname = $wgContLang->getVariantname( $code );
+                               $varname = $lang->getVariantname( $code );
 
                                if ( $varname == 'disable' ) {
                                        continue;

Modified: trunk/phase3/includes/SkinTemplate.php
===================================================================
--- trunk/phase3/includes/SkinTemplate.php      2011-09-22 20:24:12 UTC (rev 
97848)
+++ trunk/phase3/includes/SkinTemplate.php      2011-09-22 20:31:23 UTC (rev 
97849)
@@ -1011,16 +1011,21 @@
                                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

Modified: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php     2011-09-22 20:24:12 UTC (rev 97848)
+++ trunk/phase3/includes/Title.php     2011-09-22 20:31:23 UTC (rev 97849)
@@ -885,7 +885,7 @@
         */
        public function getLocalURL( $query = '', $variant = false ) {
                global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
-               global $wgVariantArticlePath, $wgContLang;
+               global $wgVariantArticlePath;
 
                if ( is_array( $query ) ) {
                        $query = wfArrayToCGI( $query );
@@ -904,7 +904,7 @@
                } 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 {

Modified: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php     2011-09-22 20:24:12 UTC (rev 
97848)
+++ trunk/phase3/includes/parser/Parser.php     2011-09-22 20:31:23 UTC (rev 
97849)
@@ -321,7 +321,7 @@
                 * 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 @@
                        # 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 @@
                                || 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 );
                        }
                }
@@ -1194,7 +1193,6 @@
         * @private
         */
        function makeFreeExternalLink( $url ) {
-               global $wgContLang;
                wfProfileIn( __METHOD__ );
 
                $trail = '';
@@ -1227,7 +1225,7 @@
                $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
@@ -1455,7 +1453,6 @@
         * @return string
         */
        function replaceExternalLinks( $text ) {
-               global $wgContLang;
                wfProfileIn( __METHOD__ );
 
                $bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, 
PREG_SPLIT_DELIM_CAPTURE );
@@ -1501,7 +1498,7 @@
                                list( $dtrail, $trail ) = Linker::splitTrail( 
$trail );
                        }
 
-                       $text = $wgContLang->markNoConversion( $text );
+                       $text = $this->getFunctionLang()->markNoConversion( 
$text );
 
                        $url = Sanitizer::cleanUrl( $url );
 
@@ -1658,8 +1655,6 @@
         * @private
         */
        function replaceInternalLinks2( &$s ) {
-               global $wgContLang;
-
                wfProfileIn( __METHOD__ );
 
                wfProfileIn( __METHOD__.'-setup' );
@@ -1683,7 +1678,7 @@
                $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,
@@ -1709,8 +1704,8 @@
                        $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() );
                }
@@ -1878,6 +1873,7 @@
 
                        # Link not escaped by : , create the various objects
                        if ( $noforce ) {
+                               global $wgContLang;
 
                                # Interwikis
                                wfProfileIn( __METHOD__."-interwiki" );
@@ -1927,7 +1923,7 @@
                                        }
                                        $sortkey = 
Sanitizer::decodeCharReferences( $sortkey );
                                        $sortkey = str_replace( "\n", '', 
$sortkey );
-                                       $sortkey = 
$wgContLang->convertCategoryKey( $sortkey );
+                                       $sortkey = 
$this->getFunctionLang()->convertCategoryKey( $sortkey );
                                        $this->mOutput->addCategory( 
$nt->getDBkey(), $sortkey );
 
                                        /**
@@ -3028,7 +3024,7 @@
         * @private
         */
        function braceSubstitution( $piece, $frame ) {
-               global $wgContLang, $wgNonincludableNamespaces, 
$wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
+               global $wgNonincludableNamespaces, 
$wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
                wfProfileIn( __METHOD__ );
                wfProfileIn( __METHOD__.'-setup' );
 
@@ -3129,7 +3125,7 @@
                                        $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 {
@@ -3205,8 +3201,8 @@
                                }
                                $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();

Modified: trunk/phase3/includes/parser/ParserOptions.php
===================================================================
--- trunk/phase3/includes/parser/ParserOptions.php      2011-09-22 20:24:12 UTC 
(rev 97848)
+++ trunk/phase3/includes/parser/ParserOptions.php      2011-09-22 20:31:23 UTC 
(rev 97849)
@@ -275,11 +275,11 @@
         *
         * @since 1.17
         * @param $forOptions Array
-        * @param $title Title: will be used to get the page content language 
(since r97636)
+        * @param $title Title: used to get the content language of the page 
(since r97636)
         * @return \string Page rendering hash
         */
        public function optionsHash( $forOptions, $title = null ) {
-               global $wgContLang, $wgRenderHashAppend;
+               global $wgRenderHashAppend;
 
                $confstr = '';
 
@@ -323,7 +323,12 @@
 
                // 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;
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to