Partial revert of r56693 related to reverts in r56937: use old values for 'userlogin'
[lhc/web/wiklou.git] / languages / LanguageConverter.php
index e219ddc..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,12 +202,30 @@ class LanguageConverter {
                                        }
                                }
 
+                               $fallback_languages = array();
                                foreach( $languages as $language ) {
                                        // strip whitespace
                                        $language = trim( $language );
                                        if( in_array( $language, $this->mVariants ) ) {
-                                               $this->mPreferredVariant = $language;
-                                               return $this->mPreferredVariant;
+                                               return $language;
+                                       }
+                                       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;
                                        }
                                }
                        }
@@ -514,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);
@@ -528,7 +554,6 @@ class LanguageConverter {
 
                // Remove the last delimiter (wasn't real)
                $text = substr( $text, 0, -strlen( $this->mMarkup['end'] ) );
-
                return $text;
        }
 
@@ -548,7 +573,7 @@ class LanguageConverter {
        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 ( $nt->exists() )
+               if ( is_object( $nt ) && $nt->exists() )
                        return;
 
                global $wgDisableLangConversion, $wgDisableTitleConversion, $wgRequest, $wgUser;