Jump to content

Manual talk:$wgNamespacesToBeSearchedDefault

Add topic
From mediawiki.org
Latest comment: 4 years ago by Wikinaut in topic Remark regarding changes for existing users

User preferences

[edit]

Important to note that setting this will not override a users preferences. So if you have changed your preferences, changing this will not appear to you, making you think that it hasn't worked --Dr DBW 01:54, 27 June 2007 (UTC)Reply


The above 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:

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;
		}
	}
}

--Jim Bim 18:32, 17 August 2007 (UTC)Reply

Problem with line $this -> load()

[edit]

There seems to be a problem in line 2: $this -> load();
no method "load()" known
probably the correct code is: $this->loadFromDatabase();  ?

Custom namespaces

[edit]

I think this setting needs to be included after any custom namespace declarations in LocalSettings.php or it won't take effect.   Thorncrag   01:48, 26 January 2011 (UTC)Reply

Not strictly speaking, but if you're defining constants for the namespaces, you can't use them until you've defined them! —Emufarmers(T|C) 03:15, 26 January 2011 (UTC)Reply

Namespaces must be uppercase?

[edit]

Namespaces must be uppercase? Because, I put this in LocalSettings.php:

$wgNamespacesToBeSearchedDefault = array(
NS_Main => true, 
NS_Help => true, 
);

But it didn´t work. What is the mistake? --Speedtook 09:25, 26 January 2012 (UTC)Reply

I guess you have to set an entirely new array in LocalSettings.php including all namespaces and yes I would follow the example an capitalise the names of the namespaces. Cheers --[[kgh]] 14:30, 26 January 2012 (UTC)Reply
Yes the namespace constants (NS_MAIN NS_HELP, etc) must be all uppercase. Bawolff 15:38, 26 January 2012 (UTC)Reply
Oops, indeed capitalise is not the same as uppercase. :| Cheers --[[kgh]] 20:05, 26 January 2012 (UTC)Reply

Im getting an error...

[edit]
Notice: Use of undefined constant NS_SITE - assumed 'NS_SITE' in Z:\wamp\www\w\LocalSettings.php on line 436
Call Stack

The code:

#Namespace sites begin

	$wgExtraNamespaces[700] = "Site";
	$wgExtraNamespaces[700] = "Site_talk";
	
	$wgContentNamespaces[] = 700;
#end

#Namespace people begin

	$wgExtraNamespaces[800] = "People";
	$wgExtraNamespaces[801] = "People_talk";
	
	$wgExtraNamespaces[800] = "Site_talk";

#end

#Set default searching
$wgNamespacesToBeSearchedDefault = array(
        NS_MAIN =>           true,
        NS_TALK =>           false,
        NS_USER =>           true,
        NS_USER_TALK =>      false,
        NS_PROJECT =>        true,
        NS_PROJECT_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 =>           true,
        NS_HELP_TALK =>      false,
        NS_CATEGORY =>       true,
        NS_CATEGORY_TALK =>  false
);
#end

--Muqman 52 (talk) 21:26, 31 May 2012 (UTC)Reply

Probably you should set the extra Namespaces as advised $wgExtraNamespaces. Cheers --[[kgh]] (talk) 07:59, 29 June 2013 (UTC)Reply

Change in MW1.34

[edit]

Before 1.34, having this set to NS_IMAGE => true, NS_IMAGE_TALK => false, worked. After 1.34, these throw an error [21-Dec-2019 10:09:57 America/Winnipeg] PHP Warning: Use of undefined constant NS_IMAGE - assumed 'NS_IMAGE' (this will throw an Error in a future version of PHP) in /home/xxx/wiki.xxx.ca/LocalSettings.php on line 98

Solution is to use NS_FILE and NS_FILE_TALK instead. Thanks to Sam Reed for the answer. Tenbergen (talk) 16:52, 21 December 2019 (UTC)Reply

Remark regarding changes for existing users

[edit]

See https://www.mediawiki.org/wiki/Topic:Vkhl3smzar03240e . Fixed now. --Wikinaut (talk) 18:06, 14 April 2020 (UTC)Reply