Implement #858 : split user assignment and group rights.
authorAntoine Musso <hashar@users.mediawiki.org>
Mon, 17 Jan 2005 11:45:47 +0000 (11:45 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Mon, 17 Jan 2005 11:45:47 +0000 (11:45 +0000)
includes/Defines.php
includes/HTMLForm.php
includes/SpecialGrouplevels.php [new file with mode: 0644]
includes/SpecialPage.php
includes/SpecialUserlevels.php
languages/Language.php
maintenance/archives/patch-group-sysopfix.sql
maintenance/archives/patch-userlevels-defaultgroups.sql
maintenance/updaters.inc

index c52b2de..4ce9ec9 100644 (file)
@@ -84,7 +84,7 @@ define( 'MW_MATH_MATHML', 5 );
  * database.
  */
 $wgAvailableRights = array('read', 'edit', 'move', 'delete', 'undelete',
-'protect', 'block', 'userrights', 'createaccount', 'upload', 'asksql',
-'rollback', 'patrol', 'editinterface', 'siteadmin', 'bot');
+'protect', 'block', 'userrights', 'grouprights', 'createaccount', 'upload',
+'asksql', 'rollback', 'patrol', 'editinterface', 'siteadmin', 'bot');
 
 ?>
index a13831f..1441fe7 100644 (file)
@@ -1,4 +1,9 @@
 <?php
+/**
+ * This file contain a class to easily build HTML forms as well as custom
+ * functions used by SpecialUserlevels.php and SpecialGrouplevels.php
+ */
+
 /**
  * Class to build various forms
  *
@@ -86,5 +91,63 @@ class HTMLForm {
                return "<div><label>".wfMsg( $this->mName.'-'.$varname ).
                        "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
        }
+} // end class
+
+
+// functions used by SpecialUserlevels & SpecialGrouplevels
+
+/** Build a select with all existent groups
+ * @param string $selectname Name of this element. Name of form is automaticly prefixed.
+ * @param array $selected Array of element selected when posted. Multiples will only show them.
+ * @param boolean $multiple A multiple elements select.
+ * @param integer $size Number of element to be shown ignored for non multiple (default 6).
+ * @param boolean $reverse If true, multiple select will hide selected elements (default false).
+*/
+function HTMLSelectGroups($selectname, $selected=array(), $multiple=false, $size=6, $reverse=false) {
+       $dbr =& wfGetDB( DB_SLAVE );
+       $group = $dbr->tableName( 'group' );
+       $sql = "SELECT group_id, group_name FROM $group";
+       $res = $dbr->query($sql,'wfSpecialAdmin');
+       
+       $out = wfMsg($selectname);
+       $out .= '<select name="'.$selectname;
+       if($multiple) { $out.='[]" multiple="multiple" size="'.$size; }
+       $out.= "\">\n";
+       
+       while($g = $dbr->fetchObject( $res ) ) {
+               if($multiple) {
+                       // for multiple will only show the things we want
+                       if(in_array($g->group_id, $selected) xor $reverse) { 
+                               $out .= '<option value="'.$g->group_id.'">'.$g->group_name."</option>\n";
+                       }
+               } else {
+                       $out .= '<option ';
+                       if(in_array($g->group_id, $selected)) { $out .= 'selected="selected" '; }
+                       $out .= 'value="'.$g->group_id.'">'.$g->group_name."</option>\n";
+               }
+       }
+       $out .= "</select>\n";
+       return $out;
+}
+
+/** Build a select with all existent rights
+ * @param array $selected Names(?) of user rights that should be selected.
+ * @return string HTML select.
+ */
+function HTMLSelectRights($selected='') {
+       global $wgAvailableRights;
+       $out = '<select name="editgroup-getrights[]" multiple="multiple">';
+       $groupRights = explode(',',$selected);
+       
+       foreach($wgAvailableRights as $right) {
+       
+               // check box when right exist
+               if(in_array($right, $groupRights)) { $selected = 'selected="selected" '; }
+               else { $selected = ''; }
+                                       
+               $out .= '<option value="'.$right.'" '.$selected.'>'.$right."</option>\n";
+       }
+       $out .= "</select>\n";
+       return $out;
 }
 ?>
