GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing www.mediawiki.org — Manual:Using custom namespaces - MediaWiki 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 It is recommended to ensure there are no pending jobs in the job queue before manipulating namespaces, to avoid such jobs from failing if they target pages from namespaces you are about to delete or rename. Use runJobs.php to run all pending jobs and clear the queue before manipulating namespace configuration.
Creating a custom namespaceYou register additional namespaces by adding them to the // 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";
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
$wgUrlProtocols = array_diff( $wgUrlProtocols, array( 'news:' ) ); In extensions
Extensions often add their own namespaces, such as the Flow extension's "Topic" namespace.
The extension.json registration system has a "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 Note that adding an extension to LocalSettings.php does not necessarily make relevant namespace constants available as globals for other extensions.
Content namespacesWhen 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:
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 scriptsWhen adjusting the value of configuration parameter Why you would want a custom namespaceThere are several reasons you might want this:
Dealing with existing pagesWhen 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 If you are not able to run maintenance scripts, then the following approach might be suitable:
Removing custom namespacesThe 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 As above, you can also temporarily restore the namespace configuration and move the pages from the user interface (or delete them). Renaming custom namespacesSuppose 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 " 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:
Avoid namespace conflictsIn 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 namespacesThe simplest way of setting the background color of pages in a particular namespace (and its associated talk namespace) is by adding 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 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. See also
Site administrationExtensions
For extension developers
| ||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |