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');
15 function wfSpecialUserrights() {
17 $form = new UserrightsForm($wgRequest);
22 * A class to manage user levels rights.
24 * @subpackage SpecialPage
26 class UserrightsForm
extends HTMLForm
{
27 var $mPosted, $mRequest, $mSaveprefs;
28 /** Escaped local url name*/
32 function UserrightsForm ( &$request ) {
33 $this->mPosted
= $request->wasPosted();
34 $this->mRequest
=& $request;
35 $this->mName
= 'userrights';
37 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Userrights' );
38 $this->action
= $titleObj->escapeLocalURL();
42 * Manage forms to be shown according to posted data.
43 * Depending on the submit button used, call a form or a save function.
46 // show the general form
48 if ( $this->mPosted
) {
49 // show some more forms
50 if($this->mRequest
->getCheck('ssearchuser')) {
51 $this->editUserGroupsForm( $this->mRequest
->getVal('user-editname')); }
54 if($this->mRequest
->getCheck('saveusergroups')) {
55 $this->saveUserGroups($this->mRequest
->getVal('user-editname'),
56 $this->mRequest
->getArray('member'),
57 $this->mRequest
->getArray('available'));
63 * Save user groups changes in the database.
64 * Data comes from the editUserGroupsForm() form function
66 * @param string $username Username to apply changes to.
67 * @param array $removegroup id of groups to be removed.
68 * @param array $addgroup id of groups to be added.
71 function saveUserGroups($username,$removegroup,$addgroup) {
72 $u = User
::newFromName($username);
75 $wgOut->addWikiText( wfMsg( 'nosuchusershort', htmlspecialchars( $username ) ) );
79 if($u->getID() == 0) {
80 $wgOut->addWikiText( wfMsg( 'nosuchusershort', htmlspecialchars( $username ) ) );
84 $oldGroups = $u->getGroups();
85 $newGroups = $oldGroups;
87 // remove then add groups
88 if(isset($removegroup)) {
89 $newGroups = array_diff($newGroups, $removegroup);
91 if(isset($addgroup)) {
92 $newGroups = array_merge($newGroups, $addgroup);
94 $newGroups = array_unique( $newGroups );
96 wfDebug( 'oldGroups: ' . print_r( $oldGroups, true ) );
97 wfDebug( 'newGroups: ' . print_r( $newGroups, true ) );
99 // save groups in user object and database
100 foreach( $removegroup as $group ) {
101 $u->removeGroup( $group );
103 foreach( $addgroup as $group ) {
104 $u->addGroup( $group );
107 $log = new LogPage( 'rights' );
108 $log->addEntry( 'rights', Title
::makeTitle( NS_USER
, $u->getName() ), '', array( $this->makeGroupNameList( $oldGroups ),
109 $this->makeGroupNameList( $newGroups ) ) );
112 function makeGroupNameList( $ids ) {
113 return implode( ', ', $ids );
118 * It allows a user to look for a username and edit its groups membership
120 function switchForm() {
124 $wgOut->addHTML( "<form name=\"uluser\" action=\"$this->action\" method=\"post\">\n" );
125 $wgOut->addHTML( $this->fieldset( 'lookup-user',
126 $this->textbox( 'user-editname' ) .
127 wfElement( 'input', array(
129 'name' => 'ssearchuser',
130 'value' => wfMsg( 'editusergroup' ) ) )
132 $wgOut->addHTML( "</form>\n" );
136 * Edit user groups membership
137 * @param string $username Name of the user.
139 function editUserGroupsForm($username) {
142 $user = User
::newFromName($username);
143 if( is_null( $user ) ||
$user->getID() == 0 ) {
144 $wgOut->addWikiText( wfMsg( 'nosuchusershort', wfEscapeWikiText( $username ) ) );
148 $groups = $user->getGroups();
150 $wgOut->addHTML( "<form name=\"editGroup\" action=\"$this->action\" method=\"post\">\n".
151 wfElement( 'input', array(
153 'name' => 'user-editname',
154 'value' => $username ) ) .
155 $this->fieldset( 'editusergroup',
156 $wgOut->parse( wfMsg('editing', $username ) ) .
157 '<table border="0" align="center"><tr><td>'.
158 HTMLSelectGroups('member', $this->mName
.'-groupsmember', $groups,true,6).
160 HTMLSelectGroups('available', $this->mName
.'-groupsavailable', $groups,true,6,true).
161 '</td></tr></table>'."\n".
162 $wgOut->parse( wfMsg('userrights-groupshelp') ) .
163 wfElement( 'input', array(
165 'name' => 'saveusergroups',
166 'value' => wfMsg( 'saveusergroups' ) ) )
168 $wgOut->addHTML( "</form>\n" );
170 } // end class UserrightsForm