diff --git a/includes/SpecialGrouplevels.php b/includes/SpecialGrouplevels.php
new file mode 100644 (file)
index 0000000..95411a1
--- /dev/null
@@ -0,0 +1,146 @@
+<?php
+/**
+ * Provide an administration interface
+ * DO NOT USE: INSECURE.
+ */
+
+/** */
+require_once('HTMLForm.php');
+require_once('Group.php');
+
+/** Entry point */
+function wfSpecialGrouplevels($par=null) {
+       global $wgRequest;
+       # Debug statement
+       // print_r($_POST);
+       $form = new GrouplevelsForm($wgRequest);
+       $form->execute();
+}
+
+/**
+ * A class to manage group levels rights.
+ */
+class GrouplevelsForm extends HTMLForm {
+       var $mPosted, $mRequest, $mSaveprefs;
+       /** Escaped local url name*/
+       var $action;
+
+       /** Constructor*/
+       function GrouplevelsForm ( &$request ) {
+               $this->mPosted = $request->wasPosted();
+               $this->mRequest = $request;
+               $this->mName = 'grouplevels';
+               
+               $titleObj = Title::makeTitle( NS_SPECIAL, 'Grouplevels' );
+               $this->action = $titleObj->escapeLocalURL();
+       }
+
+       /**
+        * Manage forms to be shown according to posted datas.
+        * Depending on the submit button used : Call a form or a saving function.
+        */
+       function execute() {
+               // show the general form
+               $this->switchForm();
+               if ( $this->mPosted ) {
+                       // show some more forms
+                       if($this->mRequest->getCheck('seditgroup')) {
+                               $this->editGroupForm( $this->mRequest->getVal($this->mName.'-group-edit') ); }
+                       if($this->mRequest->getCheck('saddgroup')) {
+                               $this->editGroupForm( ); }
+
+                       // save settings
+                       if($this->mRequest->getCheck('savegroup')) {
+                               $this->saveGroup($this->mRequest->getVal('editgroup-name'),
+                                                $this->mRequest->getVal('editgroup-oldname'),
+                                                $this->mRequest->getVal('editgroup-description'),
+                                                                $this->mRequest->getArray('editgroup-getrights'));
+                       }
+               }
+       }
+
+// save things !!
+       /**
+        * Save a group
+        * @param string $newname Group name.
+        * @param string $oldname Old (current) group name.
+        * @param string $description Group description.
+        *
+        * @todo FIXME : doesnt validate anything. Log is incorrect.
+        */
+       function saveGroup($newname, $oldname, $description, $rights) {
+               $newame = trim($newname);
+       
+               if($oldname == '') {
+               // We create a new group
+                       $g = new group();
+                       $g->addToDatabase();
+               } else {
+                       $g = Group::newFromName($oldname);
+               }
+               
+               // save stuff
+               $g->setName($newname);
+               $g->setDescription($description);
+               if(isset($rights)) { $g->setRights( implode(',',$rights) ); }
+               
+               $g->save();
+
+               $log = new LogPage( 'rights' );
+               $log->addEntry( 'rights', Title::makeTitle( NS_SPECIAL, $g->getName()) , ' '.$g->getRights() );
+
+       }
+
+       /**
+        * The entry form
+        * It allows a user to edit or eventually add a group
+        */
+       function switchForm() {
+               global $wgOut;
+               
+               // group selection              
+               $wgOut->addHTML( "<form name=\"ulgroup\" action=\"$this->action\" method=\"post\">\n" );
+               $wgOut->addHTML( $this->fieldset( 'lookup-group',
+                               HTMLSelectGroups($this->mName.'-group-edit', array(0 => $this->mRequest->getVal($this->mName.'-group-edit')) ) .
+                               ' <input type="submit" name="seditgroup" value="'.wfMsg('editgroup').'" />' .
+                               '<br /><input type="submit" name="saddgroup" value="'.wfMsg('addgroup').'" />'
+                       ));
+               $wgOut->addHTML( "</form>\n" );
+       }
+
+       /**
+        * Edit a group properties and rights.
+        * @param string $groupname Name of a group to be edited.
+        */
+       function editGroupForm($groupID = 0) {
+               global $wgOut;
+
+               if($this->mRequest->getVal('seditgroup')) {
+               // fetch data if we edit a group
+                       $g = Group::newFromID($groupID);
+                       $fieldname = 'editgroup';
+               } else {
+               // default datas when we add a group
+                       $g = new group();
+                       $fieldname = 'addgroup';
+               }
+
+               $gName = $g->getName();
+               $gDescription = $g->getDescription();
+
+
+               $wgOut->addHTML( "<form name=\"editGroup\" action=\"$this->action\" method=\"post\">\n".
+                               '<input type="hidden" name="editgroup-oldname" value="'.$gName.'" />');
+               $wgOut->addHTML( $this->fieldset( $fieldname,
+                       $this->textbox( 'editgroup-name', $gName ) .
+                       $this->textareabox( 'editgroup-description', $gDescription ) .
+                       '<br /><table border="0" align="center"><tr><td>'.
+                       HTMLSelectRights($g->getRights()).
+                       '</td></tr></table>'."\n".
+                       '<input type="submit" name="savegroup" value="'.wfMsg('savegroup').'" />'
+                       ));
+
+               $wgOut->addHTML( "</form>\n" );
+       }
+} // end class GrouplevelsForm
+?>
index d593c33..ac9b520 100644 (file)
@@ -97,6 +97,7 @@ $wgSpecialPages = array_merge($wgSpecialPages, array (
        'Unlockdb'              => new SpecialPage( 'Unlockdb', 'siteadmin' ),
        'Sitesettings'  => new SpecialPage( 'Sitesettings', 'siteadmin' ),
        'Userlevels'    => new SpecialPage( 'Userlevels', 'userrights' ),
+       'Grouplevels'   => new SpecialPage( 'Grouplevels', 'grouprights' ),
 ));
 
 /**
index 4f484a9..d82f44e 100644 (file)
@@ -2,6 +2,8 @@
 /**
  * Provide an administration interface
  * DO NOT USE: INSECURE.
+ * 
+ * TODO : remove everything related to group editing (SpecialGrouplevels.php)
  */
 
 /** */
