Extension:NamespaceProtection

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
NamespaceProtection

Release status:Extension status beta

ImplementationTemplate:Extension#type User rights
DescriptionTemplate:Extension#description Provides namespace protection capabilities built into version 1.10 for prior versions
Author(s)Template:Extension#username Lisa Ridley (Hoggwild5talk)
Latest versionTemplate:Extension#version 0.9 beta (29 May 2007)
MediaWikiTemplate:Extension#mediawiki MediaWiki versions prior to 1.10.x (0tested on version 1.6.10)
LicenseTemplate:Extension#license GPL
Download Code below
Hooks usedTemplate:Extension#hook
userCanManual:Hooks/userCan

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

Check usage and version matrix.

What can this extension do?[edit]

In MediaWiki version 1.10, namespace protection capability is a newly available function that provides the capability to protect pages in entire namespaces from editing, moving, etc by unauthorized users.

This is accomplished by establishing namespace protection definitions for those namespaces you wish to protect, which are assigned to an array called $wgNamespaceProtection. A custom user group is then created that has the namespace protection definitions assigned to it through $wgGroupPermissions. Finally, users are assigned to the custom user group through the Special:Userrights page (which must be done by bureaucrats or others with userright permissions).

Once this is completed, any users assigned to the custom group that has the associated namespace protection definitions will have edit access to the articles in the assigned namespace.

Compatibility[edit]

  • MediaWiki versions prior to 1.10.x.
  • Currently tested and working on 1.6.10.

Note: this extension is not meant to be used with MediaWiki versions 1.10 or later because this capability already exists starting with version 1.10. Please do not leave questions asking me to troubleshoot MediaWiki version 1.10.x, 1.11.x, or 1.12.x. Any questions for these versions will be deleted with no response.

Example[edit]

1. Establish a custom namespace called "Custom1", and the associated talk space called "Custom1 Talk" by adding the following to LocalSettings.php:

  $wgExtraNamespaces = array (100 => "Custom1", 101 => "Custom1 Talk");

2. Establish a namespace protection definition by adding the following to LocalSettings.php:

  $wgNamespaceProtection[100] = array('edit100');

3. Establish a new user group with the namespace protection definitions for the "Custom1" namespace by adding the following to LocalSettings.php:

  $wgGroupPermissions['Custom1' ]['edit100'] = true;

4. Assign users to the "Custom1" usergroup through the Special:Userrights page (must have 'userrights' permissions to do this; by default any user in the "bureaucrat" group can do this.

Once this is completed, only users assigned to the "Custom1" user group will have edit access to the articles in the namespace "Custom1".

To give sysops the ability to edit pages in the "Custom1" namespace, insert the following in LocalSettings.php as well:

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

Installation / Changes to LocalSettings.php[edit]

Save the code below in your extensions folder of your MediaWiki installation as NamespaceProtection.php. Add the custom namespace permissions and custom group permissions (following the example above). Add the following to the end of LocalSettings.php to activate the extension:

  require_once('extensions/NamespaceProtection.php');

Code[edit]

Copy the following code and save as "extensions/NamespaceProtection.php":

<?php
if(! defined( 'MEDIAWIKI' ) ) {
   echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
   die( -1 );
} else {
/**
 * Extension: NamespaceProtection.php
 * Created: 2007-12-09
 * Author: Lisa Ridley
 * Version: 0.91 beta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You can find a copy of the GNU General Public License at http://www.gnu.org/copyleft/gpl.html
 * A paper copy can be obtained by writing to:  Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Namespace Protection
 *
 * Allows definition of limited rights for namespaces.
 *
 *
 * Usage:  define Namespace protections in LocalSettings.php, and set up $wgGroupPermissions to go with NamespaceProtections.
 * Assign users to new groups set up with $wgGroupPermissions to allow them to edit namespace with protection.
 *
 * Save this file in your extensions folder of your MediaWiki installation.  Add the following to LocalSettings.php:
 *
 * The following example illustrates how to define a namespace protection called "edit100" for custom namespace "Custom1",
 * and set up a new group called "Custom1" with edit access.  To allow users edit access to "Custom1", assign user rights
 * by assigning users to group "Custom1" through the Special:Userrights page.

//Add the following lines to LocalSettings.php

//sets edit access to articles vs talk pages
$wgNamespaceProtection = array();
$wgNamespaceProtection[100] = array('edit100');
//Define your custom namespaces
$wgExtraNamespaces =
array(100 => "Custom1",
101 => "Custom1 Talk"
);
//Define custom Group Permissions for custom namespace
$wgGroupPermissions['Custom1' ]['edit100'] = true;

//Implement extension
require_once('extensions/NamespaceProtection.php');

 **/

global $wgHooks;

/* use the userCan hook to check user page edit permissions */
  $wgHooks[ 'userCan' ][] = 'fnNamespaceProtection';

/* register extension */
$wgExtensionCredits['other'][] = array(
   'name'=>'NamespaceProtection',
   'author' => 'Lisa Ridley',
   'version' => '0.9 beta',
   'url' => 'http://www.mediawiki.org/wiki/Extension:NamespaceProtection',
   'description' => 'This Extension adds the capability to add namespace protection to MW versions prior to version 1.10');

function fnNamespaceProtection( &$title, &$user, $action, &$result )
{
    global $wgUser, $wgNamespaceProtection;

    if ( array_key_exists( $title->mNamespace, $wgNamespaceProtection ) ) {
	   $nsProt = $wgNamespaceProtection[ $title->mNamespace ];
	   if ( !is_array($nsProt) ) $nsProt = array($nsProt);
	   foreach( $nsProt as $right ) {
	      if( '' != $right && !$user->isAllowed( $right ) ) {
		     $result = false;
		  }
   	   }
	}
    return true;
}
}
?>

MediaWiki Versions[edit]

This extension has been tested and appears to work fine on MediaWiki version 1.6.10. Once the extension has been fully tested (probably over the next 30 days) this page will be updated and the extension will be released as a stable version.