Merge "Fix functionality and usages of SpecialUserrights::userCanChangeRights"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 25 Jan 2017 11:01:54 +0000 (11:01 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 25 Jan 2017 11:01:54 +0000 (11:01 +0000)
includes/skins/SkinTemplate.php
includes/specials/SpecialUserrights.php

index 1a4554f..bf260aa 100644 (file)
@@ -1322,7 +1322,7 @@ class SkinTemplate extends Skin {
                        if ( !$user->isAnon() ) {
                                $sur = new UserrightsPage;
                                $sur->setContext( $this->getContext() );
-                               $canChange = $sur->userCanChangeRights( $this->getUser(), false );
+                               $canChange = $sur->userCanChangeRights( $user );
                                $nav_urls['userrights'] = [
                                        'text' => $this->msg(
                                                $canChange ? 'tool-link-userrights' : 'tool-link-userrights-readonly',
index 4db2198..98cdc09 100644 (file)
@@ -49,19 +49,25 @@ class UserrightsPage extends SpecialPage {
        }
 
        /**
-        * @param User $user
-        * @param bool $checkIfSelf
+        * Check whether the current user (from context) can change the target user's rights.
+        *
+        * @param User $targetUser User whose rights are being changed
+        * @param bool $checkIfSelf If false, assume that the current user can add/remove groups defined
+        *   in $wgGroupsAddToSelf / $wgGroupsRemoveFromSelf, without checking if it's the same as target
+        *   user
         * @return bool
         */
-       public function userCanChangeRights( $user, $checkIfSelf = true ) {
+       public function userCanChangeRights( $targetUser, $checkIfSelf = true ) {
+               $isself = $this->getUser()->equals( $targetUser );
+
                $available = $this->changeableGroups();
-               if ( $user->getId() == 0 ) {
+               if ( $targetUser->getId() == 0 ) {
                        return false;
                }
 
                return !empty( $available['add'] )
                        || !empty( $available['remove'] )
-                       || ( ( $this->isself || !$checkIfSelf ) &&
+                       || ( ( $isself || !$checkIfSelf ) &&
                                ( !empty( $available['add-self'] )
                                        || !empty( $available['remove-self'] ) ) );
        }