diff --git a/extension.json b/extension.json index 1b1b43d0..eb0f5791 100644 --- a/extension.json +++ b/extension.json @@ -52,10 +52,16 @@ "APIQuerySiteInfoGeneralInfo": "main", "InfoAction": "main", "WikiPageDeletionUpdates": "main", - "RevisionFromEditComplete": "main", "ParserLogLinterData": "main", "RevisionDataUpdates": "main" }, + "DomainEventSubscribers": [ + { + "events": [ "PageUpdated" ], + "class": "MediaWiki\\Linter\\LintSubscriber", + "services": [ "Linter.TotalsLookup", "Linter.Database" ] + } + ], "APIListModules": { "linterrors": { "class": "MediaWiki\\Linter\\ApiQueryLintErrors", diff --git a/includes/Hooks.php b/includes/Hooks.php index 101358fb..f5233979 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -35,16 +35,13 @@ use MediaWiki\Linker\LinkRenderer; use MediaWiki\Logger\LoggerFactory; use MediaWiki\Output\Hook\BeforePageDisplayHook; use MediaWiki\Output\OutputPage; -use MediaWiki\Page\Hook\RevisionFromEditCompleteHook; use MediaWiki\Page\Hook\WikiPageDeletionUpdatesHook; use MediaWiki\Page\ParserOutputAccess; use MediaWiki\Page\WikiPageFactory; use MediaWiki\Revision\RenderedRevision; -use MediaWiki\Revision\RevisionRecord; use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\Storage\Hook\RevisionDataUpdatesHook; use MediaWiki\Title\Title; -use MediaWiki\User\UserIdentity; use Skin; use WikiPage; @@ -53,7 +50,6 @@ class Hooks implements BeforePageDisplayHook, InfoActionHook, ParserLogLinterDataHook, - RevisionFromEditCompleteHook, WikiPageDeletionUpdatesHook, RevisionDataUpdatesHook { @@ -66,6 +62,11 @@ class Hooks implements private Database $database; private bool $parseOnDerivedDataUpdates; + /** + * This should match Parsoid's PageConfig::hasLintableContentModel() + */ + public const LINTABLE_CONTENT_MODELS = [ CONTENT_MODEL_WIKITEXT, 'proofread-page' ]; + /** * @param LinkRenderer $linkRenderer * @param JobQueueGroup $jobQueueGroup @@ -150,44 +151,6 @@ class Hooks implements }, __METHOD__ ); } - /** - * This should match Parsoid's PageConfig::hasLintableContentModel() - */ - public const LINTABLE_CONTENT_MODELS = [ CONTENT_MODEL_WIKITEXT, 'proofread-page' ]; - - /** - * Hook: RevisionFromEditComplete - * - * Remove entries from the linter table upon page content model change away from wikitext - * - * @param WikiPage $wikiPage - * @param RevisionRecord $newRevisionRecord - * @param bool|int $originalRevId - * @param UserIdentity $user - * @param string[] &$tags - */ - public function onRevisionFromEditComplete( - $wikiPage, $newRevisionRecord, $originalRevId, $user, &$tags - ) { - // This is just a stop-gap to deal with callers that aren't complying - // with the advertised hook signature. - if ( !is_array( $tags ) ) { - return; - } - - if ( - in_array( "mw-blank", $tags ) || - ( in_array( "mw-contentmodelchange", $tags ) && - !in_array( $wikiPage->getContentModel(), self::LINTABLE_CONTENT_MODELS ) ) - ) { - $this->totalsLookup->updateStats( - $this->database->setForPage( - $wikiPage->getId(), $wikiPage->getNamespace(), [] - ) - ); - } - } - /** * Hook: APIQuerySiteInfoGeneralInfo * diff --git a/includes/LintSubscriber.php b/includes/LintSubscriber.php new file mode 100644 index 00000000..4a54b8e4 --- /dev/null +++ b/includes/LintSubscriber.php @@ -0,0 +1,44 @@ +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(), [] ) + ); + } + } +}