diff --git a/extension.json b/extension.json index ccc1a38..ef5a805 100644 --- a/extension.json +++ b/extension.json @@ -30,7 +30,14 @@ "Miraheze\\RottenLinks\\": "includes/" }, "JobClasses": { - "RottenLinksJob": "Miraheze\\RottenLinks\\Jobs\\RottenLinksJob" + "RottenLinksJob": { + "class": "Miraheze\\RottenLinks\\Jobs\\RottenLinksJob", + "services": [ + "ConfigFactory", + "ConnectionProvider" + ], + "needsPage": false + } }, "SpecialPages": { "RottenLinks": { diff --git a/includes/HookHandlers/Main.php b/includes/HookHandlers/Main.php index af1fe61..5ef92ae 100644 --- a/includes/HookHandlers/Main.php +++ b/includes/HookHandlers/Main.php @@ -2,6 +2,7 @@ namespace Miraheze\RottenLinks\HookHandlers; +use JobSpecification; use MediaWiki\Deferred\LinksUpdate\LinksUpdate; use MediaWiki\Hook\LinksUpdateCompleteHook; use MediaWiki\Hook\ParserFirstCallInitHook; @@ -11,7 +12,10 @@ use Miraheze\RottenLinks\RottenLinksParserFunctions; use Wikimedia\Rdbms\IConnectionProvider; -class Main implements LinksUpdateCompleteHook, ParserFirstCallInitHook { +class Main implements + LinksUpdateCompleteHook, + ParserFirstCallInitHook +{ private JobQueueGroupFactory $jobQueueGroupFactory; private RottenLinksParserFunctions $parserFunctions; @@ -35,13 +39,16 @@ public function onLinksUpdateComplete( $linksUpdate, $ticket ) { $removedExternalLinks = $linksUpdate->getRemovedExternalLinks(); if ( $addedExternalLinks || $removedExternalLinks ) { - $params = [ - 'addedExternalLinks' => $addedExternalLinks ?? [], - 'removedExternalLinks' => $removedExternalLinks ?? [], - ]; - $jobQueueGroup = $this->jobQueueGroupFactory->makeJobQueueGroup(); - $jobQueueGroup->push( new RottenLinksJob( $params ) ); + $jobQueueGroup->push( + new JobSpecification( + RottenLinksJob::JOB_NAME, + [ + 'addedExternalLinks' => $addedExternalLinks ?? [], + 'removedExternalLinks' => $removedExternalLinks ?? [], + ] + ) + ); } } diff --git a/includes/Jobs/RottenLinksJob.php b/includes/Jobs/RottenLinksJob.php index 865ca8d..ed47c0d 100644 --- a/includes/Jobs/RottenLinksJob.php +++ b/includes/Jobs/RottenLinksJob.php @@ -2,31 +2,43 @@ namespace Miraheze\RottenLinks\Jobs; -use GenericParameterJob; use Job; +use MediaWiki\Config\Config; +use MediaWiki\Config\ConfigFactory; use MediaWiki\ExternalLinks\LinkFilter; -use MediaWiki\MediaWikiServices; use Miraheze\RottenLinks\RottenLinks; +use Wikimedia\Rdbms\IConnectionProvider; -class RottenLinksJob extends Job implements GenericParameterJob { +class RottenLinksJob extends Job { + + public const JOB_NAME = 'RottenLinksJob'; + + private Config $config; + private IConnectionProvider $connectionProvider; private array $addedExternalLinks; private array $removedExternalLinks; - public function __construct( array $params ) { - parent::__construct( 'RottenLinksJob', $params ); + public function __construct( + array $params, + ConfigFactory $configFactory, + IConnectionProvider $connectionProvider + ) { + parent::__construct( self::JOB_NAME, $params ); $this->addedExternalLinks = $params['addedExternalLinks']; $this->removedExternalLinks = $params['removedExternalLinks']; + + $this->config = $configFactory->makeConfig( 'RottenLinks' ); + $this->connectionProvider = $connectionProvider; } public function run(): bool { - $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'RottenLinks' ); - $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); + $dbw = $this->connectionProvider->getPrimaryDatabase(); if ( $this->addedExternalLinks ) { - $excludeProtocols = (array)$config->get( 'RottenLinksExcludeProtocols' ); - $excludeWebsites = (array)$config->get( 'RottenLinksExcludeWebsites' ); + $excludeProtocols = (array)$this->config->get( 'RottenLinksExcludeProtocols' ); + $excludeWebsites = (array)$this->config->get( 'RottenLinksExcludeWebsites' ); foreach ( $this->addedExternalLinks as $url ) { $url = $this->decodeDomainName( $url );