Extension:ExtraNamespaces

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
ExtraNamespaces

Release status: beta

Implementation  User interface
Description Adds the functionality of allowing Extra Namespaces to be declared in the MediaWiki namespace
Author(s)  Lisa Ridley
Last Version  0.92 beta (14 December 2008)
MediaWiki  versions 1.8.x and later
License GNU General Public License 2.0 or later
Download Code below
#Releases

check usage (experimental)

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/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
  • 1.13.2
  • 1.14alpha

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] Releases

Version Release date Comments
0.8 2008-03-02 Original version (broken)
0.92 2008-12-14 Fixed script; preliminary testing is successful; rereleased as beta version.

[edit] To Do

  • 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
/* ExtraNamespaces.php
 * Author:  Lisa Ridley (Hoggwild5)
 * Date:  14 December 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, create a folder (directory) called "ExtraNamespaces", and save this file as
 *
 *  /extensions/ExtraNamespaces/ExtraNamespaces.php
 *
 *  and place the following in your LocalSettings.php file before any other
 *  extensions are installed:
 *
 *  require_once("$IP/extensions/ExtraNamespaces/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.
 *
 */
 
if( !defined( 'MEDIAWIKI' ) ) {
	echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
	die( 1 );
}
 
$wgExtensionCredits['other'][] = array(
       'name' => 'ExtraNamespaces',
       'author' =>'Lisa Ridley',
       'version' => '0.9 beta (14 Dec 2008)',
       'url' => 'http://www.mediawiki.org/wiki/Extension:ExtraNamespaces',
       'description' => 'Allows for the definition of Extra Namespaces in the MediaWiki namespace.'
       );
 
## the following are loaded early because certain functions need to be available sooner; using require_once means they won't be
## loaded again later
require_once($IP . '/includes/GlobalFunctions.php');
require_once($IP . '/languages/Language.php');
require_once($IP . '/includes/ObjectCache.php');
require_once($IP . '/includes/StubObject.php');
require_once($IP . '/includes/AutoLoader.php');
$wgContLang = new StubContLang;
$wgMemc =& wfGetMainCache();
 
## calls the Namespace setup function.
fnExtraNamespaces();
 
function fnExtraNamespaces() {
    global $wgExtraNamespaces, $wgContLang, $wgMemc;
    $ExtraNamespaces = array();
 
    $revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, 'ExtraNamespaces' ) );
    if( $revision ) {
    	$ens = explode( "\n", trim( $revision->getText() ) );
    }
    if( !$ens ){
    	return;
    }
    foreach ($ens as $en) {
    	$en = trim($en, '* ');
    	if (strpos($en, '|') !== false) { // sanity check
    	    $en = explode( '|' , $en);
    	    $enno = $en[0];
            $enname = $en[1];
            $ExtraNamespaces[$enno] = trim($enname);
        }
    }
    if( is_array( $wgExtraNamespaces ) ) {
	$wgExtraNamespaces = $wgExtraNamespaces + $ExtraNamespaces;
    } else {
	$wgExtraNamespaces = $ExtraNamespaces;
    }
}