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.
23 public function __construct( Config
$config, Language
$lang ) {
24 $this->config
= $config;
25 $this->language
= $lang;
29 * Retrieve original config.
32 public function getConfig() {
37 * Make a list of searchable namespaces and their canonical names.
38 * @return array Namespace ID => name
40 public function searchableNamespaces() {
42 foreach ( $this->language
->getNamespaces() as $ns => $name ) {
43 if ( $ns >= NS_MAIN
) {
48 Hooks
::run( 'SearchableNamespaces', [ &$arr ] );
53 * Extract default namespaces to search from the given user's
54 * settings, returning a list of index numbers.
59 public function userNamespaces( $user ) {
61 foreach ( $this->searchableNamespaces() as $ns => $name ) {
62 if ( $user->getOption( 'searchNs' . $ns ) ) {
71 * An array of namespaces indexes to be searched by default
73 * @return int[] Namespace IDs
75 public function defaultNamespaces() {
76 return array_keys( $this->config
->get( 'NamespacesToBeSearchedDefault' ), true );
80 * Return the search engines we support. If only $wgSearchType
81 * is set, it'll be an array of just that one item.
85 public function getSearchTypes() {
86 $alternatives = $this->config
->get( 'SearchTypeAlternatives' ) ?
: [];
87 array_unshift( $alternatives, $this->config
->get( 'SearchType' ) );
93 * Return the search engine configured in $wgSearchType, etc.
97 public function getSearchType() {
98 return $this->config
->get( 'SearchType' );
102 * Get a list of namespace names useful for showing in tooltips
105 * @param int[] $namespaces
106 * @return string[] List of names
108 public function namespacesAsText( $namespaces ) {
109 $formatted = array_map( [ $this->language
, 'getFormattedNsText' ], $namespaces );
110 foreach ( $formatted as $key => $ns ) {
111 if ( empty( $ns ) ) {
112 $formatted[$key] = wfMessage( 'blanknamespace' )->text();