[Fusionforge-commits] r11114 - in trunk/src: common/include plugins/mediawiki/common plugins/mediawiki/www

Roland Mas lolando at libremir.placard.fr.eu.org
Thu Oct 21 16:04:26 CEST 2010


Author: lolando
Date: 2010-10-21 16:04:26 +0200 (Thu, 21 Oct 2010)
New Revision: 11114

Modified:
   trunk/src/common/include/RBAC.php
   trunk/src/plugins/mediawiki/common/MediaWikiPlugin.class.php
   trunk/src/plugins/mediawiki/www/LocalSettings.php
Log:
One more hook to simplify RBAC in plugins, and usage in Mediawiki

Modified: trunk/src/common/include/RBAC.php
===================================================================
--- trunk/src/common/include/RBAC.php	2010-10-21 13:47:45 UTC (rev 11113)
+++ trunk/src/common/include/RBAC.php	2010-10-21 14:04:26 UTC (rev 11114)
@@ -699,6 +699,16 @@
 			}
 			return $value ;
 			break ;
+		default:
+			$hook_params = array ();
+			$hook_params['role'] = $this ;
+			$hook_params['section'] = $section ;
+			$hook_params['reference'] = $reference ;
+			$hook_params['value'] = $value ;
+			$hook_params['result'] = 0 ;
+			plugin_hook_by_reference ("role_get_setting", $hook_params);
+			return $hook_params['result'] ;
+			break ;
 		}
 	}
 

Modified: trunk/src/plugins/mediawiki/common/MediaWikiPlugin.class.php
===================================================================
--- trunk/src/plugins/mediawiki/common/MediaWikiPlugin.class.php	2010-10-21 13:47:45 UTC (rev 11113)
+++ trunk/src/plugins/mediawiki/common/MediaWikiPlugin.class.php	2010-10-21 14:04:26 UTC (rev 11114)
@@ -46,6 +46,7 @@
 		$this->hooks[] = "role_normalize";
 		$this->hooks[] = "role_translate_strings";
 		$this->hooks[] = "role_has_permission";
+		$this->hooks[] = "role_get_setting";
 		$this->hooks[] = "list_roles_by_permission";
 		$this->hooks[] = "project_admin_plugins"; // to show up in the admin page for group
 	}
@@ -212,6 +213,41 @@
 			$right->setDescription (_('Mediawiki administrative tasks')) ;
 			$right->setValueDescriptions (array ('0' => _('No administrative access'),
 							     '1' => _('Edit interface, import XML dumps'))) ;
