MediaWiki master
SearchEngineConfig.php
Go to the documentation of this file.
1<?php
2
11
19
21 public const CONSTRUCTOR_OPTIONS = [
22 MainConfigNames::NamespacesToBeSearchedDefault,
23 MainConfigNames::SearchTypeAlternatives,
24 MainConfigNames::SearchType,
25 ];
26
31 private $config;
32 private ServiceOptions $options;
33
38 private $language;
39
48 private $engineMappings;
49
53 private $hookRunner;
54
58 private $userOptionsLookup;
59
67 public function __construct(
68 ServiceOptions $options,
69 Language $lang,
70 HookContainer $hookContainer,
71 array $mappings,
72 UserOptionsLookup $userOptionsLookup
73 ) {
74 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
75 $this->options = $options;
76 $this->language = $lang;
77 $this->engineMappings = $mappings;
78 $this->hookRunner = new HookRunner( $hookContainer );
79 $this->userOptionsLookup = $userOptionsLookup;
80 }
81
87 public function getConfig() {
88 wfDeprecated( __METHOD__, '1.43' );
89 return $this->config;
90 }
91
97 public function searchableNamespaces() {
98 $arr = [];
99 foreach ( $this->language->getNamespaces() as $ns => $name ) {
100 if ( $ns >= NS_MAIN ) {
101 $arr[$ns] = $name;
102 }
103 }
104
105 $this->hookRunner->onSearchableNamespaces( $arr );
106 return $arr;
107 }
108
116 public function userNamespaces( $user ) {
117 $arr = [];
118 foreach ( $this->searchableNamespaces() as $ns => $name ) {
119 if ( $this->userOptionsLookup->getOption( $user, 'searchNs' . $ns ) ) {
120 $arr[] = $ns;
121 }
122 }
123
124 return $arr;
125 }
126
132 public function defaultNamespaces() {
133 return array_keys( $this->options->get( MainConfigNames::NamespacesToBeSearchedDefault ),
134 true );
135 }
136
143 public function getSearchTypes() {
144 $alternatives = $this->options->get( MainConfigNames::SearchTypeAlternatives ) ?: [];
145 array_unshift( $alternatives, $this->options->get( MainConfigNames::SearchType ) );
146
147 return $alternatives;
148 }
149
155 public function getSearchType() {
156 return $this->options->get( MainConfigNames::SearchType );
157 }
158
179 public function getSearchMappings() {
180 return $this->engineMappings;
181 }
182
190 public function namespacesAsText( $namespaces ) {
191 $formatted = array_map( [ $this->language, 'getFormattedNsText' ], $namespaces );
192 foreach ( $formatted as $key => $ns ) {
193 if ( !$ns ) {
194 $formatted[$key] = wfMessage( 'blanknamespace' )->text();
195 }
196 }
197 return $formatted;
198 }
199}
const NS_MAIN
Definition Defines.php:65
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
A class for passing options to services.
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Base class for language-specific code.
Definition Language.php:80
A class containing constants representing the names of configuration variables.
Provides access to user options.
Configuration handling class for SearchEngine.
getConfig()
Retrieve original config.
__construct(ServiceOptions $options, Language $lang, HookContainer $hookContainer, array $mappings, UserOptionsLookup $userOptionsLookup)
getSearchTypes()
Return the search engines we support.
getSearchType()
Return the search engine configured in $wgSearchType, etc.
getSearchMappings()
Returns the mappings between canonical search name and underlying PHP class.
searchableNamespaces()
Make a list of searchable namespaces and their localized names.
namespacesAsText( $namespaces)
Get a list of namespace names useful for showing in tooltips and preferences.
userNamespaces( $user)
Extract default namespaces to search from the given user's settings, returning a list of index number...
defaultNamespaces()
An array of namespaces indexes to be searched by default.
Interface for configuration instances.
Definition Config.php:32
Interface for objects representing user identity.