MediaWiki REL1_39
SearchEngineConfig.php
Go to the documentation of this file.
1<?php
2
8
16
21 private $config;
22
27 private $language;
28
37 private $engineMappings;
38
42 private $hookRunner;
43
47 private $userOptionsLookup;
48
56 public function __construct(
57 Config $config,
59 HookContainer $hookContainer,
60 array $mappings,
61 UserOptionsLookup $userOptionsLookup
62 ) {
63 $this->config = $config;
64 $this->language = $lang;
65 $this->engineMappings = $mappings;
66 $this->hookRunner = new HookRunner( $hookContainer );
67 $this->userOptionsLookup = $userOptionsLookup;
68 }
69
74 public function getConfig() {
75 return $this->config;
76 }
77
83 public function searchableNamespaces() {
84 $arr = [];
85 foreach ( $this->language->getNamespaces() as $ns => $name ) {
86 if ( $ns >= NS_MAIN ) {
87 $arr[$ns] = $name;
88 }
89 }
90
91 $this->hookRunner->onSearchableNamespaces( $arr );
92 return $arr;
93 }
94
102 public function userNamespaces( $user ) {
103 $arr = [];
104 foreach ( $this->searchableNamespaces() as $ns => $name ) {
105 if ( $this->userOptionsLookup->getOption( $user, 'searchNs' . $ns ) ) {
106 $arr[] = $ns;
107 }
108 }
109
110 return $arr;
111 }
112
118 public function defaultNamespaces() {
119 return array_keys( $this->config->get( MainConfigNames::NamespacesToBeSearchedDefault ),
120 true );
121 }
122
129 public function getSearchTypes() {
130 $alternatives = $this->config->get( MainConfigNames::SearchTypeAlternatives ) ?: [];
131 array_unshift( $alternatives, $this->config->get( MainConfigNames::SearchType ) );
132
133 return $alternatives;
134 }
135
141 public function getSearchType() {
142 return $this->config->get( MainConfigNames::SearchType );
143 }
144
165 public function getSearchMappings() {
166 return $this->engineMappings;
167 }
168
176 public function namespacesAsText( $namespaces ) {
177 $formatted = array_map( [ $this->language, 'getFormattedNsText' ], $namespaces );
178 foreach ( $formatted as $key => $ns ) {
179 if ( empty( $ns ) ) {
180 $formatted[$key] = wfMessage( 'blanknamespace' )->text();
181 }
182 }
183 return $formatted;
184 }
185}
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:53
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:30
Interface for objects representing user identity.
if(!isset( $args[0])) $lang