MediaWiki  master
SearchEngineConfig.php
Go to the documentation of this file.
1 <?php
2 
10 
15  private $config;
16 
21  private $language;
22 
23  public function __construct( Config $config, Language $lang ) {
24  $this->config = $config;
25  $this->language = $lang;
26  }
27 
32  public function getConfig() {
33  return $this->config;
34  }
35 
41  public function searchableNamespaces() {
42  $arr = [];
43  foreach ( $this->language->getNamespaces() as $ns => $name ) {
44  if ( $ns >= NS_MAIN ) {
45  $arr[$ns] = $name;
46  }
47  }
48 
49  Hooks::run( 'SearchableNamespaces', [ &$arr ] );
50  return $arr;
51  }
52 
60  public function userNamespaces( $user ) {
61  $arr = [];
62  foreach ( $this->searchableNamespaces() as $ns => $name ) {
63  if ( $user->getOption( 'searchNs' . $ns ) ) {
64  $arr[] = $ns;
65  }
66  }
67 
68  return $arr;
69  }
70 
76  public function defaultNamespaces() {
77  return array_keys( $this->config->get( 'NamespacesToBeSearchedDefault' ), true );
78  }
79 
86  public function getSearchTypes() {
87  $alternatives = $this->config->get( 'SearchTypeAlternatives' ) ?: [];
88  array_unshift( $alternatives, $this->config->get( 'SearchType' ) );
89 
90  return $alternatives;
91  }
92 
98  public function getSearchType() {
99  return $this->config->get( 'SearchType' );
100  }
101 
109  public function namespacesAsText( $namespaces ) {
110  $formatted = array_map( [ $this->language, 'getFormattedNsText' ], $namespaces );
111  foreach ( $formatted as $key => $ns ) {
112  if ( empty( $ns ) ) {
113  $formatted[$key] = wfMessage( 'blanknamespace' )->text();
114  }
115  }
116  return $formatted;
117  }
118 }
searchableNamespaces()
Make a list of searchable namespaces and their canonical names.
const NS_MAIN
Definition: Defines.php:60
userNamespaces( $user)
Extract default namespaces to search from the given user&#39;s settings, returning a list of index number...
getSearchType()
Return the search engine configured in $wgSearchType, etc.
if(!isset( $args[0])) $lang
Interface for configuration instances.
Definition: Config.php:28
__construct(Config $config, Language $lang)
Language $language
Current language.
getSearchTypes()
Return the search engines we support.
defaultNamespaces()
An array of namespaces indexes to be searched by default.
namespacesAsText( $namespaces)
Get a list of namespace names useful for showing in tooltips and preferences.
Config $config
Config object from which the settings will be derived.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
return true
Definition: router.php:92
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
getConfig()
Retrieve original config.