Remove pointless PermissionManager::revokeTemporaryUserRights method
authorGergő Tisza <tgr.huwiki@gmail.com>
Wed, 17 Jul 2019 12:00:21 +0000 (14:00 +0200)
committerGergő Tisza <gtisza@wikimedia.org>
Wed, 17 Jul 2019 22:39:27 +0000 (22:39 +0000)
Also add missing @since and make phpdoc formatting match (most) other
methods.

Change-Id: I087205ad23836f283e5ba291488a9bc1f4c3ce99

includes/Permissions/PermissionManager.php
tests/phpunit/includes/Permissions/PermissionManagerTest.php

index 98a5b17..5a3dae3 100644 (file)
@@ -1409,24 +1409,20 @@ class PermissionManager {
         * to make bot-flagged actions through certain special pages.
         * Returns a "scope guard" variable; whenever that variable goes out of scope or is consumed
         * via ScopedCallback::consume(), the temporary rights are revoked.
+        *
+        * @since 1.34
+        *
         * @param UserIdentity $user
         * @param string|string[] $rights
         * @return ScopedCallback
         */
        public function addTemporaryUserRights( UserIdentity $user, $rights ) {
-               $nextKey = count( $this->temporaryUserRights[$user->getId()] ?? [] );
-               $this->temporaryUserRights[$user->getId()][$nextKey] = (array)$rights;
-               return new ScopedCallback( [ $this, 'revokeTemporaryUserRights' ], [ $user->getId(), $nextKey ] );
-       }
-
-       /**
-        * Revoke rights added by addTemporaryUserRights().
-        * @param int $userId
-        * @param int $rightsGroupKey Key in self::$temporaryUserRights
-        * @internal For use by addTemporaryUserRights() only.
-        */
-       public function revokeTemporaryUserRights( $userId, $rightsGroupKey ) {
-               unset( $this->temporaryUserRights[$userId][$rightsGroupKey] );
+               $userId = $user->getId();
+               $nextKey = count( $this->temporaryUserRights[$userId] ?? [] );
+               $this->temporaryUserRights[$userId][$nextKey] = (array)$rights;
+               return new ScopedCallback( function () use ( $userId, $nextKey ) {
+                       unset( $this->temporaryUserRights[$userId][$nextKey] );
+               } );
        }
 
        /**
index 03b35b5..5b015b3 100644 (file)
@@ -1651,9 +1651,8 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
        /**
         * @covers \MediaWiki\Permissions\PermissionManager::addTemporaryUserRights
-        * @covers \MediaWiki\Permissions\PermissionManager::revokeTemporaryUserRights
         */
-       public function testTemporaryUserRights() {
+       public function testAddTemporaryUserRights() {
                $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
                $this->overrideUserPermissions( $this->user, [ 'read', 'edit' ] );
                // sanity checks