MediaWiki REL1_35
SearchEngineConfig.php
Go to the documentation of this file.
1<?php
2
5
13
18 private $config;
19
24 private $language;
25
35
39 private $hookRunner;
40
47 public function __construct( Config $config, Language $lang,
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}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition Language.php:41
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Configuration handling class for SearchEngine.
array $engineMappings
Search Engine Mappings.
getConfig()
Retrieve original config.
getSearchTypes()
Return the search engines we support.
getSearchType()
Return the search engine configured in $wgSearchType, etc.
__construct(Config $config, Language $lang, HookContainer $hookContainer, array $mappings)
Config $config
Config object from which the settings will be derived.
getSearchMappings()
Returns the mappings between canonical search name and underlying PHP class.
searchableNamespaces()
Make a list of searchable namespaces and their canonical 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...
Language $language
Current language.
defaultNamespaces()
An array of namespaces indexes to be searched by default.
const NS_MAIN
Definition Defines.php:70
Interface for configuration instances.
Definition Config.php:30
if(!isset( $args[0])) $lang