4 * Configuration handling class for SearchEngine.
5 * Provides added service over plain configuration.
9 class SearchEngineConfig
{
12 * Config object from which the settings will be derived.
17 public function __construct( Config
$config ) {
18 $this->config
= $config;
22 * Retrieve original config.
25 public function getConfig() {
30 * Make a list of searchable namespaces and their canonical names.
31 * @return array Namespace ID => name
33 public function searchableNamespaces() {
35 foreach ( $this->config
->get( 'ContLang' )->getNamespaces() as $ns => $name ) {
36 if ( $ns >= NS_MAIN
) {
41 Hooks
::run( 'SearchableNamespaces', [ &$arr ] );
46 * Extract default namespaces to search from the given user's
47 * settings, returning a list of index numbers.
52 public function userNamespaces( $user ) {
54 foreach ( $this->searchableNamespaces() as $ns => $name ) {
55 if ( $user->getOption( 'searchNs' . $ns ) ) {
64 * An array of namespaces indexes to be searched by default
66 * @return int[] Namespace IDs
68 public function defaultNamespaces() {
69 return array_keys( $this->config
->get( 'NamespacesToBeSearchedDefault' ), true );
73 * Return the search engines we support. If only $wgSearchType
74 * is set, it'll be an array of just that one item.
78 public function getSearchTypes() {
79 $alternatives = $this->config
->get( 'SearchTypeAlternatives' ) ?
: [];
80 array_unshift( $alternatives, $this->config
->get( 'SearchType' ) );
86 * Return the search engine configured in $wgSearchType, etc.
90 public function getSearchType() {
91 return $this->config
->get( 'SearchType' );
95 * Get a list of namespace names useful for showing in tooltips
98 * @param int[] $namespaces
99 * @return string[] List of names
101 public function namespacesAsText( $namespaces ) {
102 $formatted = array_map( [ $this->config
->get( 'ContLang' ), 'getFormattedNsText' ], $namespaces );
103 foreach ( $formatted as $key => $ns ) {
104 if ( empty( $ns ) ) {
105 $formatted[$key] = wfMessage( 'blanknamespace' )->text();