mediawiki-extensions-Discus.../includes/ApiDiscussionToolsTrait.php
Ed Sanders aa03dc971e Add discussiontoolscompare API
For two given revisions, this API tells us which comments have
been added and which have been removed.

Can be used to highlight new comments, or check if the page
has been updated since we first loaded it.

Bug: T281624
Bug: T300504
Change-Id: Ia4d95ffe3b7cf2317cd8e7c0f034e09f64777ef3
2022-02-08 15:53:27 +00:00

36 lines
879 B
PHP

<?php
namespace MediaWiki\Extension\DiscussionTools;
use MediaWiki\Revision\RevisionRecord;
use Title;
use Wikimedia\Parsoid\Utils\DOMCompat;
use Wikimedia\Parsoid\Utils\DOMUtils;
trait ApiDiscussionToolsTrait {
/**
* @param RevisionRecord $revision
* @return CommentParser
*/
protected function parseRevision( RevisionRecord $revision ): CommentParser {
$response = $this->requestRestbasePageHtml( $revision );
$doc = DOMUtils::parseHTML( $response['body'] );
$container = DOMCompat::getBody( $doc );
CommentUtils::unwrapParsoidSections( $container );
$title = Title::newFromLinkTarget(
$revision->getPageAsLinkTarget()
);
return CommentParser::newFromGlobalState( $container, $title );
}
/**
* @param RevisionRecord $revision
* @return array
*/
abstract protected function requestRestbasePageHtml( RevisionRecord $revision ): array;
}