mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-01 03:26:28 +00:00
aa03dc971e
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
36 lines
879 B
PHP
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;
|
|
}
|