From MediaWiki.org
(Redirected from Extension:Simple namespaces)
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png

Release status:Extension status stable

MediaWiki extension Simple namespaces.png
ImplementationTemplate:Extension#type Special page
DescriptionTemplate:Extension#description Add new namespaces from Special:Namespaces page
Author(s)Template:Extension#username Unsupported derivative based on Special:Interwiki GPL by Stephanie Amanda Stevens
Latest versionTemplate:Extension#version 1.0 (2009-09-06)
MediaWikiTemplate:Extension#mediawiki 1.20 - 1.25
Database changesTemplate:Extension#needs-updatephp Yes
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Added rightsTemplate:Extension#rights


Hooks usedTemplate:Extension#hook

Translate the SpecialNamespaces extension if it is available at translatewiki.net

Check usage and version matrix.
The current version of this extension (for MW 1.20-1.25) is in the git repository. Any code stored on-wiki is for earlier MediaWiki releases (where the current extension may not be compatible).

The SpecialNamespaces extension allows administrators to create and modify custom namespaces without directly editing the configuration files. It is based on Extension:Interwiki code, originally released under GPL by Stephanie Amanda Stevens. This extension requires memcached.


This code was intended to be a short-lived 'kludge', adapting or twisting an existing extension to fill a new task.

There was one branch ("wikidata") of MediaWiki 1.6 which included a partially-complete Special:Namespaces editor. Namespaces could simply be created, renamed or removed using a handy web interface. While some of the proposed capabilities (such as automatic moves of existing pages into the new namespaces) hadn't been implemented, Special:Namespaces did appear to have the makings of a useful tool.

A Special:Namespaces page was proposed for inclusion in core MediaWiki code from version 1.7 onward, but this never happened. While some of the code was used in OmegaWiki, the main MediaWiki package still lacks a built-in namespace editor.

As some wikis (including a few in the Uncyclopedia Babel series) were actively using Special:Namespaces (MW1.6-wikidata) in 2006, a need arose to preserve at least minimal namespaces functionality despite site upgrades to newer MediaWiki versions. As the original Special:Interwiki is GPL'ed, a modified version was hastily contrived to provide Special:Namespaces functions. This 'temporary solution' unfortunately still exists.

While the extension has been updated once (to incorporate changes made to the original Special:Interwiki), it is unsupported code and is neither created nor maintained by any of the authors of the original Special:Interwiki extension.


The current source code for the extension is in Wikimedia revision control; any on-wiki source code is intended solely for previous or obsolete versions of MediaWiki.

The extension must be invoked from LocalSettings.php:

require_once( "$IP/extensions/SpecialNamespaces/SpecialNamespaces.php" );

Once this is done, run maintenance/update.php to create the namespace_names table. (Some versions, including any for MediaWiki < 1.18, require the table be created manually.) The table description is packaged with the extension as a separate file; if running the update script fails to create the table, import namespace_names.sql manually.

MediaWiki 1.18-1.19[edit]

The code provided for MediaWiki 1.16 (below) can be made to work with MW 1.18+ by making changes to SpecialNamespaces_body.php to search and replace Xml::hidden with HTML::hidden at all points in which it appears in the extension code. For instance:

Xml::hidden( 'wpNamespacesAction', $action ) .
$old .
Xml::hidden( 'wpEditToken', $token ) .

must become:

Html::hidden( 'wpNamespacesAction', $action ) .
$old .
Html::hidden( 'wpEditToken', $token ) .

Note: The restrictions on use of $wgExtraNamespaces are more rigid in the current MediaWiki and extension set. An attempt to rename any of the pre-defined namespaces may cause the wiki not to function correctly; a long list of extension default namespaces has also been created for various existing extensions, some of which add themselves to $wgExtraNamespaces silently. Users of DPLforum, for instance, now encounter a coded default namespace of 110: for that extension - if your wiki uses another namespace for Forum: as 110 is being used for something else, this will not function correctly after an upgrade to the current versions of all code.

