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",
"services": [
"Linter.TotalsLookup",
"Linter.Database"
"Linter.Database",
"Linter.CategoryManager"
]
}
},

View file

@ -62,12 +62,19 @@ class CategoryManager {
*/
private $hasNoParams = [];
/**
* @var bool[]
* @phan-var array<string,bool>
*/
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[]
*/

View file

@ -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 );

View file

@ -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;
}

View file

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

View file

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