Drop disabled lints

Covered by RecordLintJobTest::testDropInlineMediaCaptionLints

Change-Id: I564389ec9bd20cf36ec7a9bf96b1aebf7777cbbc
This commit is contained in:
Arlo Breault 2024-07-22 13:27:33 -04:00
parent 648b48f283
commit ed8e449e13
6 changed files with 36 additions and 9 deletions

View file

@ -86,7 +86,8 @@
"class": "MediaWiki\\Linter\\RecordLintJob", "class": "MediaWiki\\Linter\\RecordLintJob",
"services": [ "services": [
"Linter.TotalsLookup", "Linter.TotalsLookup",
"Linter.Database" "Linter.Database",
"Linter.CategoryManager"
] ]
} }
}, },

View file

@ -62,12 +62,19 @@ class CategoryManager {
*/ */
private $hasNoParams = []; private $hasNoParams = [];
/**
* @var bool[]
* @phan-var array<string,bool>
*/
private $isEnabled = [];
/** /**
* Do not instantiate directly: use MediaWikiServices to fetch. * Do not instantiate directly: use MediaWikiServices to fetch.
* @param array $linterCategories * @param array $linterCategories
*/ */
public function __construct( array $linterCategories ) { public function __construct( array $linterCategories ) {
foreach ( $linterCategories as $name => $info ) { foreach ( $linterCategories as $name => $info ) {
$this->isEnabled[$name] = $info['enabled'];
if ( $info['enabled'] ) { if ( $info['enabled'] ) {
$this->categories[$info['priority']][] = $name; $this->categories[$info['priority']][] = $name;
} }
@ -107,6 +114,11 @@ class CategoryManager {
return isset( $this->hasNoParams[$name] ); 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[] * @return string[]
*/ */

View file

@ -268,6 +268,11 @@ class Hooks implements
$catCounts = []; $catCounts = [];
foreach ( $data as $info ) { foreach ( $data as $info ) {
if ( $this->categoryManager->isKnownCategory( $info['type'] ) ) { 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; $info[ 'dbid' ] = null;
} elseif ( !isset( $info[ 'dbid' ] ) ) { } elseif ( !isset( $info[ 'dbid' ] ) ) {
continue; continue;
@ -308,10 +313,13 @@ class Hooks implements
] ]
); );
$job = new RecordLintJob( $title, [ $job = new RecordLintJob(
'errors' => $errors, $title,
'revision' => $revision, [ 'errors' => $errors, 'revision' => $revision ],
], $this->totalsLookup, $this->database ); $this->totalsLookup,
$this->database,
$this->categoryManager
);
try { try {
$this->jobQueueGroup->push( $job ); $this->jobQueueGroup->push( $job );

View file

@ -27,6 +27,7 @@ use MediaWiki\Page\PageReference;
class RecordLintJob extends Job { class RecordLintJob extends Job {
private TotalsLookup $totalsLookup; private TotalsLookup $totalsLookup;
private Database $database; private Database $database;
private CategoryManager $categoryManager;
/** /**
* RecordLintJob constructor. * RecordLintJob constructor.
@ -34,16 +35,19 @@ class RecordLintJob extends Job {
* @param array $params * @param array $params
* @param TotalsLookup $totalsLookup * @param TotalsLookup $totalsLookup
* @param Database $database * @param Database $database
* @param CategoryManager $categoryManager
*/ */
public function __construct( public function __construct(
PageReference $page, PageReference $page,
array $params, array $params,
TotalsLookup $totalsLookup, TotalsLookup $totalsLookup,
Database $database Database $database,
CategoryManager $categoryManager
) { ) {
parent::__construct( 'RecordLintJob', $page, $params ); parent::__construct( 'RecordLintJob', $page, $params );
$this->totalsLookup = $totalsLookup; $this->totalsLookup = $totalsLookup;
$this->database = $database; $this->database = $database;
$this->categoryManager = $categoryManager;
} }
public function run() { public function run() {
@ -55,7 +59,7 @@ class RecordLintJob extends Job {
// [ 'id' => LintError ] // [ 'id' => LintError ]
$errors = []; $errors = [];
foreach ( $this->params['errors'] as $errorInfo ) { 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 // Drop lints of these types for now
continue; continue;
} }

View file

@ -44,7 +44,8 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
$page, $page,
$params, $params,
$services->get( 'Linter.TotalsLookup' ), $services->get( 'Linter.TotalsLookup' ),
$this->getDatabase() $this->getDatabase(),
$services->get( 'Linter.CategoryManager' )
); );
} }

View file

@ -46,7 +46,8 @@ class SpecialLintErrorsTest extends SpecialPageTestBase {
$page, $page,
$params, $params,
$services->get( 'Linter.TotalsLookup' ), $services->get( 'Linter.TotalsLookup' ),
$this->getDatabase() $this->getDatabase(),
$services->get( 'Linter.CategoryManager' )
); );
} }