From abe2167b67a4d625ab7732de1e15d7d871a333ff Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Fri, 28 Apr 2017 14:08:32 -0700 Subject: [PATCH] user: Ensure returned user groups are sorted Without it, Special:UserRights sometimes fails with a bogus conflict error just because groups are somehow ordered differently. Bug: T164211 Change-Id: I9c7f51338e0849d9e134dc780eb13c542960c655 --- RELEASE-NOTES-1.33 | 2 ++ includes/specials/SpecialUserrights.php | 7 ++++--- includes/user/User.php | 5 +++-- includes/user/UserGroupMembership.php | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index f357aae4b5..e8d579304f 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -64,6 +64,8 @@ production. * … === Bug fixes in 1.33 === +* (T164211) Special:UserRights could sometimes fail with a + "conflict detected" error when there weren't any conflicts. * … === Action API changes in 1.33 === diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php index 4168d91854..0f9ded382a 100644 --- a/includes/specials/SpecialUserrights.php +++ b/includes/specials/SpecialUserrights.php @@ -170,9 +170,10 @@ class UserrightsPage extends SpecialPage { $targetUser->clearInstanceCache(); // T40989 } - if ( $request->getVal( 'conflictcheck-originalgroups' ) - !== implode( ',', $targetUser->getGroups() ) - ) { + $checkValue = explode( ',', $request->getVal( 'conflictcheck-originalgroups' ) ); + $userGroups = $targetUser->getGroups(); + + if ( $userGroups !== $checkValue ) { $out->addWikiMsg( 'userrights-conflict' ); } else { $status = $this->saveUserGroups( diff --git a/includes/user/User.php b/includes/user/User.php index ec75f052e5..22fe44c398 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -58,7 +58,7 @@ class User implements IDBAccessObject, UserIdentity { /** * @const int Serialized record version. */ - const VERSION = 12; + const VERSION = 13; /** * Exclude user options that are set to their default value. @@ -3601,7 +3601,8 @@ class User implements IDBAccessObject, UserIdentity { /** * Get the list of explicit group memberships this user has. * The implicit * and user groups are not included. - * @return array Array of String internal group names + * + * @return string[] Array of internal group names (sorted since 1.33) */ public function getGroups() { $this->load(); diff --git a/includes/user/UserGroupMembership.php b/includes/user/UserGroupMembership.php index cf985cb9eb..acd697081c 100644 --- a/includes/user/UserGroupMembership.php +++ b/includes/user/UserGroupMembership.php @@ -323,6 +323,7 @@ class UserGroupMembership { $ugms[$ugm->group] = $ugm; } } + ksort( $ugms ); return $ugms; } -- 2.20.1