Index: SpecialUserrights.php
===================================================================
--- SpecialUserrights.php (revision 22060)
+++ SpecialUserrights.php (working copy)
@@ -27,7 +27,7 @@
var $action;
/** Constructor*/
- function UserrightsForm ( &$request ) {
+ public function UserrightsForm ( &$request ) {
$this->mPosted = $request->wasPosted();
$this->mRequest =& $request;
$this->mName = 'userrights';
@@ -94,21 +94,25 @@
if(isset($removegroup)) {
$newGroups = array_diff($newGroups, $removegroup);
foreach( $removegroup as $group ) {
+ if ( $this->canRemove( $group ) ) {
$u->removeGroup( $group );
}
}
+ }
if(isset($addgroup)) {
$newGroups = array_merge($newGroups, $addgroup);
foreach( $addgroup as $group ) {
+ if ( $this->canAdd( $group ) ) {
$u->addGroup( $group );
}
}
+ }
$newGroups = array_unique( $newGroups );
wfDebug( 'oldGroups: ' . print_r( $oldGroups, true ) );
wfDebug( 'newGroups: ' . print_r( $newGroups, true ) );
- wfRunHooks( 'UserRights', array( &$u, $addgroup, $removegroup ) );
+ wfRunHooks( 'UserRights', array( &$u, $addgroup, $removegroup ) );
$log = new LogPage( 'rights' );
$log->addEntry( 'rights', Title::makeTitle( NS_USER, $u->getName() ), $reason, array( $this->makeGroupNameList( $oldGroups ),
$this->makeGroupNameList( $newGroups ) ) );
@@ -138,8 +142,6 @@
* @param string $username Name of the user.
*/
function editUserGroupsForm($username) {
- global $wgOut;
-
$user = User::newFromName($username);
if( is_null( $user ) ) {
$wgOut->addWikiText( wfMsg( 'nouserspecified' ) );
@@ -149,13 +151,24 @@
return;
}
- $groups = $user->getGroups();
- $this->showEditUserGroupsForm( $username, $groups );
+ list($addable, $removable) = $this->getGroups();
+ $removable = array_intersect($removable, $user->getGroups()); // Can't remove groups the user doesn't have
+ $addable = array_diff( $addable, $user->getGroups()); // Can't add groups the user does have
+
+ $this->showEditUserGroupsForm( $username, $addable, $removable );
}
-
- function showEditUserGroupsForm( $username, $groups ) {
+
+ /**
+ * Show the form to edit group memberships.
+ *
+ * @param $username String: Name of user you're editing
+ * @param $addable Array: Array of groups that can be added
+ * @param $removable Array: Array of groups that can be removed
+ */
+ private function showEditUserGroupsForm( $username, $addable, $removable ) {
global $wgOut, $wgUser;
- $wgOut->addHTML(
+
+ $wgOut->addHtml(
Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->action, 'name' => 'editGroup' ) ) .
Xml::hidden( 'user-editname', $username ) .
Xml::hidden( 'wpEditToken', $wgUser->editToken( $username ) ) .
@@ -168,8 +181,8 @@
- " . HTMLSelectGroups( 'member', $this->mName.'-groupsmember', $groups, true, 6 ) . " |
- " . HTMLSelectGroups( 'available', $this->mName.'-groupsavailable', $groups, true, 6, true) . " |
+ " . $this->removeSelect( $removable ) . " |
+ " . $this->addSelect( $addable ) . " |
@@ -197,5 +210,103 @@
Xml::closeElement( 'form' ) . "\n"
);
}
+
+ /**
+ * Adds the |