@@ -44,60 +46,19 @@ class UserlevelsForm extends HTMLForm {
                $this->switchForm();
                if ( $this->mPosted ) {
                        // show some more forms
-                       if($this->mRequest->getCheck('seditgroup')) {
-                               $this->editGroupForm( $this->mRequest->getVal($this->mName.'-group-edit') ); }
-                       if($this->mRequest->getCheck('saddgroup')) {
-                               $this->editGroupForm( ); }
                        if($this->mRequest->getCheck('ssearchuser')) {
                                $this->editUserGroupsForm( $this->mRequest->getVal('user-editname')); }
 
                        // save settings
-                       if($this->mRequest->getCheck('savegroup')) {
-                               $this->saveGroup($this->mRequest->getVal('editgroup-name'),
-                                                $this->mRequest->getVal('editgroup-oldname'),
-                                                $this->mRequest->getVal('editgroup-description'),
-                                                                $this->mRequest->getVal('editgroup-getrights'));
-                       
-                       } elseif($this->mRequest->getCheck('saveusergroups')) {
+                       if($this->mRequest->getCheck('saveusergroups')) {
                                $this->saveUserGroups($this->mRequest->getVal('user-editname'),
-                                                     $this->mRequest->getVal($this->mName.'-groupsmember'),
-                                                     $this->mRequest->getVal($this->mName.'-groupsavailable'));
+                                                     $this->mRequest->getArray($this->mName.'-groupsmember'),
+                                                     $this->mRequest->getArray($this->mName.'-groupsavailable'));
                        }
                }
        }
 
 // save things !!
