Manual talk:$wgNamespacesToBeSearchedDefault

From MediaWiki.org
Jump to navigation Jump to search

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)


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)

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)

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)

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)

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)
Yes the namespace constants (NS_MAIN NS_HELP, etc) must be all uppercase. Bawolff 15:38, 26 January 2012 (UTC)
Oops, indeed capitalise is not the same as uppercase. :| Cheers --[[kgh]] 20:05, 26 January 2012 (UTC)

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)

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