Installation is otherwise identical to that for MW 1.16 and 1.17 sites.

MediaWiki 1.16-1.17[edit]

1. Copy the code from Extension:SpecialNamespaces/sourcecode (five source files) to individual files under extensions/Namespaces/

2. Create database table namespace_names with the following SQL query: (Make sure to add your wiki's table prefix if there is one, e.g. mw_)

CREATE TABLE `mw_namespace_names` (
  `ns_id` int(8) NOT NULL default '0',
  `ns_name` varchar(200) NOT NULL default '',
  `ns_default` tinyint(1) NOT NULL default '0',
  `ns_canonical` tinyint(1) default NULL

3. Add require_once('extensions/Namespaces/SpecialNamespaces.php'); to LocalSettings.php

4. Assign the necessary permissions in LocalSettings.php to allow specific user groups to edit namespaces:

$wgGroupPermissions['sysop']['namespaces'] = true;

5. Installation can be verified through the Special:Version page of your wiki

6. ??? - Profit!

Older MediaWiki versions (1.07 - 1.15)[edit]

1. Copy the code from Extension:SpecialNamespaces/sourcecode (ver 0.1) to extensions/SpecialNamespaces.php

2. Create database table namespace_names with the following SQL query (if it doesn't exist already):

CREATE TABLE `namespace_names` (
  `ns_id` int(8) NOT NULL default '0',
  `ns_name` varchar(200) NOT NULL default '',
  `ns_default` tinyint(1) NOT NULL default '0',
  `ns_canonical` tinyint(1) default NULL

3. Add one line to languages/Language.php, insert it immediately before the call to fixUpSettings():

        function load() {
                if ( !$this->mLoaded ) {
                        self::loadLocalisation( $this->getCode() );
                        $cache =& self::$mLocalisationCache[$this->getCode()];
                        foreach ( self::$mLocalisationKeys as $key ) {
                                $this->$key = $cache[$key];
                        $this->mLoaded = true;

/*** inserted code for Special:Namespaces extension ***/
                        wfRunHooks( 'LanguageNamespaces', array( &$this->namespaceNames, &$this->namespaceAliases, $this->getCode() ) );
/*** end of inserted code ***/


4. Add require_once('extensions/SpecialNamespaces.php'); to LocalSettings.php

5. Assign 'namespaces' permission to groups authorised to edit namespaces:

$wgGroupPermissions['sysop']['namespaces'] = true;

6. Installation can be verified through the Special:Version page of your wiki.

(If replacing MW1.6-wikidata with some subsequent MediaWiki version, the `namespace` and `namespace_names` tables will already exist. This extension ignores the `namespace` portion and uses `namespace_names` in a compatible manner so that any existing MW1.6-wikidata custom namespaces will continue to operate normally.)


  • When creating new namespaces (as opposed to mere aliases for existing namespaces), it is normally advisable that 'default' and 'canonical' both be set to 1. Custom namespaces are each numbered, with 0-15 being reserved for MediaWiki's built-in namespaces. The convention of using even numbers (n) for primary namespaces and odd (n+1) for the corresponding talk pages still applies.
  • When renaming any of the existing MediaWiki namespaces (0-15), in most cases you will want the new name to be default (1) but not canonical (0). Setting both default and canonical to zero is only advisable if the name is merely an alias, used as an alternate link for something already listed.
  • The extension is relying heavily on memcached to store all of the information which it initially read from the database; this may cause problems in an environment in which multiple webservers are operating with one shared memcache and database serving MediaWiki installations across multiple machines. The scalability of this extension is therefore unknown.
  • This extension does not check for nor resolve existing page names that conflict with the names of new namespaces. There is a command-line utility provided as part of the base MediaWiki package that can move pages that are inaccessible due to naming conflicts:
php maintenance/namespaceDupes.php --fix

See Manual:Namespace and Manual:Using custom namespaces for more information on using namespaces in MediaWiki installations.

Known bugs (version 1.0)[edit]

  • Because the extension now sets $wgExtraNamespaces and $wgNamespaceAliases by standard means (instead of relying on a patch to add a hook in core MediaWiki code), the 'canonical' bit is in most instances now ignored. The only case where the extension currently uses the 'canonical' flag is for namespaces 4/5 (project:, project_talk:) where setting the bit will cause $wgSitename, $wgMetaNamespace and/or $wgMetaNamespaceTalk to be modified.
  • Localisation into other languages is currently incomplete. While some of the common text ('add', 'edit', 'delete', 'yes', 'no') may be obtained from existing localisations of other code, table column names and descriptions are often not translated.
  • Validity checks on input data are presently weak; they should be tightened to require ns_id be numeric and ns_name to be free of ' ', ':' or other non-alphanumeric characters (the space ' ' must be replaced with an underscore '_' in namespace names).
  • Deleting a namespace through the web interfaces also deletes any identically-numbered aliases to the (same number) namespace.
  • The 'namespace_names' table must already exist or be created manually; this could be improved (for recent MW versions, 1.17+) by adding update.php support which is currently lacking.
  • There is no means provided from the web interface to mass-move pages to a new namespace from mainspace, or to move remaining pages out of a namespace before deleting/renumbering a namespace prefix. While a command-line utility maintenance/namespaceDupes.php included with MediaWiki is a useful tool for moving pages rendered inaccessible by names conflicting with namespace prefixes, there is no web interface included with that script.

Known bugs (version 0.1)[edit]

The original (version 0.1) code is not recommended for new installations, but appears here as a historical record and for use in installations operating under previous MediaWiki versions.

  • This version of the extension is based on an outdated version of the extension:Interwiki code base. It also uses a patch to core MediaWiki code, which will create problems when upgrading MediaWiki. Localization strings (such as the individual table column names) will need to be set manually (as [[MediaWiki: namespace messages) after upgrade to MediaWiki 1.16; users of this MediaWiki version are therefore advised to use the new version of the namespaces extension.
  • The project: namespace (namespace #4) is a special case in that Languages.php:fixUpSettings() will automatically insert the name of your project (as listed in LocalSettings). If you wish to be able to use the Special:Namespaces page to rename the project namespace, fixUpSettings() will need to be updated to check for this.
To verify that Project: namespace hasn't already been renamed in Special:Namespaces, change fixUpSettings to replace:
$this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
if (!$this->namespaceNames[NS_PROJECT])
$this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
  • If using this code to create aliases to MediaWiki's built-in namespaces under MediaWiki 1.14, it appears that getCanonicalIndex() is not returning the proper namespace name -> namespace number conversion for these aliases. This routine is called from Languages.php and is needed to cause tags such as [[category: to be flagged for special handling.

See also[edit]

  • Help:Namespaces and Manual:Namespace for general info on the use of namespaces in MediaWiki.
  • Special page to work with the interwiki table, from which this code was blatantly stolen. All install requirements there, including setting privilege levels to edit the data, also apply here.
  • Namespace manager as originally proposed for MW1.6-wikidata and its successors. This functionality exists in OmegaWiki but is not in the mainstream MediaWiki software. Nominally still part of the MediaWiki roadmap as of version 1.17+ but not yet implemented in core code.
  • OmegaWiki, based on MediaWiki 1.10alpha (r26222), is the successor to WikiData 1.6
  • Extension:Configure allows web-based control over most or all of the standard LocalSettings.php settings. It should be capable of allowing bureaucrats to add extra namespaces, but beware: it is a powerful tool which by default allows bureaucrats to make fundamental wiki configuration changes affecting filesystem paths and executables, more than a few of which could disable a wiki entirely if misused. It is primarily a system administration tool.