Merge "Add converted namespace names as aliases to avoid confusion."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 2 Sep 2013 17:47:46 +0000 (17:47 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 2 Sep 2013 17:47:46 +0000 (17:47 +0000)
1  2 
languages/Language.php
languages/LanguageConverter.php

diff --combined languages/Language.php
@@@ -49,14 -49,12 +49,14 @@@ class FakeConverter 
         */
        public $mLang;
        function __construct( $langobj ) { $this->mLang = $langobj; }
 +      function autoConvert( $text, $variant = false ) { return $text; }
        function autoConvertToAllVariants( $text ) { return array( $this->mLang->getCode() => $text ); }
        function convert( $t ) { return $t; }
        function convertTo( $text, $variant ) { return $text; }
        function convertTitle( $t ) { return $t->getPrefixedText(); }
        function convertNamespace( $ns ) { return $this->mLang->getFormattedNsText( $ns ); }
        function getVariants() { return array( $this->mLang->getCode() ); }
 +      function getVariantFallbacks( $variant ) { return $this->mLang->getCode(); }
        function getPreferredVariant() { return $this->mLang->getCode(); }
        function getDefaultVariant() { return $this->mLang->getCode(); }
        function getURLVariant() { return ''; }
@@@ -68,8 -66,6 +68,8 @@@
        function convertCategoryKey( $key ) { return $key; }
        function convertLinkToAllVariants( $text ) { return $this->autoConvertToAllVariants( $text ); }
        function armourMath( $text ) { return $text; }
 +      function validateVariant( $variant = null ) { return $variant === $this->mLang->getCode() ? $variant : null; }
 +      function translate( $text, $variant ) { return $text; }
  }
  
  /**
@@@ -686,7 -682,18 +686,18 @@@ class Language 
                                }
                        }
  
-                       $this->namespaceAliases = $aliases;
+                       # Also add converted namespace names as aliases, to avoid confusion.
+                       $convertedNames = array();
+                       foreach ( $this->getVariants() as $variant ) {
+                               if ( $variant === $this->mCode ) {
+                                       continue;
+                               }
+                               foreach ( $this->getNamespaces() as $ns => $_ ) {
+                                       $convertedNames[$this->getConverter()->convertNamespace( $ns, $variant )] = $ns;
+                               }
+                       }
+                       $this->namespaceAliases = $aliases + $convertedNames;
                }
                return $this->namespaceAliases;
        }
                $segments = array();
  
                foreach ( $intervals as $intervalName => $intervalValue ) {
 +                      // Messages: duration-centuries, duration-decades, duration-years, duration-days,
 +                      // duration-hours, duration-minutes, duration-seconds
                        $message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
                        $segments[] = $message->inLanguage( $this )->escaped();
                }
@@@ -246,7 -246,7 +246,7 @@@ class LanguageConverter 
         * @return Mixed: variant if one found, false otherwise.
         */
        protected function getUserVariant() {
 -              global $wgUser;
 +              global $wgUser, $wgContLang;
  
                // memoizing this function wreaks havoc on parserTest.php
                /*
                // Don't call this on stub objects because that causes infinite
                // recursion during initialisation
                if ( $wgUser->isLoggedIn() ) {
 -                      $ret = $wgUser->getOption( 'variant' );
 +                      if ( $this->mMainLanguageCode == $wgContLang->getCode() ) {
 +                              $ret = $wgUser->getOption( 'variant' );
 +                      } else {
 +                              $ret = $wgUser->getOption( 'variant-' . $this->mMainLanguageCode );
 +                      }
                } else {
                        // figure out user lang without constructing wgLang to avoid
                        // infinite recursion
                $variant = $this->getPreferredVariant();
                $index = $title->getNamespace();
                if ( $index !== NS_MAIN ) {
-                       $text = $this->convertNamespace( $index ) . ':';
+                       $text = $this->convertNamespace( $index, $variant ) . ':';
                } else {
                        $text = '';
                }
         * Get the namespace display name in the preferred variant.
         *
         * @param $index int namespace id
+        * @param $variant string|null variant code or null for preferred variant
         * @return String: namespace name for display
         */
-       public function convertNamespace( $index ) {
-               $variant = $this->getPreferredVariant();
+       public function convertNamespace( $index, $variant = null ) {
+               if ( $variant === null ) {
+                       $variant = $this->getPreferredVariant();
+               }
                if ( $index === NS_MAIN ) {
                        return '';
                } else {