Extension:RestrictiveRights

From MediaWiki.org

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

Release status: beta

Implementation User rights
Description Any user permission set to false is dominant.
Author(s) Jim Hu
Last Version 0.1 (5/17/2008)
MediaWiki 1.12.0
License MIT
Download see below

Contents

[edit] Usage

MW group permissions are inherited so that true always overrides false. This reverses that behavior, so that changing $wgGroupPermissions to false in LocalSettings always overrides true. This is useful when creating new groups with subsets of the permissions granted to the 'user' group. For example, consider a school with a wiki. The admin wants to let teachers create accounts for each other and for students, but doesn't want students to be able to create additional accounts. This can be done by creating a supergroup 'teacher' with more rights than regular users (students), but it requires remembering to set those permissions each time a teacher is created. With RestrictiveRights, you would do it like this:

$wgGroupPermissions['*']['createaccount']   = false;
$wgGroupPermissions['user']['createaccount']   = true;
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['student']['createaccount'] = false;

Here, the extra group is 'student', and student permission to create accounts is explicitly blocked in LocalSettings.php (and you have to remember to put new student accounts in group 'student' ). Which way is optimal just depends on what you want the default to be. Note that using RestrictiveRights does not prevent doing it the other way, but it allows you the choice.

Note that this will only apply to groups that are in the groups table in the MW schema, i.e. sysop, bureaucrat, and any custom groups.

[edit] Installation

Save code as RestrictiveRights.php. Adjust LocalSettings.php

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

[edit] Code

<?php
/*
The MIT License
Copyright © <2006-2008> <Jim Hu>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
 
Versions
0.11 
 
*/
# Not a valid entry point, skip unless MEDIAWIKI is defined
if (!defined('MEDIAWIKI')) {
        echo <<<EOT
To install this extension, put the following line in LocalSettings.php:
require_once( "$IP/extensions/RestrictiveRights.php" );
EOT;
        exit( 1 );
}
 
$wgExtensionCredits['other'][] = array(
	'name' => 'RestrictiveRights',
	'author' => 'Jim Hu',
	'version' => '0.11',
	'description' => 'Change rights so explicit false is dominant',
	'url' => 'http://www.mediawiki.org/wiki/Extension:RestrictiveRights'
);
 
$wgHooks['UserGetRights'][] = 'efRestrictiveRights';
 
function efRestrictiveRights($user, &$rights){
	global $wgGroupPermissions;
	#print_r($rights);
	foreach ($user->getGroups() as $group){
		foreach ($wgGroupPermissions[$group] as $act => $permission){
			if ($wgGroupPermissions[$group][$act] === false) unset ($rights[array_search($act, $rights)]);
		}		
	}
	#print_r($rights);
	return true;
}

[edit] See also

Personal tools