3 * Provide an administration interface
4 * DO NOT USE: INSECURE.
6 * TODO : remove everything related to group editing (SpecialGrouplevels.php)
8 * @subpackage SpecialPage
12 require_once('HTMLForm.php');
13 require_once('Group.php');
16 function wfSpecialUserrights() {
18 $form = new UserrightsForm($wgRequest);
23 * A class to manage user levels rights.
25 * @subpackage SpecialPage
27 class UserrightsForm
extends HTMLForm
{
28 var $mPosted, $mRequest, $mSaveprefs;
29 /** Escaped local url name*/
33 function UserrightsForm ( &$request ) {
34 $this->mPosted
= $request->wasPosted();
35 $this->mRequest
=& $request;
36 $this->mName
= 'userrights';
38 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Userrights' );
39 $this->action
= $titleObj->escapeLocalURL();
43 * Manage forms to be shown according to posted data.
44 * Depending on the submit button used, call a form or a save function.
47 // show the general form
49 if ( $this->mPosted
) {
50 // show some more forms
51 if($this->mRequest
->getCheck('ssearchuser')) {
52 $this->editUserGroupsForm( $this->mRequest
->getVal('user-editname')); }
55 if($this->mRequest
->getCheck('saveusergroups')) {
56 $this->saveUserGroups($this->mRequest
->getVal('user-editname'),
57 $this->mRequest
->getArray('member'),
58 $this->mRequest
->getArray('available'));
64 * Save user groups changes in the database.
65 * Data comes from the editUserGroupsForm() form function
67 * @param string $username Username to apply changes to.
68 * @param array $removegroup id of groups to be removed.
69 * @param array $addgroup id of groups to be added.
72 function saveUserGroups($username,$removegroup,$addgroup) {
73 $u = User
::newFromName($username);
76 $wgOut->addHTML('<p>'.wfMsg('nosuchusershort',$username).'</p>');
80 if($u->getID() == 0) {
81 $wgOut->addHTML('<p>'.wfMsg('nosuchusershort',$username).'</p>');
85 $oldGroups = $u->getGroups();
86 $newGroups = $oldGroups;
88 // remove then add groups
89 if(isset($removegroup)) {
90 $newGroups = array_diff($newGroups, $removegroup);
92 if(isset($addgroup)) {
93 $newGroups = array_merge($newGroups, $addgroup);
95 $newGroups = array_unique( $newGroups );
97 // save groups in user object and database
98 $u->setGroups($newGroups);
101 $log = new LogPage( 'rights' );
102 $log->addEntry( 'rights', Title
::makeTitle( NS_USER
, $u->getName() ), '', array( $this->makeGroupNameList( $oldGroups ),
103 $this->makeGroupNameList( $newGroups ) ) );
106 function makeGroupNameList( $ids ) {
108 foreach( $ids as $id ) {
112 $groupObj = Group
::newFromId( $id );
113 $s .= $groupObj->getExpandedName();
120 * It allows a user to look for a username and edit its groups membership
122 function switchForm() {
126 $wgOut->addHTML( "<form name=\"uluser\" action=\"$this->action\" method=\"post\">\n" );
127 $wgOut->addHTML( $this->fieldset( 'lookup-user',
128 $this->textbox( 'user-editname' ) .
129 '<input type="submit" name="ssearchuser" value="'.wfMsg('editusergroup').'" />'
131 $wgOut->addHTML( "</form>\n" );
135 * Edit user groups membership
136 * @param string $username Name of the user.
138 function editUserGroupsForm($username) {
141 $user = User
::newFromName($username);
142 $encUser = htmlspecialchars( $username );
144 $wgOut->addHTML('<p>'.wfMsg('nosuchusershort', $encUser).'</p>');
148 if($user->getID() == 0) {
149 $wgOut->addHTML('<p>'.wfMsg('nosuchusershort', $encUser).'</p>');
153 $groups = $user->getGroups();
155 $wgOut->addHTML( "<form name=\"editGroup\" action=\"$this->action\" method=\"post\">\n".
156 '<input type="hidden" name="user-editname" value="'.$encUser.'" />');
157 $wgOut->addHTML( $this->fieldset( 'editusergroup',
158 wfMsg('editing', $this->mRequest
->getVal('user-editname')).".<br />\n" .
159 '<table border="0" align="center"><tr><td>'.
160 HTMLSelectGroups('member', $this->mName
.'-groupsmember', $groups,true,6).
162 HTMLSelectGroups('available', $this->mName
.'-groupsavailable', $groups,true,6,true).
163 '</td></tr></table>'."\n".
164 '<p>'.wfMsg('userrights-groupshelp').'</p>'."\n".
165 '<input type="submit" name="saveusergroups" value="'.wfMsg('saveusergroups').'" />'
167 $wgOut->addHTML( "</form>\n" );
169 } // end class UserrightsForm