2022-02-16 23:29:10 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DiscussionTools data updates hooks
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
|
|
|
|
2023-12-11 15:38:02 +00:00
|
|
|
use MediaWiki\Deferred\DeferrableUpdate;
|
|
|
|
use MediaWiki\Deferred\MWCallableUpdate;
|
2022-02-16 23:29:10 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\ThreadItemStore;
|
|
|
|
use MediaWiki\Revision\RenderedRevision;
|
|
|
|
use MediaWiki\Storage\Hook\RevisionDataUpdatesHook;
|
2023-08-19 18:16:15 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-08-17 00:18:44 +00:00
|
|
|
use MWExceptionHandler;
|
|
|
|
use Throwable;
|
2022-02-16 23:29:10 +00:00
|
|
|
|
|
|
|
class DataUpdatesHooks implements RevisionDataUpdatesHook {
|
|
|
|
|
2022-10-21 19:34:18 +00:00
|
|
|
private ThreadItemStore $threadItemStore;
|
2022-02-16 23:29:10 +00:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
ThreadItemStore $threadItemStore
|
|
|
|
) {
|
|
|
|
$this->threadItemStore = $threadItemStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Title $title
|
|
|
|
* @param RenderedRevision $renderedRevision
|
|
|
|
* @param DeferrableUpdate[] &$updates
|
|
|
|
* @return bool|void
|
|
|
|
*/
|
|
|
|
public function onRevisionDataUpdates( $title, $renderedRevision, &$updates ) {
|
|
|
|
// This doesn't trigger on action=purge, only on automatic purge after editing a template or
|
|
|
|
// transcluded page, and API action=purge&forcelinkupdate=1.
|
|
|
|
|
2024-01-10 18:29:40 +00:00
|
|
|
// TODO: Deduplicate the thread-item-processing done here with the Echo hook
|
|
|
|
// (which thread-item-processes the current and previous revisions).
|
2022-02-16 23:29:10 +00:00
|
|
|
$rev = $renderedRevision->getRevision();
|
|
|
|
if ( HookUtils::isAvailableForTitle( $title ) ) {
|
2023-01-11 14:45:20 +00:00
|
|
|
$method = __METHOD__;
|
|
|
|
$updates[] = new MWCallableUpdate( function () use ( $rev, $method ) {
|
2022-08-17 00:18:44 +00:00
|
|
|
try {
|
2024-11-05 01:05:17 +00:00
|
|
|
$threadItemSet = HookUtils::parseRevisionParsoidHtml( $rev, $method )->getValueOrThrow();
|
2023-04-14 17:36:18 +00:00
|
|
|
if ( !$this->threadItemStore->isDisabled() ) {
|
|
|
|
$this->threadItemStore->insertThreadItems( $rev, $threadItemSet );
|
|
|
|
}
|
2022-08-17 00:18:44 +00:00
|
|
|
} catch ( Throwable $e ) {
|
|
|
|
// Catch errors, so that they don't cause other updates to fail (T315383), but log them.
|
|
|
|
MWExceptionHandler::logException( $e );
|
|
|
|
}
|
2022-02-16 23:29:10 +00:00
|
|
|
}, __METHOD__ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|