MediaWiki/Suche: Unterschied zwischen den Versionen

Aus Foxwiki
Zeile 1: Zeile 1:
= Default namespaces to be searched =
= Default namespaces to be searched =
* In MediaWiki all the pages of your site are grouped into different namespaces.  
In MediaWiki all the pages of your site are grouped into different namespaces.  
* By default, the search function is configured to search only in the Main namespace.  
* By default, the search function is configured to search only in the Main namespace.  
* That's the namespace that contains the articles.  
* That's the namespace that contains the articles.  

Version vom 17. April 2022, 13:18 Uhr

Default namespaces to be searched

In MediaWiki all the pages of your site are grouped into different namespaces.

  • By default, the search function is configured to search only in the Main namespace.
  • That's the namespace that contains the articles.
  • So if the term or phrase for which the user searches is contained on pages belonging to other namespaces (e.g. discussion pages, user pages, etc.), these pages will not be listed in the search results, unless from the advanced search options the user specifically selects other namespaces.
  • If you want to, you can enable the search function for other namespaces.
  • For example, you may want discussion pages associated with articles and personal user pages also to be searched by default.
  • You can do this with the help of the option $wgNamespacesToBeSearchedDefault.
  • You have to add it at the end of the LocalSettings.php file of your MediaWiki together with a list of the namespaces.

So edit LocalSettings.php and add the following at the end of the file:

$wgNamespacesToBeSearchedDefault = array(
  NS_MAIN =>           true,
  NS_TALK =>           false,
  NS_USER =>           false,
  NS_USER_TALK =>      false,
  NS_PROJECT =>        false,
  NS_PROJECT_TALK =>   false,
  NS_FILE =>           false,
  NS_FILE_TALK =>      false,
   NS_MEDIAWIKI =>      false,
   NS_MEDIAWIKI_TALK => false,
  NS_TEMPLATE =>       false,
  NS_TEMPLATE_TALK =>  false,
  NS_HELP =>           false,
  NS_HELP_TALK =>      false,
  NS_CATEGORY =>       false,
  NS_CATEGORY_TALK =>  false
);
  • The namespaces are listed with their text IDs (also known as constants).
  • By default, only NS_MAIN is set to true, which means that the search function works only with the Main namespace.
  • For a complete list of the namespaces with their respective constants and what each namespace is used for check out the article with the reference list of MediaWiki namespaces with their ID numbers and constants.
  • To set the search function to search the pages of a namespace simply change false with true for that namespace.

For example, if you want discussion pages associated with articles, personal user pages and their associated discussion pages and category pages to be searched, make sure you have the following in your LocalSettings.php file:

$wgNamespacesToBeSearchedDefault = array(
  NS_MAIN =>           true,
  NS_TALK =>           true,
  NS_USER =>           true,
  NS_USER_TALK =>      true,
  NS_PROJECT =>        false,
  NS_PROJECT_TALK =>   false,
  NS_FILE =>           false,
  NS_FILE_TALK =>      false,
  NS_MEDIAWIKI =>      false,
  NS_MEDIAWIKI_TALK => false,
  NS_TEMPLATE =>       false,
  NS_TEMPLATE_TALK =>  false,
  NS_HELP =>           false,
  NS_HELP_TALK =>      false,
  NS_CATEGORY =>       true,
  NS_CATEGORY_TALK =>  false
);
  • These changes apply to all users of the site, both unregistered and registered
  • In MediaWiki versions 1.15 and older the changes will not affect existing registered users
  • For such users you have to configure the options with the help of the script userOptions.php
  • For more information on how to use it check out the article on how to edit the options of users in MediaWiki
  • Note that the above changes set which namespaces should be automatically searched by default when the search function is used
    • On the page with the search results on the frontend there are advanced options that can be viewed by clicking on the Advanced button
    • It displays a list of the namespaces and the user can specifically select which namespaces they want to search
    • This can be done regardless of which namespaces are set to be searched by default with the option $wgNamespacesToBeSearchedDefault

The LocalSettings.php file that you have to modify is in the root MediaWiki folder on your MediaWiki hosting account.

  • If you have installed the application directly in the public_html directory on the account (making the frontend URL yourdomain.com), then the path to the file on the account with respect to that directory will be public_html/LocalSettings.php.
  • An easy way for HostKnox customers to edit files on their accounts is with the File manager of the Pixie control panel.
  • You can also download the file on your local computer (e.g. with an FTP client), edit it with a text editor (e.g. Notepad ++) and upload it back overwriting the old file.
$wgNamespacesToBeSearchedDefault = [
 NS_MAIN => true,
 2 => true,
 3 => true,
 10 => true,
 11 => true,
 184 => true,
 185 => true,
 186 => true,
 187 => true,
 188 => true,
 189 => true,
 190 => true,
 191 => true,
 192 => true,
 193 => true,
 194 => true,
 195 => true,
 196 => true,
 197 => true,
 198 => true,
 199 => true,
 200 => true,
 201 => true,
 "_merge_strategy" => "array_plus"
];

Add all the numbered Namespaces and set to true just like in the Visual Editor

$wgNamespacesToBeSearchedDefault = [
 NS_MAIN => true,
NS_CATEGORY => true
];
$wgNamespacesToBeSearchedDefault=$nsAll

A number of Content: pages in my wiki have content in addition to serving as containers for sub-categories/pages. Even when setting the following in LocalSettings.php:

$wgNamespacesToBeSearchedDefault = [

 NS_MAIN => true,
 NS_CATEGORY => true
];

Searches executed from the searchbar fail to discover the sought-for content

  • the Special:Search UI also fails to discover this content unless I manually click "Everything" instead of "Content" under the Special:Search text field.

Interestingly, I do get the behavior I want if I declare:

$wgNamespacesToBeSearchedDefault=$nsAll
  • In which case searches from the search bar correctly discover all content (even though "$nsAll" itself is undefined at least within the scope of LocalSettings.php).
  • The disadvantage here is that since "$nsAll" is undefined, runJob.php complains about "$nsAll" being an unknown variable.
  • This doesn't appear to break runJob.php, but the whole affair seems messy, and I'd much prefer the wgNamespacesToBeSearchedDefault to work out of the box as advertised.

Links

  1. https://www.mediawiki.org/wiki/Manual:$wgNamespacesToBeSearchedDefault
  2. https://www.hostknox.com/knowledgebase/679/How-to-select-the-default-namespaces-to-be-searched-by-the-search-function-in-MediaWiki.html
  3. https://workingwithmediawiki.com/book/chapter9.html