From 248180ef0350811ec2322ec46ab70650fce1384c Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 26 Feb 2024 07:35:55 +0000 Subject: [PATCH] Inject service WatchlistManager into MinervaPagePermissions Change-Id: Id41c85c8e119efbf9814be25ba659f1da1151eb4 --- includes/Permissions/MinervaPagePermissions.php | 11 ++++++++--- includes/ServiceWiring.php | 3 ++- .../permissions/MinervaPagePermissionsTest.php | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/includes/Permissions/MinervaPagePermissions.php b/includes/Permissions/MinervaPagePermissions.php index b44a2818c..bf5be078c 100644 --- a/includes/Permissions/MinervaPagePermissions.php +++ b/includes/Permissions/MinervaPagePermissions.php @@ -24,13 +24,13 @@ use IContextSource; use MediaWiki\Config\Config; use MediaWiki\Config\ConfigException; use MediaWiki\Content\IContentHandlerFactory; -use MediaWiki\MediaWikiServices; use MediaWiki\Minerva\LanguagesHelper; use MediaWiki\Minerva\SkinOptions; use MediaWiki\Permissions\Authority; use MediaWiki\Permissions\PermissionManager; use MediaWiki\Title\Title; use MediaWiki\User\UserFactory; +use MediaWiki\Watchlist\WatchlistManager; /** * A wrapper for all available Minerva permissions. @@ -77,6 +77,8 @@ final class MinervaPagePermissions implements IMinervaPagePermissions { private UserFactory $userFactory; + private WatchlistManager $watchlistManager; + /** * Initialize internal Minerva Permissions system * @param SkinOptions $skinOptions @@ -84,19 +86,22 @@ final class MinervaPagePermissions implements IMinervaPagePermissions { * @param PermissionManager $permissionManager * @param IContentHandlerFactory $contentHandlerFactory * @param UserFactory $userFactory + * @param WatchlistManager $watchlistManager */ public function __construct( SkinOptions $skinOptions, LanguagesHelper $languagesHelper, PermissionManager $permissionManager, IContentHandlerFactory $contentHandlerFactory, - UserFactory $userFactory + UserFactory $userFactory, + WatchlistManager $watchlistManager ) { $this->skinOptions = $skinOptions; $this->languagesHelper = $languagesHelper; $this->permissionManager = $permissionManager; $this->contentHandlerFactory = $contentHandlerFactory; $this->userFactory = $userFactory; + $this->watchlistManager = $watchlistManager; } /** @@ -177,7 +182,7 @@ final class MinervaPagePermissions implements IMinervaPagePermissions { } if ( $action === self::WATCHABLE || $action === self::WATCH ) { - $isWatchable = MediaWikiServices::getInstance()->getWatchlistManager()->isWatchable( $this->title ); + $isWatchable = $this->watchlistManager->isWatchable( $this->title ); if ( $action === self::WATCHABLE ) { return $isWatchable; diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 54b7bc941..71006d9dd 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -162,7 +162,8 @@ return [ $services->getService( 'Minerva.LanguagesHelper' ), $services->getPermissionManager(), $services->getContentHandlerFactory(), - $services->getUserFactory() + $services->getUserFactory(), + $services->getWatchlistManager() ); // TODO: This should not be allowed, this is basically global $wgTitle and $wgUser. $permissions->setContext( RequestContext::getMain() ); diff --git a/tests/phpunit/permissions/MinervaPagePermissionsTest.php b/tests/phpunit/permissions/MinervaPagePermissionsTest.php index 125e7ca42..bcf222efd 100644 --- a/tests/phpunit/permissions/MinervaPagePermissionsTest.php +++ b/tests/phpunit/permissions/MinervaPagePermissionsTest.php @@ -74,7 +74,8 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase { $languageHelper, $permissionManager, $contentHandlerFactory, - $this->createMock( UserFactory::class ) + $this->createMock( UserFactory::class ), + $this->getServiceContainer()->getWatchlistManager() ) )->setContext( $context ); }