3 * Provide an administration interface
4 * DO NOT USE: INSECURE.
8 require_once('HTMLForm.php');
9 require_once('Group.php');
12 function wfSpecialGrouplevels($par=null) {
16 $form = new GrouplevelsForm($wgRequest);
21 * A class to manage group levels rights.
23 class GrouplevelsForm
extends HTMLForm
{
24 var $mPosted, $mRequest, $mSaveprefs;
25 /** Escaped local url name*/
29 function GrouplevelsForm ( &$request ) {
30 $this->mPosted
= $request->wasPosted();
31 $this->mRequest
= $request;
32 $this->mName
= 'grouplevels';
34 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Grouplevels' );
35 $this->action
= $titleObj->escapeLocalURL();
39 * Manage forms to be shown according to posted datas.
40 * Depending on the submit button used : Call a form or a saving function.
43 // show the general form
45 if ( $this->mPosted
) {
46 // show some more forms
47 if($this->mRequest
->getCheck('seditgroup')) {
48 $this->editGroupForm( $this->mRequest
->getVal($this->mName
.'-group-edit') ); }
49 if($this->mRequest
->getCheck('saddgroup')) {
50 $this->editGroupForm( ); }
53 if($this->mRequest
->getCheck('savegroup')) {
54 $this->saveGroup($this->mRequest
->getVal('editgroup-name'),
55 $this->mRequest
->getVal('editgroup-oldname'),
56 $this->mRequest
->getVal('editgroup-description'),
57 $this->mRequest
->getArray('editgroup-getrights'));
65 * @param string $newname Group name.
66 * @param string $oldname Old (current) group name.
67 * @param string $description Group description.
69 * @todo FIXME : doesnt validate anything. Log is incorrect.
71 function saveGroup($newname, $oldname, $description, $rights) {
72 $newame = trim($newname);
75 // We create a new group
79 $g = Group
::newFromName($oldname);
83 $g->setName($newname);
84 $g->setDescription($description);
85 if(isset($rights)) { $g->setRights( implode(',',$rights) ); }
89 $log = new LogPage( 'rights' );
90 $log->addEntry( 'rights', Title
::makeTitle( NS_SPECIAL
, $g->getName()) , ' '.$g->getRights() );
96 * It allows a user to edit or eventually add a group
98 function switchForm() {
102 $wgOut->addHTML( "<form name=\"ulgroup\" action=\"$this->action\" method=\"post\">\n" );
103 $wgOut->addHTML( $this->fieldset( 'lookup-group',
104 HTMLSelectGroups($this->mName
.'-group-edit', array(0 => $this->mRequest
->getVal($this->mName
.'-group-edit')) ) .
105 ' <input type="submit" name="seditgroup" value="'.wfMsg('editgroup').'" />' .
106 '<br /><input type="submit" name="saddgroup" value="'.wfMsg('addgroup').'" />'
108 $wgOut->addHTML( "</form>\n" );
112 * Edit a group properties and rights.
113 * @param string $groupname Name of a group to be edited.
115 function editGroupForm($groupID = 0) {
118 if($this->mRequest
->getVal('seditgroup')) {
119 // fetch data if we edit a group
120 $g = Group
::newFromID($groupID);
121 $fieldname = 'editgroup';
123 // default datas when we add a group
125 $fieldname = 'addgroup';
128 $gName = $g->getName();
129 $gDescription = $g->getDescription();
132 $wgOut->addHTML( "<form name=\"editGroup\" action=\"$this->action\" method=\"post\">\n".
133 '<input type="hidden" name="editgroup-oldname" value="'.$gName.'" />');
134 $wgOut->addHTML( $this->fieldset( $fieldname,
135 $this->textbox( 'editgroup-name', $gName ) .
136 $this->textareabox( 'editgroup-description', $gDescription ) .
137 '<br /><table border="0" align="center"><tr><td>'.
138 HTMLSelectRights($g->getRights()).
139 '</td></tr></table>'."\n".
140 '<input type="submit" name="savegroup" value="'.wfMsg('savegroup').'" />'
143 $wgOut->addHTML( "</form>\n" );
145 } // end class GrouplevelsForm