In addition to the built-in namespaces, it is possible to add custom namespaces to a MediaWiki installation, to further separate content and allow more logical organization.
Custom namespaces are simple to manage using the $wgExtraNamespaces
configuration directive. It is also possible to define alias names for custom (and also predefined) namespaces, using the $wgNamespaceAliases
configuration directive. Some extensions make it easy for you to create custom namespaces. Examples include NamespaceManager and BlueSpiceNamespaceManager .
It is recommended to ensure there are no pending jobs in the
job queuebefore manipulating namespaces, to avoid such jobs from failing if they target pages from namespaces you are about to delete or rename. Use
runJobs.phpto run all pending jobs and clear the queue before manipulating namespace configuration.
Creating a custom namespace[edit]You register additional namespaces by adding them to the $wgExtraNamespaces
global variable to your "LocalSettings.php" file. All namespaces require a unique numerical index in this array. As an example of simple custom namespace creation, adding the following lines to the "LocalSettings.php" file defines a "Foo" namespace 3000 and its associated "Foo_talk" namespace. Note that having a talk namespace associated with your custom namespace is currently a hard requirement.
// Define constants for my additional namespaces. define("NS_FOO", 3000); // This MUST be even. define("NS_FOO_TALK", 3001); // This MUST be the following odd integer. // Add namespaces. $wgExtraNamespaces[NS_FOO] = "Foo"; $wgExtraNamespaces[NS_FOO_TALK] = "Foo_talk"; // Note underscores in the namespace name.
The uppercase part does not permit hyphens but they can still be safely added to the prefix title. Example:
$wgExtraNamespaces[NS_FOOFOO] = "Foo-Foo";
$wgNamespaceProtection
, $wgNamespacesWithSubpages
, or $wgExtraGenderNamespaces
.
You could go on to configure additional settings for your new namespace.
$wgNamespaceProtection[NS_FOO] = [ 'editfoo' ]; // permission "editfoo" required to edit the foo namespace $wgNamespacesWithSubpages[NS_FOO] = true; // subpages enabled for the foo namespace $wgGroupPermissions['sysop']['editfoo'] = true; // permission "editfoo" granted to users in the "sysop" group
$wgExtraNamespaces
must be completed during MediaWiki initialization, i.e. in case an extension etc. should work with the newly created custom namespace, make sure that you define and name them prior to invoking the respective extension. For instance it cannot be manipulated in a post-initialization hook like $wgExtensionFunctions
.
news:
is a URL protocol for NNTP newsgroups.
news
by the lowercased name of the protocol you wish to remove):
$wgUrlProtocols = array_diff( $wgUrlProtocols, array( 'news:' ) );
Extensions often add their own namespaces, such as the Flow extension's "Topic" namespace. The extension.json registration system has a namespaces
key for an extension to list its namespaces. From the Gadgets extension:
"namespaces": [ { "id": 2300, "constant": "NS_GADGET", "name": "Gadget", "protection": "gadgets-edit" }, { "id": 2301, "constant": "NS_GADGET_TALK", "name": "Gadget_talk" }, ]
You can also set other namespace-related settings here, such as whether it should be a content namespace or not; see Manual:Extension.json/Schema for the available properties.
If namespace registration is conditional (for example EventLogging only defines its "Schema" namespace on the wiki where it stores schemas), the extension should add "conditional": true
to the namespace definition in extension.json
, and also register a handler for the CanonicalNamespaces hook there which decides whether to register the namespace or not. The hook handler should only change the $namespaces
with which it is called; all other settings of the namespace should still be registered in the extension.json
. If those settings should also be dynamic, do not change $wgContentNamespaces
, $wgNamespaceContentModels
etc. in the CanonicalNamespaces hook handler (it will have no effect – T288819); instead, you will have to set them earlier, such as in a callback (not in $wgExtensionFunctions
).
Note that adding an extension to LocalSettings.php does not necessarily make relevant namespace constants available as globals for other extensions.
Content namespaces[edit]When building the site statistics page (see Special:Statistics), MediaWiki uses values stored in the database to calculate certain totals. One particular total is the "number of articles" or "number of content pages" figure.
For a page to be considered an article, or proper content, it must:
$wgArticleCountMethod
.When creating custom namespaces to hold additional content, it is a good idea to indicate this in the configuration. This is done via the $wgContentNamespaces configuration directive.
To extend the example above, one might add the following to the "LocalSettings.php" file:
$wgContentNamespaces[] = 3000;
$wgContentNamespaces[] = NS_FOO;
MediaWiki will now consider pages in the "Foo" namespace to be articles, if they meet the remaining criteria, and will include them when updating the site statistics counters.
Running maintenance scripts[edit]When adjusting the value of configuration parameter $wgContentNamespaces
, it is a good idea to run either the "path/to/maintenance/updateArticleCount.php or "path/to/maintenance/initSiteStats.php" script to update the internal statistics cache (see Manual:Maintenance scripts ).
There are several reasons you might want this:
When storing page records, MediaWiki uses a namespace's numerical index, along with the remaining title text. Thus, when a page is created in a namespace that doesn't exist, e.g. "Bar:Some page", it is treated as being in the main namespace.
This can cause problems if adding a custom namespace definition for "Bar" at a later date, as MediaWiki will look for a page indexed via the proper namespace, but won't be able to find it, thus making the content inaccessible.
You can use the NamespaceDupes maintenance script to correct this problem. It will find pages in the main namespace with a prefix matching any of the defined namespaces, and update their records.
If you are not able to run maintenance scripts, then the following approach might be suitable:
The problem addressed above also occurs when a custom namespace definition is removed; MediaWiki is no longer aware of the numerical index for the namespace, and attempts to search the main namespace for the desired pages, leading to inaccessible content. This is a rare occurrence, since most sites will not need namespaces removed, but it is a problem.
You can use the CleanupTitles maintenance script to correct this problem. It will find pages any namespace that is no longer defined, and update their records. The pages will be moved to the main namespace with an added prefix like NS123:, unless specified otherwise by parameters to the script.
As above, you can also temporarily restore the namespace configuration and move the pages from the user interface (or delete them).
Renaming custom namespaces[edit]Suppose that you need to rename custom namespace "Foo" to "New" without performing a mass move of pages. The easiest way to achieve this is to preserve the namespace ID (here "3000
") as well as the namespace constant (here "NS_FOO
"), modify the (visible) namespace title and add the old one as an alias.
change
define("NS_FOO", 3000); $wgExtraNamespaces[NS_FOO] = "Foo";
to
define("NS_FOO", 3000); $wgExtraNamespaces[NS_FOO] = "New"; $wgNamespaceAliases['Foo'] = NS_FOO;
Note that some extensions store namespace names in plain text instead of their internal IDs, and should therefore be dealt with extra care. Examples include:
In order for you to avoid namespace conflicts e.g. your namespace has the same number as a namespace defined by an extension, the extension namespace list shows you which numbers to avoid to prevent conflicts.
Defining $wgNamespacesToBeSearchedDefault , $wgNamespacesWithSubpages , $wgContentNamespaces or $wgNamespaceAliases for an ID not associated to any existing namespace in $wgExtraNamespaces doesn't break the wiki; MediaWiki gracefully ignores such configurations.
Styling namespaces[edit]For example, to set the background color of pages in a particular namespace (and its associated talk namespace) you can add the following code to your common.css:
.ns-3000 #content, .ns-3001 #content { background-color: #f3f3ff; } .ns-3000 div.thumb, .ns-3001 div.thumb { border-color: #f3f3ff; }
where 3000
is the namespace's index and #f3f3ff
is the color you want as its background color.
You might also want to change the name of the tab from its default (the namespace's name). This is located in your system messages at MediaWiki:nstab-namespace.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4