Manual:$wgNamespacesToBeSearchedDefault
From MediaWiki.org
| Namespaces: $wgNamespacesToBeSearchedDefault | |
|---|---|
| Which namespaces should be searched? |
|
| Introduced in version: | pre 1.1.0 |
| Removed in version: | still in use |
| Allowed Values: | (see below) |
| Default Value: | (see below) |
Other settings: Alphabetical | By Function
Contents |
[edit] Details
The variable holds an array of namespaces, indicating which namespaces are enabled for searching by default. The array is indexed by the namespace ID, and each index holds either False (don't search) or True (search this namespace).
Note that changing these values in LocalSettings.php only affects newly created and anonymous users - it does not change the settings for existing users. To also update the settings for current users who have not yet changed their search preferences, modify the User.php file as well (see below).
[edit] Default value (1.5.0 and above)
#Set default searching $wgNamespacesToBeSearchedDefault = array( NS_MAIN => true, NS_TALK => true, NS_USER => true, NS_USER_TALK => true, NS_WIKIPEDIA => false, NS_WIKIPEDIA_TALK => false, NS_IMAGE => true, NS_IMAGE_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 => talk );
Change "false" to "true" to set the namespaces new users will search.
[edit] Changing options for existing users
[edit] userOptions.php MediaWiki maintenance script
Use the userOptions.php script provided with MediaWiki to change the default namespaces for existing users (or see how many are differing from your new defaults). For example, to search user pages: "php userOptions.php --nowarn --quiet searchNs2 --old 0 --new 1". For other namespaces, just replace searchNs# with the namespace number like one of those listed on the Manual:Namespace page.
# php userOptions.php
This script pass through all users and change one of their options.
The new option is NOT validated.
Usage:
php userOptions.php --list
php userOptions.php <user option> --usage
php userOptions.php [options]Â <user option> --old <old value> --new <new value>
Switchs:
--list : list available user options and their default value
--usage <option name> : report statistics about an option
--old <old value> : the value to look for
--new <new value> : new value to update users with
Options:
--nowarn: hides the 5 seconds warning
--quiet : do not print what is happening
--dry : do not save user settings back to database
[edit] Making direct changes to the MediaWiki code
The problem, unfortunately, applies even to namespaces created after a user was created/has edited his/her preferences. The problem is that method getOption() in User.php does not fall back to default user options if a particular option does not exist in that user's preferences. This is quite annoying if you use namespaces to categorize article types since there is no easy way to update preferences of all users. The following implementation of getOption() solves the problem - it uses default values for options which the user did not touch yet:
User.php:
function getOption( $oname, $defaultOverride = '' ) { $this->load(); if ( is_null( $this->mOptions ) ) { if($defaultOverride != '') { return $defaultOverride; } $this->mOptions = User::getDefaultOptions(); } if ( array_key_exists( $oname, $this->mOptions ) ) { return trim( $this->mOptions[$oname] ); } else { ## try to look for a default when the option is not set $defOpts = User::getDefaultOptions(); if ( $defaultOverride == '' && array_key_exists( $oname, $defOpts) ) { return trim( $defOpts[$oname] ); } else { return $defaultOverride; } } }
[edit] Old versions
The variable holds an array of namespaces, numbered from -1 (Special:) and not including -2 (direct-linked media), indicating which namespaces are enabled for searching by default. The array is indexed by the numeric namespace ID, and each index holds either 0 (don't search) or 1 (search this namespace).
[edit] Default value (prior to 1.5.0)
The NS_ constants weren't used (possibly because they weren't defined) so numeric values were used instead:
array( -1 => 0, 0 => 1, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0 )
[edit] Default value (prior to 1.4.5)
Prior to 1.4.5, namespaces 9 and 11 were also searched.
array( -1 => 0, 0 => 1, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 1, 10 => 0, 11 => 1 )
[edit] Another method
This is an example of what to edit if nothing else works.
DefaultSettings.php:
$wgDefaultUserOptions = array( 'quickbar' => 1, 'underline' => 2, 'cols' => 80, 'rows' => 25, 'searchlimit' => 20, 'contextlines' => 5, 'contextchars' => 50, 'skin' => false, 'math' => 1, 'rcdays' => 7, 'rclimit' => 50, 'wllimit' => 250, 'highlightbroken' => 1, 'stubthreshold' => 0, 'previewontop' => 1, 'editsection' => 1, 'editsectiononrightclick' => 0, 'showtoc' => 1, 'showtoolbar' => 1, 'date' => 'default', 'imagesize' => 2, 'thumbsize' => 2, 'rememberpassword' => 0, 'enotifwatchlistpages' => 0, 'enotifusertalkpages' => 1, 'enotifminoredits' => 0, 'enotifrevealaddr' => 0, 'shownumberswatching' => 1, 'fancysig' => 0, 'externaleditor' => 0, 'externaldiff' => 0, 'showjumplinks' => 1, 'numberheadings' => 0, 'uselivepreview' => 0, 'watchlistdays' => 3.0, 'searchNs0' => 1, 'searchNs130' => 1, 'searchNs190' => 1, 'searchNs210' => 1, 'searchNs230' => 1, 'searchNs250' => 1, 'searchNs270' => 1, 'searchNs290' => 1, 'searchNs310' => 1, 'searchNs330' => 1, 'searchNs350' => 1, 'searchNs370' => 1, 'searchNs390' => 1, 'searchNs410' => 1, 'searchNs430' => 1, 'searchNs450' => 1, );

