MediaWiki REL1_41
SearchEngineConfig.php
Go to the documentation of this file.
1<?php
2
9
17
22 private $config;
23
28 private $language;
29
38 private $engineMappings;
39
43 private $hookRunner;
44
48 private $userOptionsLookup;
49
57 public function __construct(
58 Config $config,
59 Language $lang,
60 HookContainer $hookContainer,
61 array $mappings,
62 UserOptionsLookup $userOptionsLookup
63 ) {
64 $this->config = $config;
65 $this->language = $lang;
66 $this->engineMappings = $mappings;
67 $this->hookRunner = new HookRunner( $hookContainer );
68 $this->userOptionsLookup = $userOptionsLookup;
69 }
70
75 public function getConfig() {
76 return $this->config;
77 }
78
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 => $name ) {
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->config->get( MainConfigNames::NamespacesToBeSearchedDefault ),
121 true );
122 }
123
130 public function getSearchTypes() {
131 $alternatives = $this->config->get( MainConfigNames::SearchTypeAlternatives ) ?: [];
132 array_unshift( $alternatives, $this->config->get( MainConfigNames::SearchType ) );
133
134 return $alternatives;
135 }
136
142 public function getSearchType() {
143 return $this->config->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}
const NS_MAIN
Definition Defines.php:64
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Base class for language-specific code.
Definition Language.php:63
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.
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.
__construct(Config $config, Language $lang, HookContainer $hookContainer, array $mappings, UserOptionsLookup $userOptionsLookup)
Interface for configuration instances.
Definition Config.php:32
Interface for objects representing user identity.