Implement #858 : split user assignment and group rights.
[lhc/web/wiklou.git] / includes / SpecialGrouplevels.php
1 <?php
2 /**
3 * Provide an administration interface
4 * DO NOT USE: INSECURE.
5 */
6
7 /** */
8 require_once('HTMLForm.php');
9 require_once('Group.php');
10
11 /** Entry point */
12 function wfSpecialGrouplevels($par=null) {
13 global $wgRequest;
14 # Debug statement
15 // print_r($_POST);
16 $form = new GrouplevelsForm($wgRequest);
17 $form->execute();
18 }
19
20 /**
21 * A class to manage group levels rights.
22 */
23 class GrouplevelsForm extends HTMLForm {
24 var $mPosted, $mRequest, $mSaveprefs;
25 /** Escaped local url name*/
26 var $action;
27
28 /** Constructor*/
29 function GrouplevelsForm ( &$request ) {
30 $this->mPosted = $request->wasPosted();
31 $this->mRequest = $request;
32 $this->mName = 'grouplevels';
33
34 $titleObj = Title::makeTitle( NS_SPECIAL, 'Grouplevels' );
35 $this->action = $titleObj->escapeLocalURL();
36 }
37
38 /**
39 * Manage forms to be shown according to posted datas.
40 * Depending on the submit button used : Call a form or a saving function.
41 */
42 function execute() {
43 // show the general form
44 $this->switchForm();
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( ); }
51
52 // save settings
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'));
58 }
59 }
60 }
61
62 // save things !!
63 /**
64 * Save a group
65 * @param string $newname Group name.
66 * @param string $oldname Old (current) group name.
67 * @param string $description Group description.
68 *
69 * @todo FIXME : doesnt validate anything. Log is incorrect.
70 */
71 function saveGroup($newname, $oldname, $description, $rights) {
72 $newame = trim($newname);
73
74 if($oldname == '') {
75 // We create a new group
76 $g = new group();
77 $g->addToDatabase();
78 } else {
79 $g = Group::newFromName($oldname);
80 }
81
82 // save stuff
83 $g->setName($newname);
84 $g->setDescription($description);
85 if(isset($rights)) { $g->setRights( implode(',',$rights) ); }
86
87 $g->save();
88
89 $log = new LogPage( 'rights' );
90 $log->addEntry( 'rights', Title::makeTitle( NS_SPECIAL, $g->getName()) , ' '.$g->getRights() );
91
92 }
93
94 /**
95 * The entry form
96 * It allows a user to edit or eventually add a group
97 */
98 function switchForm() {
99 global $wgOut;
100
101 // group selection
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').'" />'
107 ));
108 $wgOut->addHTML( "</form>\n" );
109 }
110
111 /**
112 * Edit a group properties and rights.
113 * @param string $groupname Name of a group to be edited.
114 */
115 function editGroupForm($groupID = 0) {
116 global $wgOut;
117
118 if($this->mRequest->getVal('seditgroup')) {
119 // fetch data if we edit a group
120 $g = Group::newFromID($groupID);
121 $fieldname = 'editgroup';
122 } else {
123 // default datas when we add a group
124 $g = new group();
125 $fieldname = 'addgroup';
126 }
127
128 $gName = $g->getName();
129 $gDescription = $g->getDescription();
130
131
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').'" />'
141 ));
142
143 $wgOut->addHTML( "</form>\n" );
144 }
145 } // end class GrouplevelsForm
146 ?>