From 139c83b1a9d2b673fbfb88352e4a168a03346b5b Mon Sep 17 00:00:00 2001 From: Fomafix Date: Sat, 20 Apr 2024 20:31:46 +0000 Subject: [PATCH] ApiFlowThank: Replace deprecated User::newFromId Change-Id: I857ce647a1374600c952107b92c3c35440c83b6c --- includes/Api/ApiFlowThank.php | 19 ++++++++++++++++++- includes/Hooks.php | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/Api/ApiFlowThank.php b/includes/Api/ApiFlowThank.php index 05221f54..860a3d85 100644 --- a/includes/Api/ApiFlowThank.php +++ b/includes/Api/ApiFlowThank.php @@ -3,14 +3,18 @@ namespace MediaWiki\Extension\Thanks\Api; use ApiBase; +use ApiMain; use Flow\Container; use Flow\Conversion\Utils; use Flow\Exception\FlowException; use Flow\Model\PostRevision; use Flow\Model\UUID; use MediaWiki\Extension\Notifications\Model\Event; +use MediaWiki\Extension\Thanks\Storage\LogStore; +use MediaWiki\Permissions\PermissionManager; use MediaWiki\Title\Title; use MediaWiki\User\User; +use MediaWiki\User\UserFactory; use Wikimedia\ParamValidator\ParamValidator; /** @@ -25,6 +29,19 @@ use Wikimedia\ParamValidator\ParamValidator; class ApiFlowThank extends ApiThank { + private UserFactory $userFactory; + + public function __construct( + ApiMain $main, + $action, + PermissionManager $permissionManager, + LogStore $storage, + UserFactory $userFactory + ) { + parent::__construct( $main, $action, $permissionManager, $storage ); + $this->userFactory = $userFactory; + } + public function execute() { $user = $this->getUser(); $this->dieOnBadUser( $user ); @@ -107,7 +124,7 @@ class ApiFlowThank extends ApiThank { * @return User */ private function getRecipientFromPost( PostRevision $post ) { - $recipient = User::newFromId( $post->getCreatorId() ); + $recipient = $this->userFactory->newFromId( $post->getCreatorId() ); if ( !$recipient->loadFromId() ) { $this->dieWithError( 'thanks-error-invalidrecipient', 'invalidrecipient' ); } diff --git a/includes/Hooks.php b/includes/Hooks.php index c337e2b4..e9342939 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -411,7 +411,8 @@ class Hooks implements "class" => ApiFlowThank::class, "services" => [ "PermissionManager", - "ThanksLogStore" + "ThanksLogStore", + "UserFactory", ] ] );