MediaWiki master
SearchEngineConfig.php
Go to the documentation of this file.
1<?php
2
10
18
20 public const CONSTRUCTOR_OPTIONS = [
21 MainConfigNames::NamespacesToBeSearchedDefault,
22 MainConfigNames::SearchTypeAlternatives,
23 MainConfigNames::SearchType,
24 ];
25
30 private $config;
31 private ServiceOptions $options;
32
37 private $language;
38
47 private $engineMappings;
48
52 private $hookRunner;
53
57 private $userOptionsLookup;
58
66 public function __construct(
67 ServiceOptions $options,
68 Language $lang,
69 HookContainer $hookContainer,
70 array $mappings,
71 UserOptionsLookup $userOptionsLookup
72 ) {
73 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
74 $this->options = $options;
75 $this->language = $lang;
76 $this->engineMappings = $mappings;
77 $this->hookRunner = new HookRunner( $hookContainer );
78 $this->userOptionsLookup = $userOptionsLookup;
79 }
80
86 public function getConfig() {
87 wfDeprecated( __METHOD__, '1.43' );
88 return $this->config;
89 }
90
96 public function searchableNamespaces() {
97 $arr = [];
98 foreach ( $this->language->getNamespaces() as $ns => $name ) {
99 if ( $ns >= NS_MAIN ) {
100 $arr[$ns] = $name;
101 }
102 }
103
104 $this->hookRunner->onSearchableNamespaces( $arr );
105 return $arr;
106 }
107
115 public function userNamespaces( $user ) {
116 $arr = [];
117 foreach ( $this->searchableNamespaces() as $ns => $name ) {
118 if ( $this->userOptionsLookup->getOption( $user, 'searchNs' . $ns ) ) {
119 $arr[] = $ns;
120 }
121 }
122
123 return $arr;
124 }
125
131 public function defaultNamespaces() {
132 return array_keys( $this->options->get( MainConfigNames::NamespacesToBeSearchedDefault ),
133 true );
134 }
135
142 public function getSearchTypes() {
143 $alternatives = $this->options->get( MainConfigNames::SearchTypeAlternatives ) ?: [];
144 array_unshift( $alternatives, $this->options->get( MainConfigNames::SearchType ) );
145
146 return $alternatives;
147 }
148
154 public function getSearchType() {
155 return $this->options->get( MainConfigNames::SearchType );
156 }
157
178 public function getSearchMappings() {
179 return $this->engineMappings;
180 }
181
189 public function namespacesAsText( $namespaces ) {
190 $formatted = array_map( [ $this->language, 'getFormattedNsText' ], $namespaces );
191 foreach ( $formatted as $key => $ns ) {
192 if ( !$ns ) {
193 $formatted[$key] = wfMessage( 'blanknamespace' )->text();
194 }
195 }
196 return $formatted;
197 }
198}
const NS_MAIN
Definition Defines.php:64
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.
Base class for language-specific code.
Definition Language.php:63
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...
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.