}
}
- if ( User::getCanonicalName( $this->mTarget ) == $user->getName() ) {
+ if ( User::getCanonicalName( $this->mTarget ) === $user->getName() ) {
$this->isself = true;
}
/**
* 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
global $wgAuth;
// Validate input set...
- $isself = ( $user->getName() == $this->getUser()->getName() );
+ $isself = $user->getName() == $this->getUser()->getName();
$groups = $user->getGroups();
$changeable = $this->changeableGroups();
$addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : array() );
$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 );