Extension:ExtraNamespaces

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
ExtraNamespaces

Release status: unstable

Implementation User interface
Description Adds the functionality of allowing Extra Namespaces to be declared in the MediaWiki namespace
Author(s) Lisa Ridley
Version 0.8 (10 March 2008)
MediaWiki versions 1.8.x, 1.9.x, 1.10.x, 1.11.x
Download Code below

NOTE: The author has determined that this extension is broken. Do not use.

Contents

[edit] What can this extension do?

This extension allows the declaration of Extra Namespaces using a new interface page in the MediaWiki namespace. This process will take the place of declaring extra namespaces using the global configuration variable $wgExtraNamespaces in LocalSettings.php.

[edit] How does it work?

To set up the Extra Namespaces, create the page "MediaWiki:ExtraNamespaces" and enter the namespaces you wish to create in the following format:

* [namespace number] | [namespace name]

where the [namespace number] represents the custom namespace index number you're assigning to the namespace, and [namespace name] represents the custom namespace name you wish to use.

As with the declaration of custom namespaces using $wgExtraNamespaces, you need to make sure you create both the main custom namespace and the discussion namespace. For example:

* 100 | Custom
* 101 | Custom_Talk

creates a custom namespace called "Custom" and the corresponding discussion namespace called "Custom Talk" (remember to include the "_" instead of spaces in your custom namespace name -- MediaWiki will convert the "_" to " ").

Note: Any custom namespace declarations using $wgExtraNamespaces will conflict with the declarations in MediaWiki:ExtraNamespaces, so DO NOT use both this extension and the $wgExtraNamespaces global declaration in LocalSettings.php.

[edit] Installation

To install this extension, place the following in your LocalSettings.php file before any other extensions are installed:

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

It is important that this is the first extension loaded so that the custom namespace declarations are available before any other extensions are loaded.

[edit] MediaWiki Versions

This extension has been tested and verified to work with the following MediaWiki versions:

  • 1.11.x

While this extension has not been tested with versions 1.8.x, 1.9.x, and 1.10.x, the core functions that this extension utilizes are available in versions 1.8 and up, and this extension should function properly in all of the listed versions. If you install this extension in one of the versions not listed above and it indeed functions properly, please add your MediaWiki version number to the list above.

[edit] To Do

  • Fix the extension
  • Build in error checking for invalid custom namespace numbers
  • Build in error checking for incorrectly formatted namespace declaration lines (must be bulleted, with a "|" between the namespace index number and the namespace name for the namespace to be created correctly)
  • Build in a way to add comments to the ExtraNamespaces page and have them ignored by the parser

[edit] Code

<?php
if ( !defined( 'MEDIAWIKI' ) ) {
        echo "This file is part of MediaWiki, it is not a valid entry point.\n";
        exit( 1 );
} else {
 
/* ExtraNamespaces.php
 * Author:  Lisa Ridley (Hoggwild5)
 * Date:  10 March 2008
 *
 * This extension allows the declaration of Extra Namespaces using the
 *  MediaWiki namespace in your installation.  To set up the Extra Namespaces
 *  create the page "MediaWiki:ExtraNamespaces" and enter the namespaces you
 *  wish to create in the following format:
 *
 *   "* [namespace number] | [namespace name]"
 *
 *  where the [namespace number] represents the custom namespace index number
 *  you're assigning to the namespace, and [namespace name] represents the
 *  custom namespace name you wish to use.
 *
 * Any custom namespace declarations using $wgExtraNamespaces will conflict with
 *  the declarations in MediaWiki:ExtraNamespaces, so DO NOT use both this
 *  extension and the $wgExtraNamespaces global declaration in LocalSettings.php
 *
 * As with the declaration of custom namespaces, you need to make sure you create
 *  both the main custom namespace and the discussion namespace.  For example:
 *
 *  * 100 | Custom
 *  * 101 | Custom_Talk
 *
 *  creates a custom namespace called "Custom" and the corresponding discussion
 *  namespace called "Custom Talk" (remember to include the "_" instead of spaces
 *  in your custom namespace name -- MediaWiki will convert the "_" to " ".
 *
 * To install this extension, save this file as
 *
 *  /extensions/ExtraNamespaces.php
 *
 *  and place the following in your LocalSettings.php file before any other
 *  extensions are installed:
 *
 *  require_once("$IP/extensions/ExtraNamespaces.php");
 *
 *  It is important that this is the first extension loaded so that the custom
 *   namespace declarations are available before any other extensions are loaded.
 *
 */
$wgExtensionCredits['other'][] = array(
       'name' => 'ExtraNamespaces',
       'author' =>'Lisa Ridley',
       'version' => '0.8 beta',
       'url' => 'http://www.mediawiki.org/wiki/Extension:ExtraNamespaces',
       'description' => 'Allows for the definition of Extra Namespaces in the MediaWiki namespace.'
       );
$wgExtensionFunctions[]='fnExtraNamespaces';
function fnExtraNamespaces() {
    global $wgExtraNamespaces, $wgContLang;
    $wgExtraNamespaces = array();
    $ens = explode( "\n", wfMsgForContent( 'ExtraNamespaces' ) );
    foreach ($ens as $en) {
        $en = trim($en, '* ');
        if (strpos($en, '|') !== false) { // sanity check
            $en = explode( '|' , $en);
            $enno = $en[0];
            $enname = $en[1];
            $wgExtraNamespaces[$enno] = trim($enname);
        }
    }
    if( is_array( $wgExtraNamespaces ) ) {
        $wgContLang->fixUpSettings();
    }
}
}
Personal tools