user: Ensure returned user groups are sorted
authorMax Semenik <maxsem.wiki@gmail.com>
Fri, 28 Apr 2017 21:08:32 +0000 (14:08 -0700)
committerKrinkle <krinklemail@gmail.com>
Sat, 22 Dec 2018 07:38:51 +0000 (07:38 +0000)
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
includes/specials/SpecialUserrights.php
includes/user/User.php
includes/user/UserGroupMembership.php

index f357aae..e8d5793 100644 (file)
@@ -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 ===
index 4168d91..0f9ded3 100644 (file)
@@ -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(
index ec75f05..22fe44c 100644 (file)
@@ -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();
index cf985cb..acd6970 100644 (file)
@@ -323,6 +323,7 @@ class UserGroupMembership {
                                $ugms[$ugm->group] = $ugm;
                        }
                }
+               ksort( $ugms );
 
                return $ugms;
        }