MediaWiki master
SearchEngineConfig.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Search;
4
13
21
23 public const CONSTRUCTOR_OPTIONS = [
27 ];
28
33 private $config;
34
43 private $engineMappings;
44
45 private ServiceOptions $options;
46 private Language $language;
47 private HookRunner $hookRunner;
48 private UserOptionsLookup $userOptionsLookup;
49
50 public function __construct(
51 ServiceOptions $options,
52 Language $language,
53 HookContainer $hookContainer,
54 array $engineMappings,
55 UserOptionsLookup $userOptionsLookup
56 ) {
57 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
58 $this->options = $options;
59 $this->language = $language;
60 $this->engineMappings = $engineMappings;
61 $this->hookRunner = new HookRunner( $hookContainer );
62 $this->userOptionsLookup = $userOptionsLookup;
63 }
64
70 public function getConfig() {
71 wfDeprecated( __METHOD__, '1.43' );
72 return $this->config;
73 }
74
84 public function searchableNamespaces() {
85 $arr = [];
86 foreach ( $this->language->getNamespaces() as $ns => $name ) {
87 if ( $ns >= NS_MAIN ) {
88 $arr[$ns] = $name;
89 }
90 }
91
92 $this->hookRunner->onSearchableNamespaces( $arr );
93 return $arr;
94 }
95
103 public function userNamespaces( $user ) {
104 $arr = [];
105 foreach ( $this->searchableNamespaces() as $ns => $_ ) {
106 if ( $this->userOptionsLookup->getOption( $user, 'searchNs' . $ns ) ) {
107 $arr[] = $ns;
108 }
109 }
110
111 return $arr;
112 }
113
119 public function defaultNamespaces() {
120 return array_keys( $this->options->get( MainConfigNames::NamespacesToBeSearchedDefault ),
121 true );
122 }
123
130 public function getSearchTypes() {
131 $alternatives = $this->options->get( MainConfigNames::SearchTypeAlternatives ) ?: [];
132 array_unshift( $alternatives, $this->options->get( MainConfigNames::SearchType ) );
133
134 return $alternatives;
135 }
136
142 public function getSearchType() {
143 return $this->options->get( MainConfigNames::SearchType );
144 }
145
166 public function getSearchMappings() {
167 return $this->engineMappings;
168 }
169
177 public function namespacesAsText( $namespaces ) {
178 $formatted = array_map( $this->language->getFormattedNsText( ... ), $namespaces );
179 foreach ( $formatted as $key => $ns ) {
180 if ( !$ns ) {
181 $formatted[$key] = wfMessage( 'blanknamespace' )->text();
182 }
183 }
184 return $formatted;
185 }
186}
187
189class_alias( SearchEngineConfig::class, 'SearchEngineConfig' );
const NS_MAIN
Definition Defines.php:51
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:69
A class containing constants representing the names of configuration variables.
const SearchTypeAlternatives
Name constant for the SearchTypeAlternatives setting, for use with Config::get()
const SearchType
Name constant for the SearchType setting, for use with Config::get()
const NamespacesToBeSearchedDefault
Name constant for the NamespacesToBeSearchedDefault setting, for use with Config::get()
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.
namespacesAsText( $namespaces)
Get a list of namespace names useful for showing in tooltips and preferences.
getSearchType()
Return the search engine configured in $wgSearchType, etc.
searchableNamespaces()
List searchable namespaces and their localized names (with underscores, without considering language ...
getSearchMappings()
Returns the mappings between canonical search name and underlying PHP class.
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.
Provides access to user options.
Interface for configuration instances.
Definition Config.php:18
Interface for objects representing user identity.
Definition of a mapping for the search index field.