mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
Merge "Use Parsoid HTML to drive notifications"
This commit is contained in:
commit
c1049da7d5
|
@ -21,6 +21,7 @@ use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook;
|
|||
use MediaWiki\Extension\Notifications\Hooks\EchoGetEventsForRevisionHook;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
|
||||
|
||||
class EchoHooks implements
|
||||
BeforeCreateEchoEventHook,
|
||||
|
@ -130,6 +131,7 @@ class EchoHooks implements
|
|||
* @param array &$events
|
||||
* @param RevisionRecord $revision
|
||||
* @param bool $isRevert
|
||||
* @throws ResourceLimitExceededException
|
||||
*/
|
||||
public function onEchoGetEventsForRevision( array &$events, RevisionRecord $revision, bool $isRevert ) {
|
||||
if ( $isRevert ) {
|
||||
|
|
|
@ -16,7 +16,6 @@ use ExtensionRegistry;
|
|||
use IDBAccessObject;
|
||||
use Iterator;
|
||||
use MediaWiki\Deferred\DeferredUpdates;
|
||||
use MediaWiki\Extension\DiscussionTools\CommentParser;
|
||||
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
||||
use MediaWiki\Extension\DiscussionTools\ContentThreadItemSet;
|
||||
use MediaWiki\Extension\DiscussionTools\Hooks\HookUtils;
|
||||
|
@ -33,12 +32,10 @@ use MediaWiki\MediaWikiServices;
|
|||
use MediaWiki\Page\PageIdentity;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Title\Title;
|
||||
use MediaWiki\Title\TitleValue;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use ParserOptions;
|
||||
use RequestContext;
|
||||
use RuntimeException;
|
||||
use Wikimedia\Assert\Assert;
|
||||
use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
|
||||
use Wikimedia\Parsoid\Utils\DOMCompat;
|
||||
use Wikimedia\Parsoid\Utils\DOMUtils;
|
||||
|
||||
|
@ -46,42 +43,16 @@ class EventDispatcher {
|
|||
/**
|
||||
* @param RevisionRecord $revRecord
|
||||
* @return ContentThreadItemSet
|
||||
* @throws ResourceLimitExceededException
|
||||
*/
|
||||
private static function getParsedRevision( RevisionRecord $revRecord ): ContentThreadItemSet {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
|
||||
$pageRecord = $services->getPageStore()->getPageById( $revRecord->getPageId() ) ?:
|
||||
$services->getPageStore()->getPageById( $revRecord->getPageId(), IDBAccessObject::READ_LATEST );
|
||||
|
||||
Assert::postcondition( $pageRecord !== null, 'Revision had no page' );
|
||||
|
||||
// If the $revRecord was fetched from the primary database, this will also fetch the content
|
||||
// from the primary database (using the same query flags)
|
||||
// TODO: Fetch HTML from Parsoid, as we do in onRevisionDataUpdates.
|
||||
$status = $services->getParserOutputAccess()->getParserOutput(
|
||||
$pageRecord,
|
||||
ParserOptions::newFromAnon(),
|
||||
$revRecord
|
||||
);
|
||||
if ( !$status->isOK() ) {
|
||||
throw new RuntimeException( 'Could not load revision for notifications' );
|
||||
}
|
||||
|
||||
$title = TitleValue::newFromPage( $revRecord->getPage() );
|
||||
|
||||
$parserOutput = $status->getValue();
|
||||
$html = $parserOutput->getText();
|
||||
|
||||
$doc = DOMUtils::parseHTML( $html );
|
||||
$container = DOMCompat::getBody( $doc );
|
||||
/** @var CommentParser $parser */
|
||||
$parser = $services->getService( 'DiscussionTools.CommentParser' );
|
||||
return $parser->parse( $container, $title );
|
||||
return HookUtils::parseRevisionParsoidHtml( $revRecord, __METHOD__ );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array &$events
|
||||
* @param RevisionRecord $newRevRecord
|
||||
* @throws ResourceLimitExceededException
|
||||
*/
|
||||
public static function generateEventsForRevision( array &$events, RevisionRecord $newRevRecord ): void {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
|
|
Loading…
Reference in a new issue