+		} elseif ($hookname == "role_get_setting") {
+			$role = $params['role'] ;
+			$reference = $params['reference'] ;
+			$value = $params['value'] ;
+
+			switch ($params['section']) {
+			case 'plugin_mediawiki_read':
+				if ($role->hasPermission('project_admin', $reference)) {
+					$params['result'] = 1 ;
+				} else {
+					$params['result'] =  $value ;
+				}
+				break ;
+			case 'plugin_mediawiki_edit':
+				if ($role->hasPermission('project_admin', $reference)) {
+					$params['result'] = 3 ;
+				} else {
+					$params['result'] =  $value ;
+				}
+				break ;
+			case 'plugin_mediawiki_upload':
+				if ($role->hasPermission('project_admin', $reference)) {
+					$params['result'] = 2 ;
+				} else {
+					$params['result'] =  $value ;
+				}
+				break ;
+			case 'plugin_mediawiki_admin':
+				if ($role->hasPermission('project_admin', $reference)) {
+					$params['result'] = 1 ;
+				} else {
+					$params['result'] =  $value ;
+				}
+				break ;
+			}
 		} elseif ($hookname == "role_has_permission") {
 			switch ($params['section']) {
 			case 'plugin_mediawiki_read':

Modified: trunk/src/plugins/mediawiki/www/LocalSettings.php
===================================================================
--- trunk/src/plugins/mediawiki/www/LocalSettings.php	2010-10-21 13:47:45 UTC (rev 11113)
+++ trunk/src/plugins/mediawiki/www/LocalSettings.php	2010-10-21 14:04:26 UTC (rev 11114)
@@ -201,93 +201,28 @@
 			$gr = FusionForgeRoleToMediawikiGroupName ($r, $g) ;
 
 			// Read access
-			switch ($r->getVal('plugin_mediawiki_read', $g->getID())) {
-			case 0:
-				$wgGroupPermissions[$gr]['read'] = false;
-				break ;
-			case 1:
-				$wgGroupPermissions[$gr]['read'] = true;
-				break ;
-			}
+			$wgGroupPermissions[$gr]['read'] = $r->hasPermission ('plugin_mediawiki_read', $g->getID()) ;
 
 			// Day-to-day edit privileges
-			switch ($r->getVal('plugin_mediawiki_edit', $g->getID())) {
-			case 0:
-				$wgGroupPermissions[$gr]['edit']          = false;
-				$wgGroupPermissions[$gr]['createpage']    = false;
-				$wgGroupPermissions[$gr]['createtalk']    = false;
-				$wgGroupPermissions[$gr]['minoredit']     = false;
-				$wgGroupPermissions[$gr]['move']          = false;
-				$wgGroupPermissions[$gr]['delete']        = false;
-				$wgGroupPermissions[$gr]['undelete']      = false;
-				break ;
-			case 1:
-				$wgGroupPermissions[$gr]['edit']          = true;
-				$wgGroupPermissions[$gr]['createpage']    = false;
-				$wgGroupPermissions[$gr]['createtalk']    = false;
-				$wgGroupPermissions[$gr]['minoredit']     = false;
-				$wgGroupPermissions[$gr]['move']          = false;
-				$wgGroupPermissions[$gr]['delete']        = false;
-				$wgGroupPermissions[$gr]['undelete']      = false;
-				break ;
-			case 2:
-				$wgGroupPermissions[$gr]['edit']          = true;
-				$wgGroupPermissions[$gr]['createpage']    = true;
-				$wgGroupPermissions[$gr]['createtalk']    = true;
-				$wgGroupPermissions[$gr]['minoredit']     = true;
-				$wgGroupPermissions[$gr]['move']          = false;
-				$wgGroupPermissions[$gr]['delete']        = false;
-				$wgGroupPermissions[$gr]['undelete']      = false;
-				break ;
-			case 3:
-				$wgGroupPermissions[$gr]['edit']          = true;
-				$wgGroupPermissions[$gr]['createpage']    = true;
-				$wgGroupPermissions[$gr]['createtalk']    = true;
-				$wgGroupPermissions[$gr]['minoredit']     = true;
-				$wgGroupPermissions[$gr]['move']          = true;
-				$wgGroupPermissions[$gr]['delete']        = true;
-				$wgGroupPermissions[$gr]['undelete']      = true;
-				break ;
-			}
+			$wgGroupPermissions[$gr]['edit']          = $r->hasPermission ('plugin_mediawiki_edit', $g->getID(), 'editexisting') ;
+			$wgGroupPermissions[$gr]['createpage']    = $r->hasPermission ('plugin_mediawiki_edit', $g->getID(), 'editnew') ;
+			$wgGroupPermissions[$gr]['createtalk']    = $r->hasPermission ('plugin_mediawiki_edit', $g->getID(), 'editnew') ;
+			$wgGroupPermissions[$gr]['minoredit']     = $r->hasPermission ('plugin_mediawiki_edit', $g->getID(), 'editnew') ;
+			$wgGroupPermissions[$gr]['move']          = $r->hasPermission ('plugin_mediawiki_edit', $g->getID(), 'editmove') ;
+			$wgGroupPermissions[$gr]['delete']        = $r->hasPermission ('plugin_mediawiki_edit', $g->getID(), 'editmove') ;
+			$wgGroupPermissions[$gr]['undelete']      = $r->hasPermission ('plugin_mediawiki_edit', $g->getID(), 'editmove') ;
 
 			// File upload privileges
-			switch ($r->getVal('plugin_mediawiki_upload', $g->getID())) {
-			case 0:
-				$wgGroupPermissions[$gr]['upload']        = false;
-				$wgGroupPermissions[$gr]['reupload-own']  = false;
-				$wgGroupPermissions[$gr]['reupload']      = false;
-				$wgGroupPermissions[$gr]['upload_by_url'] = false;
-				break ;
-			case 1:
-				$wgGroupPermissions[$gr]['upload']        = true;
-				$wgGroupPermissions[$gr]['reupload-own']  = true;
-				$wgGroupPermissions[$gr]['reupload']      = false;
-				$wgGroupPermissions[$gr]['upload_by_url'] = false;
-				break ;
-			case 2:
-				$wgGroupPermissions[$gr]['upload']        = true;
-				$wgGroupPermissions[$gr]['reupload-own']  = true;
-				$wgGroupPermissions[$gr]['reupload']      = true;
-				$wgGroupPermissions[$gr]['upload_by_url'] = true;
-				break ;
-			}
+			$wgGroupPermissions[$gr]['upload']        = $r->hasPermission ('plugin_mediawiki_upload', $g->getID(), 'upload') ;
+			$wgGroupPermissions[$gr]['reupload-own']  = $r->hasPermission ('plugin_mediawiki_upload', $g->getID(), 'upload') ;
+			$wgGroupPermissions[$gr]['reupload']      = $r->hasPermission ('plugin_mediawiki_upload', $g->getID(), 'reupload') ;
+			$wgGroupPermissions[$gr]['upload_by_url'] = $r->hasPermission ('plugin_mediawiki_upload', $g->getID(), 'reupload') ;
 
 			// Administrative tasks
-			switch ($r->getVal('plugin_mediawiki_admin', $g->getID())) {
-			case 0:
-				$wgGroupPermissions[$gr]['editinterface'] = false;
-				$wgGroupPermissions[$gr]['import']        = false;
-				$wgGroupPermissions[$gr]['importupload']  = false;
-				$wgGroupPermissions[$gr]['siteadmin']     = false;
-				break ;
-			case 1:
-				$wgGroupPermissions[$gr]['editinterface'] = true;
-				$wgGroupPermissions[$gr]['import']        = true;
-				$wgGroupPermissions[$gr]['importupload']  = true;
-				$wgGroupPermissions[$gr]['siteadmin']     = true;
-				break ;
-			}
-
+			$wgGroupPermissions[$gr]['editinterface'] = $r->hasPermission ('plugin_mediawiki_admin', $g->getID()) ;
+			$wgGroupPermissions[$gr]['import']        = $r->hasPermission ('plugin_mediawiki_admin', $g->getID()) ;
+			$wgGroupPermissions[$gr]['importupload']  = $r->hasPermission ('plugin_mediawiki_admin', $g->getID()) ;
+			$wgGroupPermissions[$gr]['siteadmin']     = $r->hasPermission ('plugin_mediawiki_admin', $g->getID()) ;
 		}
 
                 $user->setCookies ();




More information about the Fusionforge-commits mailing list