33use Wikimedia\Assert\Assert;
56 private $defaultOptions =
null;
75 $this->serviceOptions = $options;
76 $this->contentLang = $contentLang;
77 $this->hookRunner =
new HookRunner( $hookContainer );
78 $this->nsInfo = $nsInfo;
79 $this->conditionalDefaultsLookup = $conditionalUserOptionsDefaultsLookup;
87 private function getGenericDefaultOptions(): array {
88 if ( $this->defaultOptions !== null ) {
89 return $this->defaultOptions;
97 $contentLangCode = $this->contentLang->getCode();
98 $LangsWithStaticDefaultVariant = LanguageConverter::$languagesWithStaticDefaultVariant;
99 $staticDefaultVariant = $LangsWithStaticDefaultVariant[$contentLangCode] ?? $contentLangCode;
100 $this->defaultOptions[
'language'] = $contentLangCode;
101 $this->defaultOptions[
'variant'] = $staticDefaultVariant;
102 foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
103 $staticDefaultVariant = $LangsWithStaticDefaultVariant[$langCode] ?? $langCode;
104 $this->defaultOptions[
"variant-$langCode"] = $staticDefaultVariant;
111 foreach ( $this->nsInfo->getValidNamespaces() as $n ) {
112 $this->defaultOptions[
'searchNs' . $n] = ( $nsSearchDefault[$n] ?? false ) ? 1 : 0;
117 $this->hookRunner->onUserGetDefaultOptions( $this->defaultOptions );
119 return $this->defaultOptions;
126 $defaultOptions = $this->getGenericDefaultOptions();
129 if ( $userIdentity ) {
130 $conditionallyDefaultOptions = $this->conditionalDefaultsLookup->getConditionallyDefaultOptions();
131 foreach ( $conditionallyDefaultOptions as $optionName ) {
132 $conditionalDefault = $this->conditionalDefaultsLookup->getOptionDefaultForUser(
133 $optionName, $userIdentity
135 if ( $conditionalDefault !==
null ) {
136 $defaultOptions[$optionName] = $conditionalDefault;
141 return $defaultOptions;
150 $defaultOverride =
null,
151 bool $ignoreHidden =
false,
152 int $queryFlags = IDBAccessObject::READ_NORMAL
154 $this->verifyUsable( $user, __METHOD__ );
155 return $this->getDefaultOption( $oname ) ?? $defaultOverride;
164 int $queryFlags = IDBAccessObject::READ_NORMAL
166 $this->verifyUsable( $user, __METHOD__ );
167 if ( $flags & self::EXCLUDE_DEFAULTS ) {
170 return $this->getDefaultOptions();
187 private function verifyUsable(
UserIdentity $user,
string $fname ) {
188 if ( defined(
'MEDIAWIKI_INSTALL' ) ) {
191 Assert::precondition( !$user->
isRegistered(),
"$fname called on a registered user" );
196class_alias( DefaultOptionsLookup::class,
'MediaWiki\\User\\DefaultOptionsLookup' );
if(!defined('MW_SETUP_CALLBACK'))
A class containing constants representing the names of configuration variables.
const DefaultUserOptions
Name constant for the DefaultUserOptions setting, for use with Config::get()
const DefaultSkin
Name constant for the DefaultSkin setting, for use with Config::get()
const NamespacesToBeSearchedDefault
Name constant for the NamespacesToBeSearchedDefault setting, for use with Config::get()
The base class for all skins.
static normalizeKey(string $key)
Normalize a skin preference value to a form that can be loaded.
Interface for database access objects.