Partial revert of r56693 related to reverts in r56937: use old values for 'userlogin'
[lhc/web/wiklou.git] / languages / LanguageConverter.php
index 07f1619..a1f6681 100644 (file)
@@ -46,7 +46,7 @@ class LanguageConverter {
         * @param array $manualLevel limit for supported variants
         * @public
         */
-       function __construct($langobj, $maincode,
+       function __construct( $langobj, $maincode,
                                                                $variants=array(),
                                                                $variantfallbacks=array(),
                                                                $markup=array(),
@@ -54,7 +54,13 @@ class LanguageConverter {
                                                                $manualLevel = array() ) {
                $this->mLangObj = $langobj;
                $this->mMainLanguageCode = $maincode;
-               $this->mVariants = $variants;
+
+               global $wgDisabledVariants;
+               $this->mVariants = array();
+               foreach( $variants as $variant ) {
+                       if( !in_array( $variant, $wgDisabledVariants ) )
+                               $this->mVariants[] = $variant;
+               }
                $this->mVariantFallbacks = $variantfallbacks;
                global $wgLanguageNames;
                $this->mVariantNames = $wgLanguageNames;
@@ -183,7 +189,7 @@ class LanguageConverter {
                                // explode by comma
                                $result = explode(',', $acceptLanguage);
                                
-                               $languages  = array();
+                               $languages = array();
 
                                foreach( $result as $elem ) {
                                        // if $elem likes 'zh-cn;q=0.9'
@@ -196,19 +202,36 @@ class LanguageConverter {
                                        }
                                }
 
+                               $fallback_languages = array();
                                foreach( $languages as $language ) {
                                        // strip whitespace
                                        $language = trim( $language );
                                        if( in_array( $language, $this->mVariants ) ) {
                                                return $language;
-                                               break;
+                                       }
+                                       else {
+                                               // To see if there are fallbacks of current language.
+                                               // We record these fallback variants, and process
+                                               // them later.
+                                               $fallbacks = $this->getVariantFallbacks( $language );
+                                               if( is_string( $fallbacks ) )
+                                                       $fallback_languages[] = $fallbacks;
+                                               elseif( is_array( $fallbacks ) )
+                                                       $fallback_languages = array_merge( $fallback_languages, $fallbacks );
+                                       }
+                               }
+
+                               // process fallback languages now
+                               $fallback_languages = array_unique( $fallback_languages );
+                               foreach( $fallback_languages as $language ) {
+                                       if( in_array( $language, $this->mVariants ) ) {
+                                               return $language;
                                        }
                                }
                        }
                }
 
                return $this->mMainLanguageCode;
-
        }
        
        /**
@@ -515,6 +538,8 @@ class LanguageConverter {
                        if( $this->mDoContentConvert )
                                // Bug 19620: should convert a string immediately after a new rule added.
                                $text .= $this->autoConvert( $marked[0], $plang );
+                       else
+                               $text .= $marked[0];
 
                        if ( array_key_exists( 1, $marked ) ) {
                                $crule = new ConverterRule($marked[1], $this);
@@ -529,7 +554,6 @@ class LanguageConverter {
 
                // Remove the last delimiter (wasn't real)
                $text = substr( $text, 0, -strlen( $this->mMarkup['end'] ) );
-
                return $text;
        }
 
@@ -547,6 +571,11 @@ class LanguageConverter {
         * @public
         */
        function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
+               # If the article has already existed, there is no need to
+               # check it again, otherwise it may cause a fault.
+               if ( is_object( $nt ) && $nt->exists() )
+                       return;
+
                global $wgDisableLangConversion, $wgDisableTitleConversion, $wgRequest, $wgUser;
                $isredir = $wgRequest->getText( 'redirect', 'yes' );
                $action = $wgRequest->getText( 'action' );
@@ -560,7 +589,7 @@ class LanguageConverter {
                        || $action == 'submit' || $linkconvert == 'no' || $wgUser->getOption('noconvertlink') == 1 ) ) )
                        return;
 
-               if(is_object($nt))
+               if ( is_object( $nt ) )
                        $ns = $nt->getNamespace();
 
                $variants = $this->autoConvertToAllVariants($link);