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
41 private $engineMappings;
42
43 private ServiceOptions $options;
44 private Language $language;
45 private HookRunner $hookRunner;
46 private UserOptionsLookup $userOptionsLookup;
47
48 public function __construct(
49 ServiceOptions $options,
50 Language $language,
51 HookContainer $hookContainer,
52 array $engineMappings,
53 UserOptionsLookup $userOptionsLookup
54 ) {
55 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
56 $this->options = $options;
57 $this->language = $language;
58 $this->engineMappings = $engineMappings;
59 $this->hookRunner = new HookRunner( $hookContainer );
60 $this->userOptionsLookup = $userOptionsLookup;
61 }
62
68 public function getConfig() {
69 wfDeprecated( __METHOD__, '1.43' );
70 return $this->config;
71 }
72
78 public function searchableNamespaces() {
79 $arr = [];
80 foreach ( $this->language->getNamespaces() as $ns => $name ) {
81 if ( $ns >= NS_MAIN ) {
82 $arr[$ns] = $name;
83 }
84 }
85
86 $this->hookRunner->onSearchableNamespaces( $arr );
87 return $arr;
88 }
89
97 public function userNamespaces( $user ) {
98 $arr = [];
99 foreach ( $this->searchableNamespaces() as $ns => $name ) {
100 if ( $this->userOptionsLookup->getOption( $user, 'searchNs' . $ns ) ) {
101 $arr[] = $ns;
102 }
103 }
104
105 return $arr;
106 }
107
113 public function defaultNamespaces() {
114 return array_keys( $this->options->get( MainConfigNames::NamespacesToBeSearchedDefault ),
115 true );
116 }
117
124 public function getSearchTypes() {
125 $alternatives = $this->options->get( MainConfigNames::SearchTypeAlternatives ) ?: [];
126 array_unshift( $alternatives, $this->options->get( MainConfigNames::SearchType ) );
127
128 return $alternatives;
129 }
130
136 public function getSearchType() {
137 return $this->options->get( MainConfigNames::SearchType );
138 }
139
160 public function getSearchMappings() {
161 return $this->engineMappings;
162 }
163
171 public function namespacesAsText( $namespaces ) {
172 $formatted = array_map( [ $this->language, 'getFormattedNsText' ], $namespaces );
173 foreach ( $formatted as $key => $ns ) {
174 if ( !$ns ) {
175 $formatted[$key] = wfMessage( 'blanknamespace' )->text();
176 }
177 }
178 return $formatted;
179 }
180}
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:81
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 $language, HookContainer $hookContainer, array $engineMappings, 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.