mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-27 17:20:12 +00:00
bfb4ef65b5
Bug: T378937 Depends-On: I34c7aca80cfa96306e2c350a5f9bc723713b98c3 Change-Id: I020038da7c02d6c62071cdb3b572a527cee8fbd2
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Linter;
|
|
|
|
use MediaWiki\DomainEvent\EventSubscriberBase;
|
|
use MediaWiki\Revision\SlotRecord;
|
|
use MediaWiki\Storage\PageUpdatedEvent;
|
|
|
|
class LintSubscriber extends EventSubscriberBase {
|
|
private TotalsLookup $totalsLookup;
|
|
private Database $database;
|
|
|
|
public function __construct( TotalsLookup $totalsLookup, Database $database ) {
|
|
$this->totalsLookup = $totalsLookup;
|
|
$this->database = $database;
|
|
}
|
|
|
|
/**
|
|
* Remove entries from the linter table upon page content model change away from wikitext
|
|
*
|
|
* @noinspection PhpUnused
|
|
* @param PageUpdatedEvent $event
|
|
* @return void
|
|
*/
|
|
public function handlePageUpdatedEventAfterCommit( PageUpdatedEvent $event ) {
|
|
$page = $event->getPage();
|
|
$tags = $event->getTags();
|
|
|
|
if (
|
|
in_array( "mw-blank", $tags ) ||
|
|
(
|
|
in_array( "mw-contentmodelchange", $tags ) &&
|
|
!in_array(
|
|
$event->getNewRevision()->getSlot( SlotRecord::MAIN )->getModel(),
|
|
Hooks::LINTABLE_CONTENT_MODELS
|
|
)
|
|
)
|
|
) {
|
|
$this->totalsLookup->updateStats(
|
|
$this->database->setForPage( $page->getId(), $page->getNamespace(), [] )
|
|
);
|
|
}
|
|
}
|
|
}
|