From ff26f6db1612aba8adbdabf617c6296ba9777211 Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Mon, 18 Nov 2024 13:37:43 -0700 Subject: [PATCH 1/5] Use namespaced classes and other cleanup --- .phan/config.php | 1 - extension.json | 2 +- includes/HookHandlers/Installer.php | 2 +- includes/RottenLinks.php | 2 +- includes/RottenLinksPager.php | 12 ++--- includes/SpecialRottenLinks.php | 8 +-- maintenance/updateExternalLinks.php | 83 +++++++++++------------------ 7 files changed, 44 insertions(+), 66 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 0d43c78..e4bd302 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -17,7 +17,6 @@ $cfg['suppress_issue_types'] = [ 'PhanAccessMethodInternal', 'SecurityCheck-LikelyFalsePositive', - 'UnusedPluginSuppression' ]; return $cfg; diff --git a/extension.json b/extension.json index b226dc0..4269425 100644 --- a/extension.json +++ b/extension.json @@ -101,7 +101,7 @@ } }, "ConfigRegistry": { - "RottenLinks": "GlobalVarConfig::newInstance" + "RottenLinks": "MediaWiki\\Config\\GlobalVarConfig::newInstance" }, "manifest_version": 2 } diff --git a/includes/HookHandlers/Installer.php b/includes/HookHandlers/Installer.php index f2733fc..575d6cb 100644 --- a/includes/HookHandlers/Installer.php +++ b/includes/HookHandlers/Installer.php @@ -2,7 +2,7 @@ namespace Miraheze\RottenLinks\HookHandlers; -use DatabaseUpdater; +use MediaWiki\Installer\DatabaseUpdater; use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook; class Installer implements LoadExtensionSchemaUpdatesHook { diff --git a/includes/RottenLinks.php b/includes/RottenLinks.php index 9b3cccd..c080275 100644 --- a/includes/RottenLinks.php +++ b/includes/RottenLinks.php @@ -2,7 +2,7 @@ namespace Miraheze\RottenLinks; -use Config; +use MediaWiki\Config\Config; use MediaWiki\MediaWikiServices; use WikiMedia\Rdbms\IReadableDatabase; diff --git a/includes/RottenLinksPager.php b/includes/RottenLinksPager.php index 93ffb52..1e0a692 100644 --- a/includes/RottenLinksPager.php +++ b/includes/RottenLinksPager.php @@ -2,14 +2,14 @@ namespace Miraheze\RottenLinks; -use Config; -use Html; use HttpStatus; -use IContextSource; -use Linker; +use MediaWiki\Config\Config; +use MediaWiki\Context\IContextSource; use MediaWiki\ExternalLinks\LinkFilter; -use SpecialPage; -use TablePager; +use MediaWiki\Html\Html; +use MediaWiki\Linker\Linker; +use MediaWiki\Pager\TablePager; +use MediaWiki\SpecialPage\SpecialPage; class RottenLinksPager extends TablePager { diff --git a/includes/SpecialRottenLinks.php b/includes/SpecialRottenLinks.php index bdbb1d4..e790529 100644 --- a/includes/SpecialRottenLinks.php +++ b/includes/SpecialRottenLinks.php @@ -2,11 +2,11 @@ namespace Miraheze\RottenLinks; -use Config; -use ConfigFactory; -use HTMLForm; use HttpStatus; -use SpecialPage; +use MediaWiki\Config\Config; +use MediaWiki\Config\ConfigFactory; +use MediaWiki\HTMLForm\HTMLForm; +use MediaWiki\SpecialPage\SpecialPage; use Wikimedia\Rdbms\ILoadBalancer; class SpecialRottenLinks extends SpecialPage { diff --git a/maintenance/updateExternalLinks.php b/maintenance/updateExternalLinks.php index b5c64c4..d3992c7 100644 --- a/maintenance/updateExternalLinks.php +++ b/maintenance/updateExternalLinks.php @@ -2,75 +2,53 @@ namespace Miraheze\RottenLinks\Maintenance; +$IP ??= getenv( 'MW_INSTALL_PATH' ) ?: dirname( __DIR__, 3 ); +require_once "$IP/maintenance/Maintenance.php"; + use Maintenance; use MediaWiki\ExternalLinks\LinkFilter; -use MediaWiki\MediaWikiServices; use Miraheze\RottenLinks\RottenLinks; -$IP = getenv( 'MW_INSTALL_PATH' ); -if ( $IP === false ) { - $IP = __DIR__ . '/../../..'; -} - -require_once "$IP/maintenance/Maintenance.php"; - class UpdateExternalLinks extends Maintenance { + public function __construct() { parent::__construct(); $this->addDescription( 'Updates rottenlinks database table based on externallinks table.' ); - $this->requireExtension( 'RottenLinks' ); } public function execute() { $time = time(); - $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'RottenLinks' ); $dbw = $this->getDB( DB_PRIMARY ); $this->output( "Dropping all existing recorded entries\n" ); - $dbw->delete( 'rottenlinks', - '*', - __METHOD__ - ); + $dbw->newDeleteQueryBuilder() + ->deleteFrom( 'rottenlinks' ) + ->where( '*' ) + ->caller( __METHOD__ ) + ->execute(); + + $res = $dbw->newSelectQueryBuilder() + ->select( [ + 'el_from', + 'el_to_domain_index', + 'el_to_path', + ] ) + ->from( 'externallinks' ) + ->caller( __METHOD__ ) + ->fetchResultSet(); $rottenlinksarray = []; - - if ( version_compare( MW_VERSION, '1.41', '>=' ) ) { - $res = $dbw->newSelectQueryBuilder() - ->select( [ - 'el_from', - 'el_to_domain_index', - 'el_to_path', - ] ) - ->from( 'externallinks' ) - ->caller( __METHOD__ ) - ->fetchResultSet(); - - foreach ( $res as $row ) { - // @phan-suppress-next-line PhanUndeclaredStaticMethod - $elUrl = LinkFilter::reverseIndexes( $row->el_to_domain_index ) . $row->el_to_path; - $rottenlinksarray[$elUrl][] = (int)$row->el_from; - } - } else { - $res = $dbw->newSelectQueryBuilder() - ->select( [ - 'el_from', - 'el_to', - ] ) - ->from( 'externallinks' ) - ->caller( __METHOD__ ) - ->fetchResultSet(); - - foreach ( $res as $row ) { - $rottenlinksarray[$row->el_to][] = (int)$row->el_from; - } + foreach ( $res as $row ) { + $elUrl = LinkFilter::reverseIndexes( $row->el_to_domain_index ) . $row->el_to_path; + $rottenlinksarray[$elUrl][] = (int)$row->el_from; } - $excludeProtocols = (array)$config->get( 'RottenLinksExcludeProtocols' ); - $excludeWebsites = (array)$config->get( 'RottenLinksExcludeWebsites' ); + $excludeProtocols = (array)$this->getConfig()->get( 'RottenLinksExcludeProtocols' ); + $excludeWebsites = (array)$this->getConfig()->get( 'RottenLinksExcludeWebsites' ); foreach ( $rottenlinksarray as $url => $pages ) { $url = $this->decodeDomainName( $url ); @@ -108,13 +86,14 @@ public function execute() { $resp = RottenLinks::getResponse( $url ); $pagecount = count( $pages ); - $dbw->insert( 'rottenlinks', - [ + $dbw->newInsertQueryBuilder() + ->insertInto( 'rottenlinks' ) + ->row( [ 'rl_externallink' => $url, - 'rl_respcode' => $resp - ], - __METHOD__ - ); + 'rl_respcode' => $resp, + ] ) + ->caller( __METHOD__ ) + ->execute(); $this->output( "Added externallink ($url) used on $pagecount with code $resp\n" ); } From 94aeba0aa12957fa15f881e6786ed0267769fecb Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Mon, 18 Nov 2024 13:59:34 -0700 Subject: [PATCH 2/5] Part 2 --- .phpcs.xml | 23 +++++++++++++--- extension.json | 36 ++++++++++++------------- includes/HookHandlers/Installer.php | 5 +--- includes/HookHandlers/Main.php | 20 +++++++------- includes/RottenLinks.php | 1 + includes/RottenLinksJob.php | 7 ++--- includes/RottenLinksLuaLibrary.php | 1 + includes/RottenLinksPager.php | 7 ++--- includes/RottenLinksParserFunctions.php | 3 --- includes/SpecialRottenLinks.php | 13 +++------ 10 files changed, 58 insertions(+), 58 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index 304518b..ae2956a 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -2,7 +2,24 @@ . - - - + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + + diff --git a/extension.json b/extension.json index 4269425..a8bbdb0 100644 --- a/extension.json +++ b/extension.json @@ -62,8 +62,8 @@ "Main": { "class": "Miraheze\\RottenLinks\\HookHandlers\\Main", "services": [ - "JobQueueGroup", - "ConnectionProvider" + "ConnectionProvider", + "JobQueueGroupFactory" ] }, "Scribunto": { @@ -72,32 +72,32 @@ }, "config": { "RottenLinksBadCodes": { - "value": [ "0", "400", "401", "403", "404", "405", "410", "502", "503", "504" ], - "description": "Holds a list of HTTP codes that are considered bad. (array)" + "description": "Array. Holds a list of HTTP codes that are considered bad.", + "value": [ "0", "400", "401", "403", "404", "405", "410", "502", "503", "504" ] }, "RottenLinksCurlTimeout": { - "value": 30, - "description": "Sets the timeout for cURL in seconds. (integer)" - }, - "RottenLinksHTTPProxy": { - "value": "", - "description": "Sets a proxy to use for requests. (string)" + "description": "Integer. Sets the timeout for cURL in seconds.", + "value": 30 }, "RottenLinksExcludeProtocols": { - "value": [ "tel", "mailto" ], - "description": "Holds a list of protocols that should not be checked for validity. (array)" + "description": "Array. Holds a list of protocols that should not be checked for validity.", + "value": [ "tel", "mailto" ] }, "RottenLinksExcludeWebsites": { - "value": false, - "description": "List of websites to exclude checking of response codes for. (array)" + "description": "Array. List of websites to exclude checking of response codes for.", + "value": [] }, "RottenLinksExternalLinkTarget": { - "value": "_self", - "description": "Sets the external link target (_self for the current tab or _blank for a new tab). (string)" + "description": "String. Sets the external link target (_self for the current tab or _blank for a new tab).", + "value": "_self" + }, + "RottenLinksHTTPProxy": { + "description": "String. Sets a proxy to use for requests.", + "value": "" }, "RottenLinksUserAgent": { - "value": "", - "description": "Overrides the user-agent to use for requests. Defaults to 'RottenLinks, MediaWiki extension (https://github.com/miraheze/RottenLinks), running on '. (string)" + "description": "String. Overrides the user-agent to use for requests. Defaults to 'RottenLinks, MediaWiki extension (https://github.com/miraheze/RottenLinks), running on '.", + "value": "" } }, "ConfigRegistry": { diff --git a/includes/HookHandlers/Installer.php b/includes/HookHandlers/Installer.php index 575d6cb..1d2bd4f 100644 --- a/includes/HookHandlers/Installer.php +++ b/includes/HookHandlers/Installer.php @@ -2,14 +2,11 @@ namespace Miraheze\RottenLinks\HookHandlers; -use MediaWiki\Installer\DatabaseUpdater; use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook; class Installer implements LoadExtensionSchemaUpdatesHook { - /** - * @param DatabaseUpdater $updater - */ + /** @inheritDoc */ public function onLoadExtensionSchemaUpdates( $updater ) { $dir = __DIR__ . '/../../sql'; diff --git a/includes/HookHandlers/Main.php b/includes/HookHandlers/Main.php index 8baa93a..c2ce9e0 100644 --- a/includes/HookHandlers/Main.php +++ b/includes/HookHandlers/Main.php @@ -2,10 +2,10 @@ namespace Miraheze\RottenLinks\HookHandlers; -use JobQueueGroup; use MediaWiki\Deferred\LinksUpdate\LinksUpdate; use MediaWiki\Hook\LinksUpdateCompleteHook; use MediaWiki\Hook\ParserFirstCallInitHook; +use MediaWiki\JobQueue\JobQueueGroupFactory; use MediaWiki\Parser\Parser; use Miraheze\RottenLinks\RottenLinksJob; use Miraheze\RottenLinks\RottenLinksParserFunctions; @@ -13,15 +13,14 @@ class Main implements LinksUpdateCompleteHook, ParserFirstCallInitHook { - private JobQueueGroup $jobQueueGroup; + private JobQueueGroupFactory $jobQueueGroupFactory; private RottenLinksParserFunctions $parserFunctions; - /** - * @param JobQueueGroup $jobQueueGroup - * @param IConnectionProvider $connectionProvider - */ - public function __construct( JobQueueGroup $jobQueueGroup, IConnectionProvider $connectionProvider ) { - $this->jobQueueGroup = $jobQueueGroup; + public function __construct( + IConnectionProvider $connectionProvider, + JobQueueGroupFactory $jobQueueGroupFactory + ) { + $this->jobQueueGroupFactory = $jobQueueGroupFactory; $this->parserFunctions = new RottenLinksParserFunctions( $connectionProvider ); } @@ -38,10 +37,11 @@ public function onLinksUpdateComplete( $linksUpdate, $ticket ) { if ( $addedExternalLinks || $removedExternalLinks ) { $params = [ 'addedExternalLinks' => $addedExternalLinks, - 'removedExternalLinks' => $removedExternalLinks + 'removedExternalLinks' => $removedExternalLinks, ]; - $this->jobQueueGroup->push( new RottenLinksJob( $params ) ); + $jobQueueGroup = $this->jobQueueGroupFactory->makeJobQueueGroup(); + $jobQueueGroup->push( new RottenLinksJob( $params ) ); } } diff --git a/includes/RottenLinks.php b/includes/RottenLinks.php index c080275..2c9ede7 100644 --- a/includes/RottenLinks.php +++ b/includes/RottenLinks.php @@ -7,6 +7,7 @@ use WikiMedia\Rdbms\IReadableDatabase; class RottenLinks { + /** * Get the HTTP response status code for a given URL. * diff --git a/includes/RottenLinksJob.php b/includes/RottenLinksJob.php index 5d76584..114e309 100644 --- a/includes/RottenLinksJob.php +++ b/includes/RottenLinksJob.php @@ -9,11 +9,8 @@ class RottenLinksJob extends Job implements GenericParameterJob { - /** @var array */ - private $addedExternalLinks; - - /** @var array */ - private $removedExternalLinks; + private array $addedExternalLinks; + private array $removedExternalLinks; /** * @param array $params Job parameters. diff --git a/includes/RottenLinksLuaLibrary.php b/includes/RottenLinksLuaLibrary.php index b1d03bb..420d437 100644 --- a/includes/RottenLinksLuaLibrary.php +++ b/includes/RottenLinksLuaLibrary.php @@ -1,4 +1,5 @@ connectionProvider = $connectionProvider; } diff --git a/includes/SpecialRottenLinks.php b/includes/SpecialRottenLinks.php index e790529..89b29e8 100644 --- a/includes/SpecialRottenLinks.php +++ b/includes/SpecialRottenLinks.php @@ -11,16 +11,9 @@ class SpecialRottenLinks extends SpecialPage { - /** @var Config */ - private $config; + private Config $config; + private ILoadBalancer $dbLoadBalancer; - /** @var ILoadBalancer */ - private $dbLoadBalancer; - - /** - * @param ConfigFactory $configFactory - * @param ILoadBalancer $dbLoadBalancer - */ public function __construct( ConfigFactory $configFactory, ILoadBalancer $dbLoadBalancer @@ -32,7 +25,7 @@ public function __construct( } /** - * @param string $par + * @param ?string $par */ public function execute( $par ) { $this->setHeaders(); From 3897170d8cfb81ae9eb6e86e877e7f629a3c93b1 Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Mon, 18 Nov 2024 14:24:04 -0700 Subject: [PATCH 3/5] Part 3 --- extension.json | 6 +- includes/HookHandlers/Main.php | 6 +- includes/{ => Jobs}/RottenLinksJob.php | 21 ++----- includes/RottenLinks.php | 7 +-- includes/RottenLinksPager.php | 13 ++--- .../{ => Specials}/SpecialRottenLinks.php | 55 ++++++++----------- maintenance/updateExternalLinks.php | 3 +- 7 files changed, 41 insertions(+), 70 deletions(-) rename includes/{ => Jobs}/RottenLinksJob.php (87%) rename includes/{ => Specials}/SpecialRottenLinks.php (69%) diff --git a/extension.json b/extension.json index a8bbdb0..6c38d3f 100644 --- a/extension.json +++ b/extension.json @@ -30,14 +30,14 @@ "Miraheze\\RottenLinks\\": "includes/" }, "JobClasses": { - "RottenLinksJob": "Miraheze\\RottenLinks\\RottenLinksJob" + "RottenLinksJob": "Miraheze\\RottenLinks\\Jobs\\RottenLinksJob" }, "SpecialPages": { "RottenLinks": { - "class": "Miraheze\\RottenLinks\\SpecialRottenLinks", + "class": "Miraheze\\RottenLinks\\Specials\\SpecialRottenLinks", "services": [ "ConfigFactory", - "DBLoadBalancer" + "ConnectionProvider" ] } }, diff --git a/includes/HookHandlers/Main.php b/includes/HookHandlers/Main.php index c2ce9e0..af1fe61 100644 --- a/includes/HookHandlers/Main.php +++ b/includes/HookHandlers/Main.php @@ -7,7 +7,7 @@ use MediaWiki\Hook\ParserFirstCallInitHook; use MediaWiki\JobQueue\JobQueueGroupFactory; use MediaWiki\Parser\Parser; -use Miraheze\RottenLinks\RottenLinksJob; +use Miraheze\RottenLinks\Jobs\RottenLinksJob; use Miraheze\RottenLinks\RottenLinksParserFunctions; use Wikimedia\Rdbms\IConnectionProvider; @@ -36,8 +36,8 @@ public function onLinksUpdateComplete( $linksUpdate, $ticket ) { if ( $addedExternalLinks || $removedExternalLinks ) { $params = [ - 'addedExternalLinks' => $addedExternalLinks, - 'removedExternalLinks' => $removedExternalLinks, + 'addedExternalLinks' => $addedExternalLinks ?? [], + 'removedExternalLinks' => $removedExternalLinks ?? [], ]; $jobQueueGroup = $this->jobQueueGroupFactory->makeJobQueueGroup(); diff --git a/includes/RottenLinksJob.php b/includes/Jobs/RottenLinksJob.php similarity index 87% rename from includes/RottenLinksJob.php rename to includes/Jobs/RottenLinksJob.php index 114e309..7c3e8cc 100644 --- a/includes/RottenLinksJob.php +++ b/includes/Jobs/RottenLinksJob.php @@ -1,6 +1,6 @@ addedExternalLinks = $params['addedExternalLinks'] ?? []; - $this->removedExternalLinks = $params['removedExternalLinks'] ?? []; + $this->addedExternalLinks = $params['addedExternalLinks']; + $this->removedExternalLinks = $params['removedExternalLinks']; } /** @@ -27,14 +24,11 @@ public function __construct( array $params ) { * * @return bool True on success. */ - public function run() { + public function run(): bool { $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'RottenLinks' ); + $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); if ( $this->addedExternalLinks ) { - $dbw = MediaWikiServices::getInstance() - ->getDBLoadBalancer() - ->getMaintenanceConnectionRef( DB_PRIMARY ); - $excludeProtocols = (array)$config->get( 'RottenLinksExcludeProtocols' ); $excludeWebsites = (array)$config->get( 'RottenLinksExcludeWebsites' ); @@ -83,10 +77,6 @@ public function run() { } if ( $this->removedExternalLinks ) { - $dbw = MediaWikiServices::getInstance() - ->getDBLoadBalancer() - ->getMaintenanceConnectionRef( DB_PRIMARY ); - foreach ( $this->removedExternalLinks as $url ) { $url = $this->decodeDomainName( $url ); @@ -127,7 +117,6 @@ public function run() { * URL-decoding the domain part turns these URLs back into valid syntax. * * @param string $url The URL to decode. - * * @return string The URL with the decoded domain name. */ private function decodeDomainName( string $url ): string { diff --git a/includes/RottenLinks.php b/includes/RottenLinks.php index 2c9ede7..9496d8e 100644 --- a/includes/RottenLinks.php +++ b/includes/RottenLinks.php @@ -12,10 +12,9 @@ class RottenLinks { * Get the HTTP response status code for a given URL. * * @param string $url The URL to check. - * * @return int The HTTP status code. */ - public static function getResponse( string $url ) { + public static function getResponse( string $url ): int { $services = MediaWikiServices::getInstance(); $config = $services->getConfigFactory()->makeConfig( 'RottenLinks' ); @@ -42,7 +41,6 @@ public static function getResponse( string $url ) { * @param string $method The HTTP method to use ('HEAD' or 'GET'). * @param MediaWikiServices $services MediaWiki service instance. * @param Config $config Configuration instance. - * * @return int The HTTP status code. */ private static function getHttpStatus( @@ -50,7 +48,7 @@ private static function getHttpStatus( string $method, MediaWikiServices $services, Config $config - ) { + ): int { $httpProxy = $config->get( 'RottenLinksHTTPProxy' ); $userAgent = $config->get( 'RottenLinksUserAgent' ) ?: @@ -77,7 +75,6 @@ private static function getHttpStatus( * * @param IReadableDatabase $dbr * @param string $url - * * @return ?int null if the URL is not in the database, 0 if there was no response, or the response code */ public static function getResponseFromDatabase( IReadableDatabase $dbr, string $url ): ?int { diff --git a/includes/RottenLinksPager.php b/includes/RottenLinksPager.php index 047a642..302c9d0 100644 --- a/includes/RottenLinksPager.php +++ b/includes/RottenLinksPager.php @@ -8,6 +8,7 @@ use MediaWiki\ExternalLinks\LinkFilter; use MediaWiki\Html\Html; use MediaWiki\Linker\Linker; +use MediaWiki\Linker\LinkRenderer; use MediaWiki\Pager\TablePager; use MediaWiki\SpecialPage\SpecialPage; @@ -16,20 +17,16 @@ class RottenLinksPager extends TablePager { private Config $config; private bool $showBad; - /** - * @param IContextSource $context The context source. - * @param Config $config RottenLinks config factory instance. - * @param bool $showBad Whether to show only links with bad status. - */ public function __construct( - IContextSource $context, Config $config, + IContextSource $context, + LinkRenderer $linkRenderer, bool $showBad ) { - parent::__construct( $context ); + parent::__construct( $context, $linkRenderer ); - $this->showBad = $showBad; $this->config = $config; + $this->showBad = $showBad; } /** diff --git a/includes/SpecialRottenLinks.php b/includes/Specials/SpecialRottenLinks.php similarity index 69% rename from includes/SpecialRottenLinks.php rename to includes/Specials/SpecialRottenLinks.php index 89b29e8..b0ffbed 100644 --- a/includes/SpecialRottenLinks.php +++ b/includes/Specials/SpecialRottenLinks.php @@ -1,33 +1,26 @@ config = $configFactory->makeConfig( 'RottenLinks' ); - $this->dbLoadBalancer = $dbLoadBalancer; + $this->connectionProvider = $connectionProvider; } /** * @param ?string $par */ - public function execute( $par ) { + public function execute( $par ): void { $this->setHeaders(); $this->outputHeader(); $this->addHelpLink( 'Extension:RottenLinks' ); @@ -35,7 +28,12 @@ public function execute( $par ) { $showBad = $this->getRequest()->getBool( 'showBad' ); $stats = $this->getRequest()->getBool( 'stats' ); - $pager = new RottenLinksPager( $this->getContext(), $this->config, $showBad ); + $pager = new RottenLinksPager( + $this->getConfig(), + $this->getContext(), + $this->getLinkRenderer(), + $showBad + ); $formDescriptor = [ 'info' => [ @@ -46,21 +44,21 @@ public function execute( $par ) { 'type' => 'check', 'name' => 'showBad', 'label-message' => 'rottenlinks-showbad', - 'default' => $showBad + 'default' => $showBad, ], 'statistics' => [ 'type' => 'check', 'name' => 'stats', 'label-message' => 'rottenlinks-stats', - 'default' => $stats + 'default' => $stats, ], 'limit' => [ 'type' => 'limitselect', 'name' => 'limit', 'label-message' => 'table_pager_limit_label', 'default' => $pager->getLimit(), - 'options' => $pager->getLimitSelectList() - ] + 'options' => $pager->getLimitSelectList(), + ], ]; $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ); @@ -84,13 +82,8 @@ public function execute( $par ) { $this->getOutput()->addParserOutputContent( $pager->getFullOutput() ); } - /** - * Display statistics related to RottenLinks. - * - * @return array Array with statistics information. - */ - private function showStatistics() { - $dbr = $this->dbLoadBalancer->getMaintenanceConnectionRef( DB_REPLICA ); + private function showStatistics(): array { + $dbr = $this->connectionProvider->getReplicaDatabase(); $statusNumbers = $dbr->newSelectQueryBuilder() ->select( 'rl_respcode' ) @@ -115,19 +108,15 @@ private function showStatistics() { 'label' => "HTTP: {$respCode} " . ( $respCode != 0 ? HttpStatus::getMessage( $respCode ) : 'No Response' ), 'default' => $count, - 'section' => 'statistics' + 'section' => 'statistics', ]; } return $statDescriptor; } - /** - * Get the group name for the special page. - * - * @return string Group name. - */ - protected function getGroupName() { + /** @inheritDoc */ + protected function getGroupName(): string { return 'maintenance'; } } diff --git a/maintenance/updateExternalLinks.php b/maintenance/updateExternalLinks.php index d3992c7..8c19a3c 100644 --- a/maintenance/updateExternalLinks.php +++ b/maintenance/updateExternalLinks.php @@ -18,7 +18,7 @@ public function __construct() { $this->requireExtension( 'RottenLinks' ); } - public function execute() { + public function execute(): void { $time = time(); $dbw = $this->getDB( DB_PRIMARY ); @@ -109,7 +109,6 @@ public function execute() { * URL-decoding the domain part turns these URLs back into valid syntax. * * @param string $url The URL to decode. - * * @return string The URL with the decoded domain name. */ private function decodeDomainName( string $url ): string { From e0c40b3b99381e339ceb6ddbd5b138815a745467 Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Mon, 18 Nov 2024 14:27:02 -0700 Subject: [PATCH 4/5] Fix --- includes/Jobs/RottenLinksJob.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/includes/Jobs/RottenLinksJob.php b/includes/Jobs/RottenLinksJob.php index 7c3e8cc..865ca8d 100644 --- a/includes/Jobs/RottenLinksJob.php +++ b/includes/Jobs/RottenLinksJob.php @@ -6,6 +6,7 @@ use Job; use MediaWiki\ExternalLinks\LinkFilter; use MediaWiki\MediaWikiServices; +use Miraheze\RottenLinks\RottenLinks; class RottenLinksJob extends Job implements GenericParameterJob { @@ -19,11 +20,6 @@ public function __construct( array $params ) { $this->removedExternalLinks = $params['removedExternalLinks']; } - /** - * Execute the job, updating the 'rottenlinks' table based on added and removed external links. - * - * @return bool True on success. - */ public function run(): bool { $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'RottenLinks' ); $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); From fd4e4d9550899ce4684556a2756da7bb9e8c37bd Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Mon, 18 Nov 2024 14:30:57 -0700 Subject: [PATCH 5/5] Fix --- extension.json | 1 - 1 file changed, 1 deletion(-) diff --git a/extension.json b/extension.json index 6c38d3f..ccc1a38 100644 --- a/extension.json +++ b/extension.json @@ -36,7 +36,6 @@ "RottenLinks": { "class": "Miraheze\\RottenLinks\\Specials\\SpecialRottenLinks", "services": [ - "ConfigFactory", "ConnectionProvider" ] }