3 * Provide an administration interface
4 * DO NOT USE: INSECURE.
6 * @subpackage SpecialPage
10 require_once('HTMLForm.php');
11 require_once('Group.php');
14 function wfSpecialGroups() {
17 $form = new GroupsForm($wgRequest);
22 * A class to manage group levels rights.
24 * @subpackage SpecialPage
26 class GroupsForm
extends HTMLForm
{
27 var $mPosted, $mRequest, $mSaveprefs, $mChangeAllowed;
28 var $mNewName, $mDescription, $mOldName, $mRights, $mId;
31 /** Escaped local url name*/
32 var $action, $location;
35 function GroupsForm ( &$request ) {
38 $this->mPosted
= $request->wasPosted();
39 $this->mRequest
= $request;
40 $this->mName
= 'groups';
42 $this->mNewName
= trim( $request->getText('editgroup-name') );
43 $this->mOldName
= trim( $request->getText('editgroup-oldname' ) );
44 $this->mDescription
= trim( $request->getText( 'editgroup-description' ) );
45 $this->mRights
= $request->getArray( 'editgroup-getrights' );
46 $this->mId
= $this->mRequest
->getInt('id');
47 $this->mEdit
= $request->getCheck('edit');
48 $this->mAdd
= $request->getCheck('add');
51 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Groups' );
52 $this->action
= $titleObj->escapeLocalURL();
54 $this->location
= $titleObj->getLocalURL( "add=1&id={$this->mId}" );
55 } elseif ( $this->mEdit
) {
56 $this->location
= $titleObj->getLocalURL( "edit=1&id={$this->mId}" );
58 $this->location
= $this->action
;
61 $this->mChangeAllowed
= $wgUser->isAllowed( 'grouprights' ) && !Group
::getStaticGroups();
65 * Manage forms to be shown according to posted datas.
66 * Depending on the submit button used : Call a form or a saving function.
71 if ( $this->mRequest
->getBool( 'showrecord' ) ) {
73 } elseif ( $this->mPosted
&& $this->mChangeAllowed
&& $this->mRequest
->getCheck('savegroup') ) {
76 } elseif ( $this->mEdit
) {
77 if ( $this->mPosted
) {
78 $wgOut->redirect( $this->location
);
81 $this->editGroupForm( $this->mId
);
83 } elseif ( $this->mAdd
) {
84 if ( $this->mPosted
) {
85 $wgOut->redirect( $this->location
);
88 $this->editGroupForm( );
91 $this->showAllGroups();
92 if ( $this->mChangeAllowed
) {
100 * @todo FIXME : Log is incorrect.
102 function saveGroup() {
105 $this->mNewName
= trim($this->mNewName
);
107 if ( $this->mNewName
== '' ) {
108 $this->editGroupForm( $this->mGroupID
, 'groups-noname' );
112 if($this->mOldName
== '') {
113 // Check if the group already exists
115 $g = Group
::newFromName( $this->mNewName
);
117 $this->editGroupForm( 0, 'groups-already-exists' );
121 // Create a new group
126 $g = Group
::newFromName($this->mOldName
);
128 $this->editGroupForm( 0, 'groups-noname' );
134 $g->setName($this->mNewName
);
135 $g->setDescription($this->mDescription
);
136 if( is_array( $this->mRights
) ) {
137 $g->setRights( implode(',',$this->mRights
) );
142 // Make the log entry
143 $log = new LogPage( 'rights' );
144 $dummyTitle = Title
::makeTitle( 0, '' );
146 $log->addEntry( 'addgroup', $dummyTitle, '', array( $g->getNameForContent() ) );
148 if ( $this->mOldName
!= $this->mNewName
) {
149 // Abbreviated action name, must be less than 10 bytes
150 $log->addEntry( 'rngroup', $dummyTitle, '', array( Group
::getMessageForContent( $this->mOldName
),
151 $g->getNameForContent() ) );
153 $log->addEntry( 'chgroup', $dummyTitle, '', array( $g->getNameForContent() ) );
157 // Success, go back to all groups page
158 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Groups' );
159 $url = $titleObj->getLocalURL();
161 $wgOut->redirect( $url );
166 * It allows a user to edit or eventually add a group
168 function switchForm() {
172 $wgOut->addHTML( "<form name=\"ulgroup\" action=\"$this->action\" method=\"post\">\n" );
173 $wgOut->addHTML( $this->fieldset( 'lookup-group',
174 HTMLSelectGroups('id', $this->mName
.'-group-edit', array(0 => $this->mRequest
->getVal('id')) ) .
175 ' <input type="submit" name="edit" value="'.wfMsg('editgroup').'" />' .
176 '<br /><input type="submit" name="add" value="'.wfMsg('addgroup').'" />'
178 $wgOut->addHTML( "</form>\n" );
182 * Edit a group properties and rights.
183 * @param string $groupname Name of a group to be edited.
184 * @param string $error message name of the error to display
186 function editGroupForm($groupID = 0, $error = '') {
190 $errText = wfMsg( $error );
191 $wgOut->addHTML( "<p class='error'>$errText</p>" );
194 if($this->mRequest
->getVal('edit')) {
195 // fetch data if we edit a group
196 $g = Group
::newFromID($groupID);
197 $fieldname = 'editgroup';
199 // default datas when we add a group
201 $fieldname = 'addgroup';
204 $gName = $g->getName();
205 $gDescription = $g->getDescription();
208 $wgOut->addHTML( "<form name=\"editGroup\" action=\"$this->action\" method=\"post\">\n".
209 '<input type="hidden" name="editgroup-oldname" value="'.$gName."\" />\n" );
211 $wgOut->addHTML( $this->fieldset( $fieldname,
212 '<p>' . wfMsg( 'groups-editgroup-preamble' ) . "</p>\n" .
213 $this->textbox( 'editgroup-name', $gName ) .
214 $this->textareabox( 'editgroup-description', $gDescription ) .
215 '<br /><table border="0" align="center"><tr><td>'.
216 HTMLSelectRights($g->getRights()).
217 '</td></tr></table>'."\n".
218 '<input type="submit" name="savegroup" value="'.wfMsg('savegroup').'" />'
221 $wgOut->addHTML( "</form>\n" );
224 function showAllGroups() {
226 $groups =& Group
::getAllGroups();
228 $groupsExisting = wfMsg( 'groups-existing' );
229 $groupsHeader = wfMsg( 'groups-tableheader' );
232 |+'''$groupsExisting'''
236 foreach ( $groups as $group ) {
237 $s .= "|-\n| " . $group->getId() . ' || ' .
238 $group->getExpandedName() . ' || ' .
239 $group->getExpandedDescription() . ' || '.
240 // Insert spaces to make it wrap
241 str_replace( ',', ', ', $group->getRights() ) . "\n";
244 $wgOut->addWikiText( $s );
247 function showRecord() {
250 $groups =& Group
::getAllGroups();
251 $rec = serialize( $groups );
253 $rec = str_replace( array( '\\', "'" ), array( '\\\\', "\\'" ), $rec );
254 // Escape it for HTML
255 $rec = htmlspecialchars( $rec );
256 $s = "<p>Copy the following into LocalSettings.php:</p>\n" .
257 "<textarea readonly rows=20>\n" .
258 "\$wgStaticGroups = '$rec';\n" .
260 $wgOut->addHTML( $s );
263 } // end class GroupsForm