* 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');
?>
<?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
*
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;
}
?>
--- /dev/null
+<?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
+?>
'Unlockdb' => new SpecialPage( 'Unlockdb', 'siteadmin' ),
'Sitesettings' => new SpecialPage( 'Sitesettings', 'siteadmin' ),
'Userlevels' => new SpecialPage( 'Userlevels', 'userrights' ),
+ 'Grouplevels' => new SpecialPage( 'Grouplevels', 'grouprights' ),
));
/**
/**
* Provide an administration interface
* DO NOT USE: INSECURE.
+ *
+ * TODO : remove everything related to group editing (SpecialGrouplevels.php)
*/
/** */
$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
/**
* 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',
$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.
$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
?>
#
# 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',
'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
'createaccountpheading' => 'createaccount level',
'deletepheading' => 'delete level',
'userrightspheading' => 'userrights level',
+'grouprightspheading' => 'grouprights level',
'siteadminpheading' => 'siteadmin level',
/** obsoletes
'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
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');
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');
$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 {