}
if ( !$base ) {
+ // No subpage provided or base page does not exist
return null;
}
}
$uiCode = $this->getLanguage()->getCode();
+ $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() && $uiCode !== $base->getPageLanguage()->getCode() ) {
+ if ( $proposed && $proposed->exists() ) {
return $proposed;
- } elseif ( $provided && $provided->exists() ) {
+ }
+
+ if ( $provided !== $base && $provided->exists() ) {
+ // Explicit language code given and the page exists
return $provided;
- } else {
- return $base;
}
+
+ // 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;
}
/**
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 ) );
}
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' ],
];
}
}