ce617f1af6c57dfddc77469330e04242cc086460
[lhc/web/wiklou.git] / includes / SpecialGroups.php
1 <?php
2 /**
3 * Provide an administration interface
4 * DO NOT USE: INSECURE.
5 * @package MediaWiki
6 * @subpackage SpecialPage
7 */
8
9 /** */
10 require_once('HTMLForm.php');
11 require_once('Group.php');
12
13 /** Entry point */
14 function wfSpecialGroups($par=null) {
15 global $wgRequest;
16 # Debug statement
17 // print_r($_POST);
18 $form = new GroupsForm($wgRequest);
19 $form->execute();
20 }
21
22 /**
23 * A class to manage group levels rights.
24 * @package MediaWiki
25 * @subpackage SpecialPage
26 */
27 class GroupsForm extends HTMLForm {
28 var $mPosted, $mRequest, $mSaveprefs;
29 /** Escaped local url name*/
30 var $action;
31
32 /** Constructor*/
33 function GroupsForm ( &$request ) {
34 $this->mPosted = $request->wasPosted();
35 $this->mRequest = $request;
36 $this->mName = 'groups';
37
38 $titleObj = Title::makeTitle( NS_SPECIAL, 'Groups' );
39 $this->action = $titleObj->escapeLocalURL();
40 }
41
42 /**
43 * Manage forms to be shown according to posted datas.
44 * Depending on the submit button used : Call a form or a saving function.
45 */
46 function execute() {
47 // show the general form
48 $this->switchForm();
49 if ( $this->mPosted ) {
50 // show some more forms
51 if($this->mRequest->getCheck('seditgroup')) {
52 $this->editGroupForm( $this->mRequest->getVal($this->mName.'-group-edit') ); }
53 if($this->mRequest->getCheck('saddgroup')) {
54 $this->editGroupForm( ); }
55
56 // save settings
57 if($this->mRequest->getCheck('savegroup')) {
58 $this->saveGroup($this->mRequest->getVal('editgroup-name'),
59 $this->mRequest->getVal('editgroup-oldname'),
60 $this->mRequest->getVal('editgroup-description'),
61 $this->mRequest->getArray('editgroup-getrights'));
62 }
63 }
64 }
65
66 // save things !!
67 /**
68 * Save a group
69 * @param string $newname Group name.
70 * @param string $oldname Old (current) group name.
71 * @param string $description Group description.
72 *
73 * @todo FIXME : doesnt validate anything. Log is incorrect.
74 */
75 function saveGroup($newname, $oldname, $description, $rights) {
76 $newame = trim($newname);
77
78 if($oldname == '') {
79 // We create a new group
80 $g = new group();
81 $g->addToDatabase();
82 } else {
83 $g = Group::newFromName($oldname);
84 }
85
86 // save stuff
87 $g->setName($newname);
88 $g->setDescription($description);
89 if(isset($rights)) { $g->setRights( implode(',',$rights) ); }
90
91 $g->save();
92
93 $log = new LogPage( 'rights' );
94 $log->addEntry( 'rights', Title::makeTitle( NS_SPECIAL, $g->getName()) , ' '.$g->getRights() );
95
96 }
97
98 /**
99 * The entry form
100 * It allows a user to edit or eventually add a group
101 */
102 function switchForm() {
103 global $wgOut;
104
105 // group selection
106 $wgOut->addHTML( "<form name=\"ulgroup\" action=\"$this->action\" method=\"post\">\n" );
107 $wgOut->addHTML( $this->fieldset( 'lookup-group',
108 HTMLSelectGroups($this->mName.'-group-edit', array(0 => $this->mRequest->getVal($this->mName.'-group-edit')) ) .
109 ' <input type="submit" name="seditgroup" value="'.wfMsg('editgroup').'" />' .
110 '<br /><input type="submit" name="saddgroup" value="'.wfMsg('addgroup').'" />'
111 ));
112 $wgOut->addHTML( "</form>\n" );
113 }
114
115 /**
116 * Edit a group properties and rights.
117 * @param string $groupname Name of a group to be edited.
118 */
119 function editGroupForm($groupID = 0) {
120 global $wgOut;
121
122 if($this->mRequest->getVal('seditgroup')) {
123 // fetch data if we edit a group
124 $g = Group::newFromID($groupID);
125 $fieldname = 'editgroup';
126 } else {
127 // default datas when we add a group
128 $g = new group();
129 $fieldname = 'addgroup';
130 }
131
132 $gName = $g->getName();
133 $gDescription = $g->getDescription();
134
135
136 $wgOut->addHTML( "<form name=\"editGroup\" action=\"$this->action\" method=\"post\">\n".
137 '<input type="hidden" name="editgroup-oldname" value="'.$gName.'" />');
138 $wgOut->addHTML( $this->fieldset( $fieldname,
139 $this->textbox( 'editgroup-name', $gName ) .
140 $this->textareabox( 'editgroup-description', $gDescription ) .
141 '<br /><table border="0" align="center"><tr><td>'.
142 HTMLSelectRights($g->getRights()).
143 '</td></tr></table>'."\n".
144 '<input type="submit" name="savegroup" value="'.wfMsg('savegroup').'" />'
145 ));
146
147 $wgOut->addHTML( "</form>\n" );
148 }
149 } // end class GroupsForm
150 ?>