From 49df51e1063e09be64cae6cfebcaa069c11b6537 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Fri, 4 Nov 2022 11:03:00 +0000 Subject: [PATCH] Inject services Change-Id: I7f11825af2bb96ad61aa2cefcc47fcad706388af --- extension.json | 9 ++++++++- includes/SpecialNuke.php | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/extension.json b/extension.json index cff4ff22..a871e641 100644 --- a/extension.json +++ b/extension.json @@ -58,7 +58,14 @@ } }, "SpecialPages": { - "Nuke": "MediaWiki\\Extension\\Nuke\\SpecialNuke" + "Nuke": { + "class": "MediaWiki\\Extension\\Nuke\\SpecialNuke", + "services": [ + "JobQueueGroup", + "PermissionManager", + "RepoGroup" + ] + } }, "AutoloadNamespaces": { "MediaWiki\\Extension\\Nuke\\": "includes/" diff --git a/includes/SpecialNuke.php b/includes/SpecialNuke.php index c707d9be..305e3d87 100644 --- a/includes/SpecialNuke.php +++ b/includes/SpecialNuke.php @@ -7,13 +7,15 @@ use DeletePageJob; use FileDeleteForm; use Html; use HTMLForm; +use JobQueueGroup; use ListToggle; use MediaWiki\Extension\Nuke\Hooks\NukeHookRunner; -use MediaWiki\MediaWikiServices; +use MediaWiki\Permissions\PermissionManager; use OOUI\DropdownInputWidget; use OOUI\FieldLayout; use OOUI\TextInputWidget; use PermissionsError; +use RepoGroup; use SpecialPage; use Title; use User; @@ -27,9 +29,30 @@ class SpecialNuke extends SpecialPage { /** @var NukeHookRunner */ private $hookRunner; - public function __construct() { + /** @var JobQueueGroup */ + private $jobQueueGroup; + + /** @var PermissionManager */ + private $permissionManager; + + /** @var RepoGroup */ + private $repoGroup; + + /** + * @param JobQueueGroup $jobQueueGroup + * @param PermissionManager $permissionManager + * @param RepoGroup $repoGroup + */ + public function __construct( + JobQueueGroup $jobQueueGroup, + PermissionManager $permissionManager, + RepoGroup $repoGroup + ) { parent::__construct( 'Nuke', 'nuke' ); $this->hookRunner = new NukeHookRunner( $this->getHookContainer() ); + $this->jobQueueGroup = $jobQueueGroup; + $this->permissionManager = $permissionManager; + $this->repoGroup = $repoGroup; } public function doesWrites() { @@ -246,7 +269,7 @@ class SpecialNuke extends SpecialPage { $commaSeparator = $this->msg( 'comma-separator' )->escaped(); $linkRenderer = $this->getLinkRenderer(); - $localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo(); + $localRepo = $this->repoGroup->getLocalRepo(); foreach ( $pages as $info ) { /** * @var $title Title @@ -377,9 +400,7 @@ class SpecialNuke extends SpecialPage { $jobs = []; $user = $this->getUser(); - $services = MediaWikiServices::getInstance(); - $localRepo = $services->getRepoGroup()->getLocalRepo(); - $permissionManager = $services->getPermissionManager(); + $localRepo = $this->repoGroup->getLocalRepo(); foreach ( $pages as $page ) { $title = Title::newFromText( $page ); @@ -397,7 +418,7 @@ class SpecialNuke extends SpecialPage { continue; } - $permission_errors = $permissionManager->getPermissionErrors( 'delete', $user, $title ); + $permission_errors = $this->permissionManager->getPermissionErrors( 'delete', $user, $title ); if ( $permission_errors !== [] ) { throw new PermissionsError( 'delete', $permission_errors ); @@ -445,7 +466,7 @@ class SpecialNuke extends SpecialPage { } if ( $jobs ) { - MediaWikiServices::getInstance()->getJobQueueGroup()->push( $jobs ); + $this->jobQueueGroup->push( $jobs ); } $this->getOutput()->addHTML(