diff --git a/extension.json b/extension.json index ca6abd84..c50a0819 100644 --- a/extension.json +++ b/extension.json @@ -86,7 +86,8 @@ "class": "MediaWiki\\Linter\\RecordLintJob", "services": [ "Linter.TotalsLookup", - "Linter.Database" + "Linter.Database", + "Linter.CategoryManager" ] } }, diff --git a/includes/CategoryManager.php b/includes/CategoryManager.php index abbfb30f..7c88eef1 100644 --- a/includes/CategoryManager.php +++ b/includes/CategoryManager.php @@ -62,12 +62,19 @@ class CategoryManager { */ private $hasNoParams = []; + /** + * @var bool[] + * @phan-var array + */ + private $isEnabled = []; + /** * Do not instantiate directly: use MediaWikiServices to fetch. * @param array $linterCategories */ public function __construct( array $linterCategories ) { foreach ( $linterCategories as $name => $info ) { + $this->isEnabled[$name] = $info['enabled']; if ( $info['enabled'] ) { $this->categories[$info['priority']][] = $name; } @@ -107,6 +114,11 @@ class CategoryManager { return isset( $this->hasNoParams[$name] ); } + public function isEnabled( string $name ): bool { + // Default to true so !isKnownCategory aren't dropped + return $this->isEnabled[$name] ?? true; + } + /** * @return string[] */ diff --git a/includes/Hooks.php b/includes/Hooks.php index 04bc47a6..e2588059 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -268,6 +268,11 @@ class Hooks implements $catCounts = []; foreach ( $data as $info ) { if ( $this->categoryManager->isKnownCategory( $info['type'] ) ) { + // NOTE: Redundant with RecordLintJob, but why even create the job + if ( !$this->categoryManager->isEnabled( $info['type'] ) ) { + // Drop lints of these types for now + continue; + } $info[ 'dbid' ] = null; } elseif ( !isset( $info[ 'dbid' ] ) ) { continue; @@ -308,10 +313,13 @@ class Hooks implements ] ); - $job = new RecordLintJob( $title, [ - 'errors' => $errors, - 'revision' => $revision, - ], $this->totalsLookup, $this->database ); + $job = new RecordLintJob( + $title, + [ 'errors' => $errors, 'revision' => $revision ], + $this->totalsLookup, + $this->database, + $this->categoryManager + ); try { $this->jobQueueGroup->push( $job ); diff --git a/includes/RecordLintJob.php b/includes/RecordLintJob.php index b8f16146..df80acff 100644 --- a/includes/RecordLintJob.php +++ b/includes/RecordLintJob.php @@ -27,6 +27,7 @@ use MediaWiki\Page\PageReference; class RecordLintJob extends Job { private TotalsLookup $totalsLookup; private Database $database; + private CategoryManager $categoryManager; /** * RecordLintJob constructor. @@ -34,16 +35,19 @@ class RecordLintJob extends Job { * @param array $params * @param TotalsLookup $totalsLookup * @param Database $database + * @param CategoryManager $categoryManager */ public function __construct( PageReference $page, array $params, TotalsLookup $totalsLookup, - Database $database + Database $database, + CategoryManager $categoryManager ) { parent::__construct( 'RecordLintJob', $page, $params ); $this->totalsLookup = $totalsLookup; $this->database = $database; + $this->categoryManager = $categoryManager; } public function run() { @@ -55,7 +59,7 @@ class RecordLintJob extends Job { // [ 'id' => LintError ] $errors = []; foreach ( $this->params['errors'] as $errorInfo ) { - if ( in_array( $errorInfo['type'], [ 'inline-media-caption', 'missing-image-alt-text' ] ) ) { + if ( !$this->categoryManager->isEnabled( $errorInfo['type'] ) ) { // Drop lints of these types for now continue; } diff --git a/tests/phpunit/RecordLintJobTest.php b/tests/phpunit/RecordLintJobTest.php index cd39ff78..b75bdf9f 100644 --- a/tests/phpunit/RecordLintJobTest.php +++ b/tests/phpunit/RecordLintJobTest.php @@ -44,7 +44,8 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase { $page, $params, $services->get( 'Linter.TotalsLookup' ), - $this->getDatabase() + $this->getDatabase(), + $services->get( 'Linter.CategoryManager' ) ); } diff --git a/tests/phpunit/SpecialLintErrorsTest.php b/tests/phpunit/SpecialLintErrorsTest.php index e3cdf214..88a9e88f 100644 --- a/tests/phpunit/SpecialLintErrorsTest.php +++ b/tests/phpunit/SpecialLintErrorsTest.php @@ -46,7 +46,8 @@ class SpecialLintErrorsTest extends SpecialPageTestBase { $page, $params, $services->get( 'Linter.TotalsLookup' ), - $this->getDatabase() + $this->getDatabase(), + $services->get( 'Linter.CategoryManager' ) ); }