Merge "ForeignAPIRepo: Fetch thumb error from foreign repo"
[lhc/web/wiklou.git] / languages / LanguageConverter.php
index 43afe65..0186ccf 100644 (file)
@@ -258,7 +258,7 @@ class LanguageConverter {
                // Get language variant preference from logged in users
                // Don't call this on stub objects because that causes infinite
                // recursion during initialisation
-               if ( $wgUser->isLoggedIn() )  {
+               if ( $wgUser->isLoggedIn() ) {
                        $ret = $wgUser->getOption( 'variant' );
                } else {
                        // figure out user lang without constructing wgLang to avoid
@@ -344,7 +344,7 @@ class LanguageConverter {
                        }
                }
 
-               if( $this->guessVariant( $text, $toVariant ) ) {
+               if ( $this->guessVariant( $text, $toVariant ) ) {
                        wfProfileOut( __METHOD__ );
                        return $text;
                }
@@ -644,14 +644,14 @@ class LanguageConverter {
                        if ( $pos === false ) {
                                // No more markup, append final segment
                                $fragment = substr( $text, $startPos );
-                               $out .= $shouldConvert? $this->autoConvert( $fragment, $variant ): $fragment;
+                               $out .= $shouldConvert ? $this->autoConvert( $fragment, $variant ) : $fragment;
                                return $out;
                        }
 
                        // Markup found
                        // Append initial segment
                        $fragment = substr( $text, $startPos, $pos - $startPos );
-                       $out .= $shouldConvert? $this->autoConvert( $fragment, $variant ): $fragment;
+                       $out .= $shouldConvert ? $this->autoConvert( $fragment, $variant ) : $fragment;
 
                        // Advance position
                        $startPos = $pos;
@@ -687,7 +687,7 @@ class LanguageConverter {
 
                while ( $startPos < $length ) {
                        $m = false;
-                       preg_match( '/-\{|\}-/', $text, $m,  PREG_OFFSET_CAPTURE, $startPos );
+                       preg_match( '/-\{|\}-/', $text, $m, PREG_OFFSET_CAPTURE, $startPos );
                        if ( !$m ) {
                                // Unclosed rule
                                break;
@@ -833,7 +833,7 @@ class LanguageConverter {
         * @author Nikola Smolenski <smolensk@eunet.rs>
         * @since 1.19
         */
-       public function guessVariant($text, $variant) {
+       public function guessVariant( $text, $variant ) {
                return false;
        }
 
@@ -941,7 +941,7 @@ class LanguageConverter {
                $parsed[$key] = true;
 
                if ( $subpage === '' ) {
-                       $txt = MessageCache::singleton()->get( 'conversiontable', true, $code );
+                       $txt = MessageCache::singleton()->getMsgFromNamespace( $key, $code );
                } else {
                        $txt = false;
                        $title = Title::makeTitleSafe( NS_MEDIAWIKI, $key );
@@ -952,7 +952,7 @@ class LanguageConverter {
                                                $txt = $revision->getContent( Revision::RAW )->getNativeData();
                                        }
 
-                                       //@todo: in the future, use a specialized content model, perhaps based on json!
+                                       // @todo in the future, use a specialized content model, perhaps based on json!
                                }
                        }
                }
@@ -1259,14 +1259,14 @@ class ConverterRule {
                $choice = preg_split( $varsep_pattern, $rules );
 
                foreach ( $choice as $c ) {
-                       $v  = explode( ':', $c, 2 );
+                       $v = explode( ':', $c, 2 );
                        if ( count( $v ) != 2 ) {
                                // syntax error, skip
                                continue;
                        }
                        $to = trim( $v[1] );
-                       $v  = trim( $v[0] );
-                       $u  = explode( '=>', $v, 2 );
+                       $v = trim( $v[0] );
+                       $u = explode( '=>', $v, 2 );
                        // if $to is empty, strtr() could return a wrong result
                        if ( count( $u ) == 1 && $to && in_array( $v, $variants ) ) {
                                $bidtable[$v] = $to;
@@ -1357,6 +1357,37 @@ class ConverterRule {
                }
        }
 
+       /**
+        * Similar to getRuleConvertedStr(), but this prefers to use original
+        * page title if $variant === $this->mConverter->mMainLanguageCode
+        * and may return false in this case (so this title conversion rule
+        * will be ignored and the original title is shown).
+        *
+        * @since 1.21
+        * @param $variant The variant code to display page title in
+        * @return String|false The converted title or false if just page name
+        */
+       function getRuleConvertedTitle( $variant ) {
+               if ( $variant === $this->mConverter->mMainLanguageCode ) {
+                       // If a string targeting exactly this variant is set,
+                       // use it. Otherwise, just return false, so the real
+                       // page name can be shown (and because variant === main,
+                       // there'll be no further automatic conversion).
+                       $disp = $this->getTextInBidtable( $variant );
+                       if ( $disp ) {
+                               return $disp;
+                       }
+                       if ( array_key_exists( $variant, $this->mUnidtable ) ) {
+                               $disp = array_values( $this->mUnidtable[$variant] );
+                               $disp = $disp[0];
+                       }
+                       // Assigned above or still false.
+                       return $disp;
+               } else {
+                       return $this->getRuleConvertedStr( $variant );
+               }
+       }
+
        /**
         * Generate conversion table for all text.
         * @private
@@ -1439,7 +1470,7 @@ class ConverterRule {
                                   // then we check its fallback variants.
                                $variantFallbacks =
                                        $this->mConverter->getVariantFallbacks( $variant );
-                               if( is_array( $variantFallbacks ) ) {
+                               if ( is_array( $variantFallbacks ) ) {
                                        foreach ( $variantFallbacks as $variantFallback ) {
                                                // if current variant's fallback exist in flags
                                                if ( isset( $this->mVariantFlags[$variantFallback] ) ) {
@@ -1509,7 +1540,7 @@ class ConverterRule {
                                        $this->mRuleDisplay = $this->getRuleConvertedStr( $variant );
                                        break;
                                case 'T':
-                                       $this->mRuleTitle = $this->getRuleConvertedStr( $variant );
+                                       $this->mRuleTitle = $this->getRuleConvertedTitle( $variant );
                                        $this->mRuleDisplay = '';
                                        break;
                                default: