From 773f915d76c5cad1bab9ed037d457e923940abad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Wed, 17 Jul 2019 14:00:21 +0200 Subject: [PATCH] Remove pointless PermissionManager::revokeTemporaryUserRights method Also add missing @since and make phpdoc formatting match (most) other methods. Change-Id: I087205ad23836f283e5ba291488a9bc1f4c3ce99 --- includes/Permissions/PermissionManager.php | 22 ++++++++----------- .../Permissions/PermissionManagerTest.php | 3 +-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/includes/Permissions/PermissionManager.php b/includes/Permissions/PermissionManager.php index 98a5b17608..5a3dae3fdd 100644 --- a/includes/Permissions/PermissionManager.php +++ b/includes/Permissions/PermissionManager.php @@ -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] ); + } ); } /** diff --git a/tests/phpunit/includes/Permissions/PermissionManagerTest.php b/tests/phpunit/includes/Permissions/PermissionManagerTest.php index 03b35b5331..5b015b3144 100644 --- a/tests/phpunit/includes/Permissions/PermissionManagerTest.php +++ b/tests/phpunit/includes/Permissions/PermissionManagerTest.php @@ -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 -- 2.20.1