MediaWiki  master
SearchEngineConfig.php
Go to the documentation of this file.
1 <?php
2 
5 
13 
18  private $config;
19 
24  private $language;
25 
34  private $engineMappings;
35 
39  private $hookRunner;
40 
48  HookContainer $hookContainer, array $mappings
49  ) {
50  $this->config = $config;
51  $this->language = $lang;
52  $this->engineMappings = $mappings;
53  $this->hookRunner = new HookRunner( $hookContainer );
54  }
55 
60  public function getConfig() {
61  return $this->config;
62  }
63 
69  public function searchableNamespaces() {
70  $arr = [];
71  foreach ( $this->language->getNamespaces() as $ns => $name ) {
72  if ( $ns >= NS_MAIN ) {
73  $arr[$ns] = $name;
74  }
75  }
76 
77  $this->hookRunner->onSearchableNamespaces( $arr );
78  return $arr;
79  }
80 
88  public function userNamespaces( $user ) {
89  $arr = [];
90  foreach ( $this->searchableNamespaces() as $ns => $name ) {
91  if ( $user->getOption( 'searchNs' . $ns ) ) {
92  $arr[] = $ns;
93  }
94  }
95 
96  return $arr;
97  }
98 
104  public function defaultNamespaces() {
105  return array_keys( $this->config->get( 'NamespacesToBeSearchedDefault' ), true );
106  }
107 
114  public function getSearchTypes() {
115  $alternatives = $this->config->get( 'SearchTypeAlternatives' ) ?: [];
116  array_unshift( $alternatives, $this->config->get( 'SearchType' ) );
117 
118  return $alternatives;
119  }
120 
126  public function getSearchType() {
127  return $this->config->get( 'SearchType' );
128  }
129 
150  public function getSearchMappings() {
151  return $this->engineMappings;
152  }
153 
161  public function namespacesAsText( $namespaces ) {
162  $formatted = array_map( [ $this->language, 'getFormattedNsText' ], $namespaces );
163  foreach ( $formatted as $key => $ns ) {
164  if ( empty( $ns ) ) {
165  $formatted[$key] = wfMessage( 'blanknamespace' )->text();
166  }
167  }
168  return $formatted;
169  }
170 }
SearchEngineConfig\$config
Config $config
Config object from which the settings will be derived.
Definition: SearchEngineConfig.php:18
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1219
NS_MAIN
const NS_MAIN
Definition: Defines.php:69
Config
Interface for configuration instances.
Definition: Config.php:30
SearchEngineConfig\$hookRunner
HookRunner $hookRunner
Definition: SearchEngineConfig.php:39
SearchEngineConfig\userNamespaces
userNamespaces( $user)
Extract default namespaces to search from the given user's settings, returning a list of index number...
Definition: SearchEngineConfig.php:88
SearchEngineConfig\getSearchMappings
getSearchMappings()
Returns the mappings between canonical search name and underlying PHP class.
Definition: SearchEngineConfig.php:150
SearchEngineConfig\getSearchType
getSearchType()
Return the search engine configured in $wgSearchType, etc.
Definition: SearchEngineConfig.php:126
SearchEngineConfig\defaultNamespaces
defaultNamespaces()
An array of namespaces indexes to be searched by default.
Definition: SearchEngineConfig.php:104
SearchEngineConfig\searchableNamespaces
searchableNamespaces()
Make a list of searchable namespaces and their canonical names.
Definition: SearchEngineConfig.php:69
SearchEngineConfig\namespacesAsText
namespacesAsText( $namespaces)
Get a list of namespace names useful for showing in tooltips and preferences.
Definition: SearchEngineConfig.php:161
SearchEngineConfig\getSearchTypes
getSearchTypes()
Return the search engines we support.
Definition: SearchEngineConfig.php:114
SearchEngineConfig\$language
Language $language
Current language.
Definition: SearchEngineConfig.php:24
SearchEngineConfig
Configuration handling class for SearchEngine.
Definition: SearchEngineConfig.php:12
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:44
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:571
SearchEngineConfig\getConfig
getConfig()
Retrieve original config.
Definition: SearchEngineConfig.php:60
SearchEngineConfig\__construct
__construct(Config $config, Language $lang, HookContainer $hookContainer, array $mappings)
Definition: SearchEngineConfig.php:47
SearchEngineConfig\$engineMappings
array $engineMappings
Search Engine Mappings.
Definition: SearchEngineConfig.php:34
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41