From 1b334a48e9624c2ccf882a39fb70875960376450 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Wed, 29 Sep 2021 02:46:36 +0200 Subject: [PATCH] user: Add default value for all "variant" user option keys Without a default the preference is treat as unknown and possible values identical to the default are not excluded from javascript code or database. Bug: T291748 Change-Id: I37cf1cd87a5ef1fd91aba0c3cc4b0e3f9c9c08b4 --- includes/user/DefaultOptionsLookup.php | 10 ++++------ tests/phpunit/includes/auth/AuthManagerTest.php | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/user/DefaultOptionsLookup.php b/includes/user/DefaultOptionsLookup.php index c8da7185d4a..ebe72deb320 100644 --- a/includes/user/DefaultOptionsLookup.php +++ b/includes/user/DefaultOptionsLookup.php @@ -82,13 +82,11 @@ class DefaultOptionsLookup extends UserOptionsLookup { $this->defaultOptions = $this->serviceOptions->get( 'DefaultUserOptions' ); // Default language setting - $this->defaultOptions['language'] = $this->contentLang->getCode(); + $contentLangCode = $this->contentLang->getCode(); + $this->defaultOptions['language'] = $contentLangCode; + $this->defaultOptions['variant'] = $contentLangCode; foreach ( LanguageConverter::$languagesWithVariants as $langCode ) { - if ( $langCode === $this->contentLang->getCode() ) { - $this->defaultOptions['variant'] = $langCode; - } else { - $this->defaultOptions["variant-$langCode"] = $langCode; - } + $this->defaultOptions["variant-$langCode"] = $langCode; } // NOTE: don't use SearchEngineConfig::getSearchableNamespaces here, diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index 4e6488798ee..1422165e7aa 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -751,7 +751,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase { return [ [ 'zh', false, 'zh', 'zh' ], [ 'zh', true, 'de', 'zh' ], - [ 'fr', true, 'de', null ], + [ 'fr', true, 'de', 'fr' ], ]; }