39bbe629cb8476df1c354b0da6f5bff58ce0edef
3 * Provide an administration interface
5 * @subpackage SpecialPage
9 require_once('HTMLForm.php');
10 require_once('Group.php');
13 function wfSpecialGroups() {
16 $form = new GroupsForm($wgRequest);
21 * A class to manage group levels rights.
23 * @subpackage SpecialPage
25 class GroupsForm
extends HTMLForm
{
26 var $mPosted, $mRequest, $mSaveprefs, $mChangeAllowed;
27 var $mNewName, $mDescription, $mOldName, $mRights, $mId;
30 /** Escaped local url name*/
31 var $action, $location;
34 function GroupsForm ( &$request ) {
37 $this->mPosted
= $request->wasPosted();
38 $this->mRequest
=& $request;
39 $this->mName
= 'groups';
41 $this->mNewName
= trim( $request->getText('editgroup-name') );
42 $this->mOldName
= trim( $request->getText('editgroup-oldname' ) );
43 $this->mDescription
= trim( $request->getText( 'editgroup-description' ) );
44 $this->mRights
= $request->getArray( 'editgroup-getrights' );
45 $this->mId
= $this->mRequest
->getInt('id');
46 $this->mEdit
= $request->getCheck('edit');
47 $this->mAdd
= $request->getCheck('add');
50 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Groups' );
51 $this->action
= $titleObj->escapeLocalURL();
53 $this->location
= $titleObj->getLocalURL( "add=1&id={$this->mId}" );
54 } elseif ( $this->mEdit
) {
55 $this->location
= $titleObj->getLocalURL( "edit=1&id={$this->mId}" );
57 $this->location
= $this->action
;
60 $this->mChangeAllowed
= $wgUser->isAllowed( 'grouprights' ) && !Group
::getStaticGroups();
64 * Manage forms to be shown according to posted data
65 * Depending on the submit button used, call a form or a saving function.
70 if ( $this->mRequest
->getBool( 'showrecord' ) ) {
72 } elseif ( $this->mPosted
&& $this->mChangeAllowed
&& $this->mRequest
->getCheck('savegroup') ) {
75 } elseif ( $this->mEdit
) {
76 if ( $this->mPosted
) {
77 $wgOut->redirect( $this->location
);
80 $this->editGroupForm( $this->mId
);
82 } elseif ( $this->mAdd
) {
83 if ( $this->mPosted
) {
84 $wgOut->redirect( $this->location
);
87 $this->editGroupForm( );
90 $this->showAllGroups();
91 if ( $this->mChangeAllowed
) {
100 function saveGroup() {
103 $this->mNewName
= trim($this->mNewName
);
105 if ( $this->mNewName
== '' ) {
106 $this->editGroupForm( $this->mGroupID
, 'groups-noname' );
110 if($this->mOldName
== '') {
111 // Check if the group already exists
113 $g = Group
::newFromName( $this->mNewName
);
115 $this->editGroupForm( 0, 'groups-already-exists' );
119 // Create a new group
124 $g = Group
::newFromName($this->mOldName
);
126 $this->editGroupForm( 0, 'groups-noname' );
132 $g->setName($this->mNewName
);
133 $g->setDescription($this->mDescription
);
134 if( is_array( $this->mRights
) ) {
135 $g->setRights( implode(',',$this->mRights
) );
140 // Make the log entry
141 $log = new LogPage( 'rights' );
142 $dummyTitle = Title
::makeTitle( 0, '' );
144 $log->addEntry( 'addgroup', $dummyTitle, '', array( $g->getNameForContent() ) );
146 if ( $this->mOldName
!= $this->mNewName
) {
147 // Abbreviated action name, must be less than 10 bytes
148 $log->addEntry( 'rngroup', $dummyTitle, '', array( Group
::getMessageForContent( $this->mOldName
),
149 $g->getNameForContent() ) );
151 $log->addEntry( 'chgroup', $dummyTitle, '', array( $g->getNameForContent() ) );
155 // Success, go back to all groups page
156 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Groups' );
157 $url = $titleObj->getLocalURL();
159 $wgOut->redirect( $url );
164 * It allows a user to edit or eventually add a group
166 function switchForm() {
170 $wgOut->addHTML( "<form name=\"ulgroup\" action=\"$this->action\" method=\"post\">\n" );
171 $wgOut->addHTML( $this->fieldset( 'lookup-group',
172 HTMLSelectGroups('id', $this->mName
.'-group-edit', array(0 => $this->mRequest
->getVal('id')) ) .
173 ' <input type="submit" name="edit" value="'.wfMsg('editgroup').'" />' .
174 '<br /><input type="submit" name="add" value="'.wfMsg('addgroup').'" />'
176 $wgOut->addHTML( "</form>\n" );
180 * Edit a group properties and rights.
181 * @param string $groupname Name of a group to be edited.
182 * @param string $error message name of the error to display
184 function editGroupForm($groupID = 0, $error = '') {
188 $errText = wfMsg( $error );
189 $wgOut->addHTML( "<p class='error'>$errText</p>" );
192 if($this->mRequest
->getVal('edit')) {
193 // fetch data if we edit a group
194 $g = Group
::newFromID($groupID);
195 $fieldname = 'editgroup';
197 // default data when we add a group
199 $fieldname = 'addgroup';
202 $gName = htmlspecialchars( $g->getName() );
203 $gDescription = htmlspecialchars( $g->getDescription() );
206 $wgOut->addHTML( "<form name=\"editGroup\" action=\"{$this->action}\" method=\"post\">\n".
207 '<input type="hidden" name="editgroup-oldname" value="'.$gName."\" />\n" );
209 $wgOut->addHTML( $this->fieldset( $fieldname,
210 '<p>' . wfMsg( 'groups-editgroup-preamble' ) . "</p>\n" .
211 $this->textbox( 'editgroup-name', $gName ) .
212 $this->textareabox( 'editgroup-description', $gDescription ) .
213 '<br /><table border="0" align="center"><tr><td>'.
214 HTMLSelectRights($g->getRights()).
215 '</td></tr></table>'."\n".
216 '<input type="submit" name="savegroup" value="'.wfMsg('savegroup').'" />'
219 $wgOut->addHTML( "</form>\n" );
222 function showAllGroups() {
224 $groups =& Group
::getAllGroups();
226 $groupsExisting = wfMsg( 'groups-existing' );
227 $groupsHeader = wfMsg( 'groups-tableheader' );
230 |+'''$groupsExisting'''
234 foreach ( $groups as $group ) {
235 $s .= "|-\n| " . $group->getId() . ' || ' .
236 $group->getExpandedName() . ' || ' .
237 $group->getExpandedDescription() . ' || '.
238 // Insert spaces to make it wrap
239 str_replace( ',', ', ', $group->getRights() ) . "\n";
242 $wgOut->addWikiText( $s );
245 function showRecord() {
248 $groups =& Group
::getAllGroups();
249 $rec = serialize( $groups );
250 // Split it into lines
251 $rec = explode( "\r\n", chunk_split( $rec ) );
253 foreach ( $rec as $index => $line ) {
254 if ( trim( $line ) != '' ) {
259 $line = str_replace( array( '\\', "'" ), array( '\\\\', "\\'" ), $line );
260 // Escape it for HTML
261 $line = htmlspecialchars( $line );
262 // Add it to the string
267 $s = "<p>Copy the following into LocalSettings.php:</p>\n" .
268 "<textarea readonly rows=20>\n" .
269 "\$wgStaticGroups = \n\t'$s\n" .
271 $wgOut->addHTML( $s );
274 } // end class GroupsForm