Inject services

Change-Id: I7f11825af2bb96ad61aa2cefcc47fcad706388af
This commit is contained in:
Fomafix 2022-11-04 11:03:00 +00:00
parent 6f8f4d759f
commit 49df51e106
2 changed files with 37 additions and 9 deletions

View file

@ -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/"

View file

@ -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(