Stop using heavy Language object when not needed

Two easy cases, way more can be done.

Bug: T376565
Change-Id: I3b875c4b6b2c2bdf7171a712898d50e26d86c807
This commit is contained in:
Amir Sarabadani 2024-10-16 20:02:43 +02:00
parent 4acdea458f
commit 2db1020868
4 changed files with 8 additions and 9 deletions

View file

@ -134,7 +134,7 @@ class EntryPoint extends MediaWikiEntryPoint {
private function getTextFormatters() {
$services = $this->getServiceContainer();
$code = $services->getContentLanguage()->getCode();
$code = $services->getContentLanguageCode()->toString();
$langs = array_unique( [ $code, 'en' ] );
$textFormatters = [];
$factory = $services->getMessageFormatterFactory();

View file

@ -2677,7 +2677,7 @@ return [
'_DefaultOptionsLookup' => static function ( MediaWikiServices $services ): DefaultOptionsLookup {
return new DefaultOptionsLookup(
new ServiceOptions( DefaultOptionsLookup::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
$services->getContentLanguage(),
$services->getContentLanguageCode(),
$services->getHookContainer(),
$services->getNamespaceInfo(),
$services->get( '_ConditionalDefaultsLookup' )

View file

@ -23,7 +23,7 @@ namespace MediaWiki\User\Options;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\Language\Language;
use MediaWiki\Language\LanguageCode;
use MediaWiki\Language\LanguageConverter;
use MediaWiki\MainConfigNames;
use MediaWiki\Title\NamespaceInfo;
@ -48,7 +48,7 @@ class DefaultOptionsLookup extends UserOptionsLookup {
];
private ServiceOptions $serviceOptions;
private Language $contentLang;
private LanguageCode $contentLang;
private NamespaceInfo $nsInfo;
private ConditionalDefaultsLookup $conditionalDefaultsLookup;
@ -59,14 +59,14 @@ class DefaultOptionsLookup extends UserOptionsLookup {
/**
* @param ServiceOptions $options
* @param Language $contentLang
* @param LanguageCode $contentLang
* @param HookContainer $hookContainer
* @param NamespaceInfo $nsInfo
* @param ConditionalDefaultsLookup $conditionalUserOptionsDefaultsLookup
*/
public function __construct(
ServiceOptions $options,
Language $contentLang,
LanguageCode $contentLang,
HookContainer $hookContainer,
NamespaceInfo $nsInfo,
ConditionalDefaultsLookup $conditionalUserOptionsDefaultsLookup
@ -94,7 +94,7 @@ class DefaultOptionsLookup extends UserOptionsLookup {
// Default language setting
// NOTE: don't use the content language code since the static default variant would
// NOT always be the same as the content language code.
$contentLangCode = $this->contentLang->getCode();
$contentLangCode = $this->contentLang->toString();
$LangsWithStaticDefaultVariant = LanguageConverter::$languagesWithStaticDefaultVariant;
$staticDefaultVariant = $LangsWithStaticDefaultVariant[$contentLangCode] ?? $contentLangCode;
$this->defaultOptions['language'] = $contentLangCode;

View file

@ -71,8 +71,7 @@ abstract class UserOptionsLookupTestBase extends MediaWikiIntegrationTestCase {
string $langCode = 'qqq',
array $defaultOptionsOverrides = []
): DefaultOptionsLookup {
$lang = $this->createMock( Language::class );
$lang->method( 'getCode' )->willReturn( $langCode );
$lang = new LanguageCode( $langCode );
return new DefaultOptionsLookup(
new ServiceOptions(
DefaultOptionsLookup::CONSTRUCTOR_OPTIONS,