jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/266785 )

Change subject: Support language fallbacks for Special:MyLanguage
......................................................................


Support language fallbacks for Special:MyLanguage

Add fallback lookup based on the interface language to
Special:MyLanguage. Lookup order:

  <user lang> -> <explicit lang> -> <fallback lang(s)> -> <base>

Example when the user's lang is arz:

  arz -> <explicit lang> -> ar -> en -> <base>

Bug: T50292
Change-Id: I245cab71fdd4b4585f86dde808493cd69841b09a
---
M includes/specials/SpecialMyLanguage.php
M tests/phpunit/includes/specials/SpecialMyLanguageTest.php
2 files changed, 44 insertions(+), 6 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/specials/SpecialMyLanguage.php 
b/includes/specials/SpecialMyLanguage.php
index 9cb6d4b..37d96f4 100644
--- a/includes/specials/SpecialMyLanguage.php
+++ b/includes/specials/SpecialMyLanguage.php
@@ -81,6 +81,7 @@
                }
 
                if ( !$base ) {
+                       // No subpage provided or base page does not exist
                        return null;
                }
 
@@ -90,14 +91,38 @@
                }
 
                $uiCode = $this->getLanguage()->getCode();
-               $proposed = $base->getSubpage( $uiCode );
-               if ( $proposed && $proposed->exists() && $uiCode !== 
$base->getPageLanguage()->getCode() ) {
-                       return $proposed;
-               } elseif ( $provided && $provided->exists() ) {
-                       return $provided;
-               } else {
+               $wikiLangCode = $this->getConfig()->get( 'LanguageCode' );
+
+               if ( $uiCode === $wikiLangCode ) {
+                       // Short circuit when the current UI language is the
+                       // wiki's default language to avoid unnecessary page 
lookups.
                        return $base;
                }
+
+               // Check for a subpage in current UI language
+               $proposed = $base->getSubpage( $uiCode );
+               if ( $proposed && $proposed->exists() ) {
+                       return $proposed;
+               }
+
+               if ( $provided !== $base && $provided->exists() ) {
+                       // Explicit language code given and the page exists
+                       return $provided;
+               }
+
+               // Check for fallback languages specified by the UI language
+               $possibilities = Language::getFallbacksFor( $uiCode );
+               foreach ( $possibilities as $lang ) {
+                       if ( $lang !== $wikiLangCode ) {
+                               $proposed = $base->getSubpage( $lang );
+                               if ( $proposed && $proposed->exists() ) {
+                                       return $proposed;
+                               }
+                       }
+               }
+
+               // When all else has failed, return the base page
+               return $base;
        }
 
        /**
diff --git a/tests/phpunit/includes/specials/SpecialMyLanguageTest.php 
b/tests/phpunit/includes/specials/SpecialMyLanguageTest.php
index 89fd1b0..84fa71a 100644
--- a/tests/phpunit/includes/specials/SpecialMyLanguageTest.php
+++ b/tests/phpunit/includes/specials/SpecialMyLanguageTest.php
@@ -8,7 +8,10 @@
        public function addDBDataOnce() {
                $titles = [
                        'Page/Another',
+                       'Page/Another/ar',
+                       'Page/Another/en',
                        'Page/Another/ru',
+                       'Page/Another/zh-hans',
                ];
                foreach ( $titles as $title ) {
                        $page = WikiPage::factory( Title::newFromText( $title ) 
);
@@ -54,12 +57,22 @@
        }
 
        public static function provideFindTitle() {
+               // See addDBDataOnce() for page declarations
                return [
+                       // [ $expected, $subpage, $langCode, $userLang ]
                        [ null, '::Fail', 'en', 'en' ],
                        [ 'Page/Another', 'Page/Another/en', 'en', 'en' ],
                        [ 'Page/Another', 'Page/Another', 'en', 'en' ],
                        [ 'Page/Another/ru', 'Page/Another', 'en', 'ru' ],
                        [ 'Page/Another', 'Page/Another', 'en', 'es' ],
+                       [ 'Page/Another/zh-hans', 'Page/Another', 'en', 
'zh-hans' ],
+                       [ 'Page/Another/zh-hans', 'Page/Another', 'en', 'zh-mo' 
],
+                       [ 'Page/Another/en', 'Page/Another', 'de', 'es' ],
+                       [ 'Page/Another/ar', 'Page/Another', 'en', 'ar' ],
+                       [ 'Page/Another/ar', 'Page/Another', 'en', 'arz' ],
+                       [ 'Page/Another/ar', 'Page/Another/de', 'en', 'arz' ],
+                       [ 'Page/Another/ru', 'Page/Another/ru', 'en', 'arz' ],
+                       [ 'Page/Another/ar', 'Page/Another/ru', 'en', 'ar' ],
                ];
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/266785
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I245cab71fdd4b4585f86dde808493cd69841b09a
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Nemo bis <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to