Knowledgebase

How to turn namespaces into content namespaces in MediaWiki

In MediaWiki namespaces can be turned into content namespaces. By default, only the Main namespaces is a content one. Content namespaces are used by MediaWiki to identify which pages are content pages (also referred to as articles). Since only the Main namespace is a content one, then only the pages from that namespace are counted as articles, while the pages from other namespaces are not considered articles.

By default in order for a page to be counted as an article it has to belong to a content namespace, it should contain one or more internal links to other pages on the site, it shouldn't be a redirect to another page.

Whether a page is an article or not is mainly important for a couple of site tools: the site statistics and the random page tool. The article count is kept by the site statistics (Tools menu>Special Pages>Date and tools section>Statistics button). The other tool for which it matters whether a page is an article or not is the tool for selecting a random page (Random page link in the menu on the left). It selects a random page only from content pages.

With the option $wgContentNamespaces you can turn default and custom namespaces into content namespaces so that the pages in them are counted as articles. You have to add it to the LocalSettings.php file with the ID number or constant of the namespace(s) that you want to make a content one. For example, by adding the following on a new line at the end of LocalSettings.php:

$wgContentNamespaces[] = NS_HELP;

you'll turn the default Help namespace that comes preconfigured with MediaWiki into a content namespace. NS_HELP is the constant with which the Help namespace is identified; instead of it you can use the ID number of the namespace. For example:

$wgContentNamespaces[] = 12;

will also turn the Help namespace into a content one (12 is its ID number). For information on the ID numbers and constants of the default namespaces check the reference list of MediaWiki namespaces with their ID numbers and constants.

If you want to turn more than one namespace into a content one, instead of listing each one separately you can use the option once with an array of namespaces. For example:

$wgContentNamespaces = array( NS_HELP, NS_CATEGORY, NS_EXAMPLE );

will turn into content namespaces the default namespaces Help and Category and the custom one Example.

Keep in mind that if you add content namespaces with single lines (one namespaces per option), as in the previous examples, and then further down the LocalSettings.php file you add more content namespaces with an array, as in the last example, then those single lines will not be active; only the namespaces added with the array will be considered content namespaces. The opposite is not a problem, meaning that you can add an array first and then you can use single lines to add content namespaces.

Note that after a namespace is made a content one, in order for the articles in it to be counted and shown in the site statistics right away it's a good idea to update the site statistics. This can be done by executing the script initSiteStats.php that's in the maintenance folder of your MediaWiki. For more information on this check out the article on how to update the site statistics in MediaWiki.

You can also change the default condition that a page should contain a link to another page to be counted as a content page. For more information read the article on how to change the method for counting pages as articles in MediaWiki.

Other articles in our knowledge base related to namespaces:

Was this answer helpful?

 Print this Article

Also Read