Namespaces in MediaWiki

Every page on a MediaWiki site is created in one of the existing namespaces. In this way the pages are grouped according to their function on the site. For example, main content pages/articles are in the Main namespace while their associated discussion pages are in the Talk namespace.

In this article we'll briefly go over the basic information related to namespaces. For some more details you can also read the tutorial about namespaces in MediaWiki, and also the various articles in our knowledge base on how to perform different things related to namespaces.

Default Namespaces

MediaWiki comes prepackaged with 18 default namespaces. Two of these are virtual namespaces to which users cannot add pages. The other 16 can be used for creating pages and editing these pages. They are divided into 8 pairs of namespaces; for each namespaces intended for pages with some content there's a corresponding namespace for containing discussion pages for making comments.

Each namespace has a name that's used on the frontend and in URLs, and each namespace is also defined with an ID number and a text constant. They are used when making changes to the options of namespaces.

Here are the default namespaces. In brackets you'll see the respective ID number and constant:

  • Media (-2, NS_MEDIA) - a virtual namespaces that cannot be modified.

  • Special (-1, NS_SPECIAL) - a virtual namespace for the special pages with tools and reports.

  • Main (0, NS_MAIN) - the namespace for the main content pages/articles.

  • Talk (1, NS_TALK) - the discussion pages of the Main namespace.

  • User (2, NS_USER) - the namespace for personal user pages.

  • User talk (3, NS_USER_TALK) - the discussion pages for user pages.

  • Project (4, NS_PROJECT) - for pages about the site (e.g. About us, Disclaimers, Privacy policy).

  • Project talk (5, NS_PROJECT_TALK) - for pages for discussing the Project namespace.

  • File (6, NS_FILE) - the pages of uploaded files.

  • File talk (7, NS_FILE_TALK) - their corresponding discussion pages.

  • MediaWiki (8, NS_MEDIAWIKI) - contains the pages for modifying the CSS code of skins and for editing the interface text and messages.

  • MediaWiki talk (9, NS_MEDIAWIKI_TALK) - the talk pages for discussing the pages of the MediaWiki namespace.

  • Template (10, NS_TEMPLATE) - the namespace for templates.

  • Template talk (11, NS_TEMPLATE_TALK) - their corresponding talk pages.

  • Help (12, NS_HELP) - a namespace for any pages with helpful information.

  • Help talk (13, NS_HELP_TALK) - their associated discussion pages.

  • Category (14, NS_CATEGORY) - the namespace for category pages.

  • Category talk (15, NS_CATEGORY_TALK) - discussion pages for commenting category pages.

Namespace Prefixes and URLs

The full name of a page is formed by the prefix of the namespace to which it belongs plus the name of the page. The namespace prefix is also used in the URL address of the page. The only namespace that doesn't have a prefix is the Main namespace.

The name of a namespace is used for its prefix. For example, a page called Example page in the Help namespace will have a full name Help:Example page and its corresponding URL will have the form

Prevent the Editing of Namespaces

In addition to the option for restricting the editing of specific pages (with the Protect page option), you can do this for all pages on the site or for all pages from a particular namespace. For example, you may want to restrict the editing of all pages in the Help namespace.

This can be done by adding the option $wgNamespaceProtection with the necessary information about the particular namespace to the LocalSettings.php file of your MediaWiki. With that option you can define what permission a user group must have in order to be able to edit the pages of the selected namespace. You can either use a permission that already exists and is assigned only to the group(s) which you want to be able to edit the namespace, or you can create a new permission and add it to the group(s) you want to allow to edit the namespace.

For example, by adding the following at the end of LocalSettings.php:

$wgGroupPermissions['user']['edithelp'] = true;
$wgNamespaceProtection[NS_HELP] = array( 'edithelp' );

you'll create a permission called edithelp that will be assigned to the user group, and you'll allow only those who have that permission to edit the pages in the Help namespace.

For information on how to prevent users from editing all pages of the site or only specific pages check out the article on how to prevent users from editing pages in MediaWiki.

Custom Namespaces

If for any reason you need to create a new namespace(s), you can do that as well. This is done by adding some lines to the LocalSettings.php file. Namespaces typically go in pairs, meaning that for each namespace there's one for containing discussion pages. So it's a good idea to create a corresponding talk namespace for every non-talk namespace.

For instance, with the following added at the end of LocalSettings.php:

define("NS_EXAMPLE", 3002); 
define("NS_EXAMPLE_TALK", 3003);
$wgExtraNamespaces[NS_EXAMPLE] = "Example";
$wgExtraNamespaces[NS_EXAMPLE_TALK] = "Example_talk";

you'll create two namespaces: Example and Example talk. The first two lines define the ID number of each of the new namespaces (e.g. 3002 and 3003), and the constants (e.g. NS_EXAMPLE and NS_EXAMPLE_TALK). The other two lines add the new namespaces. In quotation marks put the name of the namespace as you want it to appear on the frontend (separate words with underscores). In the square brackets use the respective constants as you've defined them in the previous two lines.

Note that each non-talk namespace should have an even number for an ID, and each talk namespace an odd number. The numbers should be different than those of any existing namespaces (or ones that can be created in the future by installing an extension). The safest way is to use a number above 3000.

Some other articles related to namespaces that you may find useful:

Was this answer helpful?

 Print this Article

Also Read