Merge "Avoid @backupGlobals in ExtensionRegistryTest"
[lhc/web/wiklou.git] / includes / specials / SpecialUserrights.php
index 36a31bd..a5edcb0 100644 (file)
@@ -218,7 +218,7 @@ class UserrightsPage extends SpecialPage {
        /**
         * Save user groups changes in the database.
         *
-        * @param User $user
+        * @param User|UserRightsProxy $user
         * @param array $add Array of groups to add
         * @param array $remove Array of groups to remove
         * @param string $reason Reason for group change
@@ -228,7 +228,7 @@ class UserrightsPage extends SpecialPage {
                global $wgAuth;
 
                // Validate input set...
-               $isself = $user->equals( $this->getUser() );
+               $isself = $user->getName() == $this->getUser()->getName();
                $groups = $user->getGroups();
                $changeable = $this->changeableGroups();
                $addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : array() );
@@ -244,18 +244,22 @@ class UserrightsPage extends SpecialPage {
                $oldGroups = $user->getGroups();
                $newGroups = $oldGroups;
 
-               // remove then add groups
+               // Remove then add groups
                if ( $remove ) {
-                       $newGroups = array_diff( $newGroups, $remove );
-                       foreach ( $remove as $group ) {
-                               $user->removeGroup( $group );
+                       foreach ( $remove as $index => $group ) {
+                               if ( !$user->removeGroup( $group ) ) {
+                                       unset($remove[$index]);
+                               }
                        }
+                       $newGroups = array_diff( $newGroups, $remove );
                }
                if ( $add ) {
-                       $newGroups = array_merge( $newGroups, $add );
-                       foreach ( $add as $group ) {
-                               $user->addGroup( $group );
+                       foreach ( $add as $index => $group ) {
+                               if ( !$user->addGroup( $group ) ) {
+                                       unset($add[$index]);
+                               }
                        }
+                       $newGroups = array_merge( $newGroups, $add );
                }
                $newGroups = array_unique( $newGroups );