-       /**
-        * Save a group
-        * @param string $newname Group name.
-        * @param string $oldname Old (current) group name.
-        * @param string $description Group description.
-        *
-        * @todo FIXME : doesnt validate anything. Log is incorrect.
-        */
-       function saveGroup($newname, $oldname, $description, $rights) {
-               $newame = trim($newname);
-       
-               if($oldname == '') {
-               // We create a new group
-                       $g = new group();
-                       $g->addToDatabase();
-               } else {
-                       $g = Group::newFromName($oldname);
-               }
-               
-               // save stuff
-               $g->setName($newname);
-               $g->setDescription($description);
-               if(isset($rights)) { $g->setRights( implode(',',$rights) ); }
-               
-               $g->save();
-
-               $log = new LogPage( 'rights' );
-               $log->addEntry( 'rights', Title::makeTitle( NS_SPECIAL, $g->getName()) , ' '.$g->getRights() );
-
-       }
-
        /**
         * Save user groups changes in the database.
         * Datas comes from the editUserGroupsForm() form function
@@ -142,21 +103,11 @@ class UserlevelsForm extends HTMLForm {
 
        /**
         * The entry form
-        * It allows a user to select or eventually add a group as well as looking up
-        * for a username.
+        * It allows a user to look for a username and edit its groups membership
         */
        function switchForm() {
                global $wgOut;
                
-               // group selection              
-               $wgOut->addHTML( "<form name=\"ulgroup\" action=\"$this->action\" method=\"post\">\n" );
-               $wgOut->addHTML( $this->fieldset( 'lookup-group',
-                               $this->HTMLSelectGroups('group-edit', array(0 => $this->mRequest->getVal($this->mName.'-group-edit')) ) .
-                               ' <input type="submit" name="seditgroup" value="'.wfMsg('editgroup').'" />' .
-                               '<br /><input type="submit" name="saddgroup" value="'.wfMsg('addgroup').'" />'
-                       ));
-               $wgOut->addHTML( "</form>\n" );
-               
                // user selection
                $wgOut->addHTML( "<form name=\"uluser\" action=\"$this->action\" method=\"post\">\n" );
                $wgOut->addHTML( $this->fieldset( 'lookup-user',
@@ -166,41 +117,6 @@ class UserlevelsForm extends HTMLForm {
                $wgOut->addHTML( "</form>\n" );
        }
 
-       /**
-        * Edit a group properties and rights.
-        * @param string $groupname Name of a group to be edited.
-        */
-       function editGroupForm($groupID = 0) {
-               global $wgOut;
-
-               if($this->mRequest->getVal('seditgroup')) {
-               // fetch data if we edit a group
-                       $g = Group::newFromID($groupID);
-                       $fieldname = 'editgroup';
-               } else {
-               // default datas when we add a group
-                       $g = new group();
-                       $fieldname = 'addgroup';
-               }
-
-               $gName = $g->getName();
-               $gDescription = $g->getDescription();
-
-
-               $wgOut->addHTML( "<form name=\"editGroup\" action=\"$this->action\" method=\"post\">\n".
-                               '<input type="hidden" name="editgroup-oldname" value="'.$gName.'" />');
-               $wgOut->addHTML( $this->fieldset( $fieldname,
-                       $this->textbox( 'editgroup-name', $gName ) .
-                       $this->textareabox( 'editgroup-description', $gDescription ) .
-                       '<br /><table border="0" align="center"><tr><td>'.
-                       $this->HTMLSelectRights($g->getRights()).
-                       '</td></tr></table>'."\n".
-                       '<input type="submit" name="savegroup" value="'.wfMsg('savegroup').'" />'
-                       ));
-
-               $wgOut->addHTML( "</form>\n" );
-       }
-
        /**
         * Edit user groups membership
         * @param string $username Name of the user.
@@ -226,67 +142,14 @@ class UserlevelsForm extends HTMLForm {
                $wgOut->addHTML( $this->fieldset( 'editusergroup',
                        wfMsg('editing', $this->mRequest->getVal('user-editname')).".<br />\n" .
                        '<table border="0" align="center"><tr><td>'.
-                       $this->HTMLSelectGroups('groupsmember', $groups,true,6).
+                       HTMLSelectGroups($this->mName.'-groupsmember', $groups,true,6).
                        '</td><td>'.
-                       $this->HTMLSelectGroups('groupsavailable', $groups,true,6,true).
+                       HTMLSelectGroups($this->mName.'-groupsavailable', $groups,true,6,true).
                        '</td></tr></table>'."\n".
                        '<p>'.wfMsg('userlevels-groupshelp').'</p>'."\n".
                        '<input type="submit" name="saveusergroups" value="'.wfMsg('saveusergroups').'" />'
                        ));
                $wgOut->addHTML( "</form>\n" );
        }
-
-
-       /** Build a select with all existent groups
-        * @param string $selectname Name of this element. Name of form is automaticly prefixed.
-        * @param array $selected Array of element selected when posted. Multiples will only show them.
-        * @param boolean $multiple A multiple elements select.
-        * @param integer $size Number of element to be shown ignored for non multiple (default 6).
-        * @param boolean $reverse If true, multiple select will hide selected elements (default false).
-       */
-       function HTMLSelectGroups($selectname, $selected=array(), $multiple=false, $size=6, $reverse=false) {
-               $selectname = $this->mName.'-'.$selectname;
-               $dbr =& wfGetDB( DB_SLAVE );
-               $group = $dbr->tableName( 'group' );
-               $sql = "SELECT group_id, group_name FROM $group";
-               $res = $dbr->query($sql,'wfSpecialAdmin');
-               
-               $out = wfMsg($selectname);
-               $out .= '<select name="'.$selectname;
-               if($multiple) { $out.='[]" multiple="multiple" size="'.$size; }
-               $out.= "\">\n";
-               
-               while($g = $dbr->fetchObject( $res ) ) {
-                       if($multiple) {
-                               // for multiple will only show the things we want
-                               if(in_array($g->group_id, $selected) xor $reverse) { 
-                                       $out .= '<option value="'.$g->group_id.'">'.$g->group_name."</option>\n";
-                               }
-                       } else {
-                               $out .= '<option ';
-                               if(in_array($g->group_id, $selected)) { $out .= 'selected="selected" '; }
-                               $out .= 'value="'.$g->group_id.'">'.$g->group_name."</option>\n";
-                       }
-               }
-               $out .= "</select>\n";
-               return $out;
-       }
-       
-       function HTMLSelectRights($selected='') {
-               global $wgAvailableRights;
-               $out = '<select name="editgroup-getrights[]" multiple="multiple">';
-               $groupRights = explode(',',$selected);
-               
-               foreach($wgAvailableRights as $right) {
-               
-                       // check box when right exist
-                       if(in_array($right, $groupRights)) { $selected = 'selected="selected" '; }
-                       else { $selected = ''; }
-                                               
-                       $out .= '<option value="'.$right.'" '.$selected.'>'.$right."</option>\n";
-               }
-               $out .= "</select>\n";
-               return $out;
-       }
-}
+} // end class UserlevelsForm
 ?>
index 420248e..8738107 100644 (file)
@@ -889,8 +889,8 @@ from server time (UTC).',
 #
 
 # switching pan
-'userlevels-lookup-group' => 'Manage group rights',
-'userlevels-group-edit' => 'Existent groups: ',
+'grouplevels-lookup-group' => 'Manage group rights',
+'grouplevels-group-edit' => 'Existent groups: ',
 'editgroup' => 'Edit Group',
 'addgroup' => 'Add Group',
 
@@ -899,10 +899,10 @@ from server time (UTC).',
 'editusergroup' => 'Edit User Groups',
 
 # group editing
-'userlevels-editgroup' => 'Edit group',
-'userlevels-addgroup' => 'Add group',
-'userlevels-editgroup-name' => 'Group name: ',
-'userlevels-editgroup-description' => 'Group description (max 255 characters):<br />',
+'grouplevels-editgroup' => 'Edit group',
+'grouplevels-addgroup' => 'Add group',
+'grouplevels-editgroup-name' => 'Group name: ',
+'grouplevels-editgroup-description' => 'Group description (max 255 characters):<br />',
 'savegroup' => 'Save Group',
 
 # user groups editing
@@ -1110,6 +1110,7 @@ That comes to '''$5''' average edits per page, and '''$6''' views per edit.",
 'createaccountpheading' => 'createaccount level',
 'deletepheading' => 'delete level',
 'userrightspheading' => 'userrights level',
+'grouprightspheading' => 'grouprights level',
 'siteadminpheading' => 'siteadmin level',
 
 /** obsoletes
@@ -1132,6 +1133,7 @@ in active use.</p>',
 'categoriespagetext' => 'The following categories exists in the wiki.',
 'data' => 'Data',
 'userlevels' => 'User levels management',
+'grouplevels' => 'Group levels management',
 
 # FIXME: Other sites, of course, may have affiliate relations with the booksellers list
 'booksourcetext' => "Below is a list of links to other sites that
index 44701c1..924b6cd 100644 (file)
@@ -5,3 +5,9 @@
 UPDATE /*$wgDBprefix*/`group`
    SET group_rights=CONCAT(group_rights,',sysop')
  WHERE group_name IN('Sysops','Bureaucrat');
+
+-- Add 'grouprights' right as for bureaucrats
+-- 2005-01-17
+UPDATE /*$wgDBprefix*/`group`
+   SET group_rights=CONCAT(group_rights,',grouprights')
+ WHERE group_name IN('Bureaucrat');
index fac0476..0c648b9 100644 (file)
@@ -10,4 +10,4 @@ INSERT INTO /*$wgDBprefix*/`group` (group_id,group_name,group_description,group_
 INSERT INTO /*$wgDBprefix*/`group` (group_id,group_name,group_description,group_rights)
        VALUES (3,'Sysops','Operators of this site','read,edit,move,delete,undelete,protect,block,upload,asksql,rollback,patrol,editinterface,sysop');
 INSERT INTO /*$wgDBprefix*/`group` (group_id,group_name,group_description,group_rights)
-       VALUES (4,'Bureaucrat','The bureaucrat group is able to make sysops for example. They have no other rights.','read,edit,move,delete,undelete,protect,block,userrights,createaccount,upload,asksql,rollback,patrol,editinterface,siteadmin,sysop');
+       VALUES (4,'Bureaucrat','The bureaucrat group is able to make sysops for example. They have no other rights.','read,edit,move,delete,undelete,protect,block,userrights,grouprights,createaccount,upload,asksql,rollback,patrol,editinterface,siteadmin,sysop');
index 277b740..58eb0cc 100644 (file)
@@ -239,7 +239,7 @@ function do_group_update() {
                $row = $wgDatabase->fetchObject( $res );
                $wgDatabase->freeResult( $res );
                if( $row->n ) {
-                       echo "Fixing sysops group permissions... ";
+                       echo "Fixing sysops group permissions and add group editing right... ";
                        dbsource( "maintenance/archives/patch-group-sysopfix.sql", $wgDatabase );
                        echo "ok\n";
                } else {