Alexia has uploaded a new change for review.
https://gerrit.wikimedia.org/r/180328
Change subject: Have the User::addGroup() and User::removeGroup() functions
return a boolean when their respective hooks return the respective boolean.
Fix the SpecialUserrights page to respect this and update the arrays
accordingly.
......................................................................
Have the User::addGroup() and User::removeGroup() functions return a boolean
when their respective hooks return the respective boolean. Fix the
SpecialUserrights page to respect this and update the arrays accordingly.
Change-Id: I7621cc22b04ff41cf67bd434a1f89d31bdc2cffd
---
M includes/User.php
M includes/specials/SpecialUserrights.php
2 files changed, 20 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/28/180328/1
diff --git a/includes/User.php b/includes/User.php
index bda825f..bec9f67 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -3031,6 +3031,7 @@
* Add the user to the given group.
* This takes immediate effect.
* @param string $group Name of the group to add
+ * @return bool
*/
public function addGroup( $group ) {
if ( Hooks::run( 'UserAddGroup', array( $this, &$group ) ) ) {
@@ -3044,6 +3045,8 @@
__METHOD__,
array( 'IGNORE' ) );
}
+ } else {
+ return false;
}
$this->loadGroups();
$this->mGroups[] = $group;
@@ -3057,12 +3060,15 @@
$this->mRights = null;
$this->invalidateCache();
+
+ return true;
}
/**
* Remove the user from the given group.
* This takes immediate effect.
* @param string $group Name of the group to remove
+ * @return bool
*/
public function removeGroup( $group ) {
$this->load();
@@ -3081,6 +3087,8 @@
),
__METHOD__,
array( 'IGNORE' ) );
+ } else {
+ return false;
}
$this->loadGroups();
$this->mGroups = array_diff( $this->mGroups, array( $group ) );
@@ -3091,6 +3099,8 @@
$this->mRights = null;
$this->invalidateCache();
+
+ return true;
}
/**
diff --git a/includes/specials/SpecialUserrights.php
b/includes/specials/SpecialUserrights.php
index 3e9313c..06b943e 100644
--- a/includes/specials/SpecialUserrights.php
+++ b/includes/specials/SpecialUserrights.php
@@ -246,16 +246,20 @@
// 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 );
--
To view, visit https://gerrit.wikimedia.org/r/180328
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7621cc22b04ff41cf67bd434a1f89d31bdc2cffd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Alexia <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits