Merge "(bug 1495) Include the site language in the fallback list"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 25 Mar 2013 23:26:00 +0000 (23:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 25 Mar 2013 23:26:00 +0000 (23:26 +0000)
languages/Language.php
tests/phpunit/includes/cache/MessageCacheTest.php

index 42883b5..16de816 100644 (file)
@@ -4006,8 +4006,9 @@ class Language {
                        if ( end( $fallbacks ) === 'en' ) {
                                array_pop( $fallbacks );
                        }
-                       // Append the site's fallback chain
+                       // Append the site's fallback chain, including the site language itself
                        $siteFallbacks = self::getFallbacksFor( $wgLanguageCode );
+                       array_unshift( $siteFallbacks, $wgLanguageCode );
 
                        // Eliminate any languages already included in the chain
                        $siteFallbacks = array_intersect( array_diff( $siteFallbacks, $fallbacks ), $siteFallbacks );
index eda06d4..3b3e4a6 100644 (file)
@@ -8,25 +8,44 @@ class MessageCacheTest extends MediaWikiLangTestCase {
 
        protected function setUp() {
                parent::setUp();
+               $this->configureLanguages();
                MessageCache::singleton()->enable();
        }
 
-       function addDBData() {
-               // be sure english messages under $key, not $key/en
+       /**
+        * Helper function -- setup site language for testing
+        */
+       protected function configureLanguages() {
+               // for the test, we need the content language to be anything but English,
+               // let's choose e.g. German (de)
+               $langCode = 'de';
+               $langObj = Language::factory( $langCode );
+
                $this->setMwGlobals( array(
-                       'wgLanguageCode' => 'en',
-                       'wgContLang' => Language::factory( 'en' ),
+                       'wgLanguageCode' => $langCode,
+                       'wgLang' => $langObj,
+                       'wgContLang' => $langObj,
                ) );
+       }
+
+       function addDBData() {
+               $this->configureLanguages();
 
-               // Set up messages and fallbacks ab -> ru -> en
+               // Set up messages and fallbacks ab -> ru -> de -> en
                $this->makePage( 'FallbackLanguageTest-Full', 'ab' );
                $this->makePage( 'FallbackLanguageTest-Full', 'ru' );
+               $this->makePage( 'FallbackLanguageTest-Full', 'de' );
                $this->makePage( 'FallbackLanguageTest-Full', 'en' );
 
                // Fallbacks where ab does not exist
                $this->makePage( 'FallbackLanguageTest-Partial', 'ru' );
+               $this->makePage( 'FallbackLanguageTest-Partial', 'de' );
                $this->makePage( 'FallbackLanguageTest-Partial', 'en' );
 
+               // Fallback to the content language
+               $this->makePage( 'FallbackLanguageTest-ContLang', 'de' );
+               $this->makePage( 'FallbackLanguageTest-ContLang', 'en' );
+
                // Fallback to english
                $this->makePage( 'FallbackLanguageTest-English', 'en' );
 
@@ -67,6 +86,7 @@ class MessageCacheTest extends MediaWikiLangTestCase {
                return array(
                        array( 'FallbackLanguageTest-Full', 'ab', 'ab' ),
                        array( 'FallbackLanguageTest-Partial', 'ab', 'ru' ),
+                       array( 'FallbackLanguageTest-ContLang', 'ab', 'de' ),
                        array( 'FallbackLanguageTest-English', 'ab', 'en' ),
                        array( 'FallbackLanguageTest-None', 'ab', false ),
                );