2020-05-22 16:26:05 +00:00
|
|
|
<?php
|
|
|
|
|
2022-03-18 03:28:06 +00:00
|
|
|
namespace MediaWiki\Extension\DiscussionTools\ThreadItem;
|
2020-05-22 16:26:05 +00:00
|
|
|
|
2020-09-16 12:06:14 +00:00
|
|
|
use JsonSerializable;
|
2021-11-18 22:30:26 +00:00
|
|
|
use LogicException;
|
2022-03-18 03:28:06 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\CommentModifier;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\ImmutableRange;
|
2022-02-10 20:34:05 +00:00
|
|
|
use Sanitizer;
|
2021-11-18 22:30:26 +00:00
|
|
|
use Title;
|
2022-02-21 17:29:50 +00:00
|
|
|
use Wikimedia\Assert\Assert;
|
2021-11-18 22:30:26 +00:00
|
|
|
use Wikimedia\Parsoid\DOM\Element;
|
2022-02-08 22:11:24 +00:00
|
|
|
use Wikimedia\Parsoid\Utils\DOMUtils;
|
2020-07-29 23:57:51 +00:00
|
|
|
|
2020-06-25 12:23:17 +00:00
|
|
|
/**
|
|
|
|
* A thread item, either a heading or a comment
|
|
|
|
*/
|
2022-03-18 03:28:06 +00:00
|
|
|
abstract class ContentThreadItem implements JsonSerializable, ThreadItem {
|
|
|
|
use ThreadItemTrait;
|
|
|
|
|
2020-07-20 21:15:03 +00:00
|
|
|
protected $type;
|
|
|
|
protected $range;
|
2020-07-29 23:57:51 +00:00
|
|
|
protected $rootNode;
|
2020-07-20 21:15:03 +00:00
|
|
|
protected $level;
|
2020-10-01 19:36:11 +00:00
|
|
|
protected $parent;
|
2020-11-02 18:35:38 +00:00
|
|
|
protected $warnings = [];
|
2020-05-22 16:26:05 +00:00
|
|
|
|
2021-02-12 19:16:13 +00:00
|
|
|
protected $name = null;
|
2020-07-20 21:15:03 +00:00
|
|
|
protected $id = null;
|
|
|
|
protected $replies = [];
|
2020-05-22 16:26:05 +00:00
|
|
|
|
2022-07-05 23:21:34 +00:00
|
|
|
protected $authors = null;
|
|
|
|
protected $commentCount;
|
|
|
|
protected $oldestReply;
|
|
|
|
protected $latestReply;
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
/**
|
2020-06-25 12:23:17 +00:00
|
|
|
* @param string $type `heading` or `comment`
|
2020-10-01 19:36:11 +00:00
|
|
|
* @param int $level Indentation level
|
2020-06-25 12:23:17 +00:00
|
|
|
* @param ImmutableRange $range Object describing the extent of the comment, including the
|
|
|
|
* signature and timestamp.
|
2020-05-22 16:26:05 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
string $type, int $level, ImmutableRange $range
|
|
|
|
) {
|
|
|
|
$this->type = $type;
|
|
|
|
$this->level = $level;
|
|
|
|
$this->range = $range;
|
|
|
|
}
|
|
|
|
|
2021-01-28 17:19:52 +00:00
|
|
|
/**
|
|
|
|
* Get summary metadata for a thread.
|
|
|
|
*/
|
2022-07-05 23:21:34 +00:00
|
|
|
private function calculateThreadSummary(): void {
|
|
|
|
if ( $this->authors !== null ) {
|
|
|
|
return;
|
|
|
|
}
|
2021-01-28 17:19:52 +00:00
|
|
|
$authors = [];
|
|
|
|
$commentCount = 0;
|
2022-07-05 17:36:56 +00:00
|
|
|
$oldestReply = null;
|
|
|
|
$latestReply = null;
|
2022-09-06 13:35:52 +00:00
|
|
|
$threadScan = static function ( ContentThreadItem $comment ) use (
|
2022-07-05 17:36:56 +00:00
|
|
|
&$authors, &$commentCount, &$oldestReply, &$latestReply, &$threadScan
|
2021-01-28 17:19:52 +00:00
|
|
|
) {
|
2022-09-06 13:35:52 +00:00
|
|
|
if ( $comment instanceof ContentCommentItem ) {
|
2021-01-28 17:19:52 +00:00
|
|
|
$author = $comment->getAuthor();
|
2022-09-06 13:16:10 +00:00
|
|
|
if ( !isset( $authors[ $author] ) ) {
|
|
|
|
$authors[ $author ] = [
|
|
|
|
'username' => $author,
|
|
|
|
'displayNames' => [],
|
|
|
|
];
|
2021-01-28 17:19:52 +00:00
|
|
|
}
|
2022-09-06 13:16:10 +00:00
|
|
|
$displayName = $comment->getDisplayName();
|
|
|
|
if ( $displayName && !in_array( $displayName, $authors[ $author ][ 'displayNames' ], true ) ) {
|
|
|
|
$authors[ $author ][ 'displayNames' ][] = $displayName;
|
|
|
|
}
|
|
|
|
|
2022-07-05 17:36:56 +00:00
|
|
|
if (
|
|
|
|
!$oldestReply ||
|
|
|
|
( $comment->getTimestamp() < $oldestReply->getTimestamp() )
|
|
|
|
) {
|
|
|
|
$oldestReply = $comment;
|
|
|
|
}
|
2021-01-28 17:19:52 +00:00
|
|
|
if (
|
|
|
|
!$latestReply ||
|
|
|
|
( $latestReply->getTimestamp() < $comment->getTimestamp() )
|
|
|
|
) {
|
|
|
|
$latestReply = $comment;
|
|
|
|
}
|
|
|
|
$commentCount++;
|
|
|
|
}
|
|
|
|
// Get the set of authors in the same format from each reply
|
|
|
|
$replies = $comment->getReplies();
|
|
|
|
array_walk( $replies, $threadScan );
|
|
|
|
};
|
|
|
|
$replies = $this->getReplies();
|
|
|
|
array_walk( $replies, $threadScan );
|
|
|
|
|
|
|
|
ksort( $authors );
|
2022-07-05 23:21:34 +00:00
|
|
|
|
2022-09-06 13:16:10 +00:00
|
|
|
$this->authors = array_values( $authors );
|
2022-07-05 23:21:34 +00:00
|
|
|
$this->commentCount = $commentCount;
|
|
|
|
$this->oldestReply = $oldestReply;
|
|
|
|
$this->latestReply = $latestReply;
|
2021-01-28 17:19:52 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 14:13:59 +00:00
|
|
|
/**
|
2022-07-05 23:21:34 +00:00
|
|
|
* Get the list of authors in the tree below this thread item.
|
2020-07-20 14:13:59 +00:00
|
|
|
*
|
|
|
|
* Usually called on a HeadingItem to find all authors in a thread.
|
|
|
|
*
|
2022-09-06 13:16:10 +00:00
|
|
|
* @return array[] Authors, with `username` and `displayNames` (list of display names) properties.
|
2020-07-20 14:13:59 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getAuthorsBelow(): array {
|
2022-07-05 23:21:34 +00:00
|
|
|
$this->calculateThreadSummary();
|
|
|
|
return $this->authors;
|
|
|
|
}
|
2020-07-20 14:13:59 +00:00
|
|
|
|
2022-07-05 23:21:34 +00:00
|
|
|
/**
|
|
|
|
* Get the number of comment items in the tree below this thread item.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getCommentCount(): int {
|
|
|
|
$this->calculateThreadSummary();
|
|
|
|
return $this->commentCount;
|
|
|
|
}
|
2020-07-20 14:13:59 +00:00
|
|
|
|
2022-07-05 23:21:34 +00:00
|
|
|
/**
|
|
|
|
* Get the latest reply in the tree below this thread item, null if there are no replies
|
|
|
|
*
|
|
|
|
* @return ContentCommentItem|null
|
|
|
|
*/
|
|
|
|
public function getLatestReply(): ?ContentCommentItem {
|
|
|
|
$this->calculateThreadSummary();
|
|
|
|
return $this->latestReply;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the oldest reply in the tree below this thread item, null if there are no replies
|
|
|
|
*
|
|
|
|
* @return ContentCommentItem|null
|
|
|
|
*/
|
|
|
|
public function getOldestReply(): ?ContentCommentItem {
|
|
|
|
$this->calculateThreadSummary();
|
|
|
|
return $this->oldestReply;
|
2020-07-20 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 00:22:39 +00:00
|
|
|
/**
|
2022-07-05 23:21:34 +00:00
|
|
|
* Get a flat list of thread items in the comment tree below this thread item.
|
2022-02-21 00:22:39 +00:00
|
|
|
*
|
2022-03-18 03:28:06 +00:00
|
|
|
* @return ContentThreadItem[] Thread items
|
2022-02-21 00:22:39 +00:00
|
|
|
*/
|
|
|
|
public function getThreadItemsBelow(): array {
|
|
|
|
$threadItems = [];
|
2022-09-06 13:35:52 +00:00
|
|
|
$getReplies = static function ( ContentThreadItem $threadItem ) use ( &$threadItems, &$getReplies ) {
|
2022-02-21 00:22:39 +00:00
|
|
|
$threadItems[] = $threadItem;
|
|
|
|
foreach ( $threadItem->getReplies() as $reply ) {
|
|
|
|
$getReplies( $reply );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
foreach ( $this->getReplies() as $reply ) {
|
|
|
|
$getReplies( $reply );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $threadItems;
|
|
|
|
}
|
|
|
|
|
2020-07-20 14:48:41 +00:00
|
|
|
/**
|
2021-11-18 22:30:26 +00:00
|
|
|
* Get the name of the page from which this thread item is transcluded (if any). Replies to
|
|
|
|
* transcluded items must be posted on that page, instead of the current one.
|
|
|
|
*
|
|
|
|
* This is tricky, because we don't want to mark items as trancluded when they're just using a
|
|
|
|
* template (e.g. {{ping|…}} or a non-substituted signature template). Sometimes the whole comment
|
|
|
|
* can be template-generated (e.g. when using some wrapper templates), but as long as a reply can
|
|
|
|
* be added outside of that template, we should not treat it as transcluded.
|
|
|
|
*
|
|
|
|
* The start/end boundary points of comment ranges and Parsoid transclusion ranges don't line up
|
|
|
|
* exactly, even when to a human it's obvious that they cover the same content, making this more
|
|
|
|
* complicated.
|
2020-07-20 14:48:41 +00:00
|
|
|
*
|
|
|
|
* @return string|bool `false` if this item is not transcluded. A string if it's transcluded
|
|
|
|
* from a single page (the page title, in text form with spaces). `true` if it's transcluded, but
|
|
|
|
* we can't determine the source.
|
|
|
|
*/
|
|
|
|
public function getTranscludedFrom() {
|
2021-11-18 22:30:26 +00:00
|
|
|
// General approach:
|
|
|
|
//
|
|
|
|
// Compare the comment range to each transclusion range on the page, and if it overlaps any of
|
|
|
|
// them, examine the overlap. There are a few cases:
|
|
|
|
//
|
|
|
|
// * Comment and transclusion do not overlap:
|
|
|
|
// → Not transcluded.
|
|
|
|
// * Comment contains the transclusion:
|
|
|
|
// → Not transcluded (just a template).
|
|
|
|
// * Comment is contained within the transclusion:
|
|
|
|
// → Transcluded, we can determine the source page (unless it's a complex transclusion).
|
|
|
|
// * Comment and transclusion overlap partially:
|
|
|
|
// → Transcluded, but we can't determine the source page.
|
|
|
|
// * Comment (almost) exactly matches the transclusion:
|
|
|
|
// → Maybe transcluded (it could be that the source page only contains that single comment),
|
|
|
|
// maybe not transcluded (it could be a wrapper template that covers a single comment).
|
|
|
|
// This is very sad, and we decide based on the namespace.
|
|
|
|
//
|
|
|
|
// Most transclusion ranges on the page trivially fall in the "do not overlap" or "contains"
|
|
|
|
// cases, and we only have to carefully examine the two transclusion ranges that contain the
|
|
|
|
// first and last node of the comment range.
|
|
|
|
//
|
|
|
|
// To check for almost exact matches, we walk between the relevant boundary points, and if we
|
|
|
|
// only find uninteresting nodes (that would be ignored when detecting comments), we treat them
|
|
|
|
// like exact matches.
|
|
|
|
|
|
|
|
$commentRange = $this->getRange();
|
|
|
|
$startTransclNode = CommentUtils::getTranscludedFromElement(
|
|
|
|
CommentUtils::getRangeFirstNode( $commentRange )
|
|
|
|
);
|
|
|
|
$endTransclNode = CommentUtils::getTranscludedFromElement(
|
|
|
|
CommentUtils::getRangeLastNode( $commentRange )
|
|
|
|
);
|
|
|
|
|
|
|
|
// We only have to examine the two transclusion ranges that contain the first/last node of the
|
|
|
|
// comment range (if they exist). Ignore ranges outside the comment or in the middle of it.
|
|
|
|
$transclNodes = [];
|
|
|
|
if ( $startTransclNode ) {
|
|
|
|
$transclNodes[] = $startTransclNode;
|
|
|
|
}
|
|
|
|
if ( $endTransclNode && $endTransclNode !== $startTransclNode ) {
|
|
|
|
$transclNodes[] = $endTransclNode;
|
2020-06-16 14:08:01 +00:00
|
|
|
}
|
2020-07-20 14:48:41 +00:00
|
|
|
|
2021-11-18 22:30:26 +00:00
|
|
|
foreach ( $transclNodes as $transclNode ) {
|
2022-06-09 13:51:33 +00:00
|
|
|
$transclRange = static::getTransclusionRange( $transclNode );
|
2021-11-18 22:30:26 +00:00
|
|
|
$compared = CommentUtils::compareRanges( $commentRange, $transclRange );
|
2022-10-08 18:13:06 +00:00
|
|
|
$transclTitles = $this->getTransclusionTitles( $transclNode );
|
|
|
|
$simpleTransclTitle = count( $transclTitles ) === 1 ? $transclTitles[0] : null;
|
2021-11-18 22:30:26 +00:00
|
|
|
|
|
|
|
switch ( $compared ) {
|
|
|
|
case 'equal':
|
|
|
|
// Comment (almost) exactly matches the transclusion
|
2022-10-08 18:13:06 +00:00
|
|
|
if ( $simpleTransclTitle === null ) {
|
|
|
|
// Allow replying to some accidental complex transclusions consisting of only templates
|
|
|
|
// and wikitext (T313093)
|
|
|
|
if ( count( $transclTitles ) > 1 ) {
|
|
|
|
foreach ( $transclTitles as $transclTitle ) {
|
|
|
|
if ( $transclTitle && !$transclTitle->inNamespace( NS_TEMPLATE ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Continue examining the other ranges.
|
|
|
|
break;
|
|
|
|
}
|
2021-11-18 22:30:26 +00:00
|
|
|
// Multi-template transclusion, or a parser function call, or template-affected wikitext outside
|
|
|
|
// of a template call, or a mix of the above
|
|
|
|
return true;
|
2022-10-08 18:13:06 +00:00
|
|
|
|
|
|
|
} elseif ( $simpleTransclTitle->inNamespace( NS_TEMPLATE ) ) {
|
2021-11-18 22:30:26 +00:00
|
|
|
// Is that a subpage transclusion with a single comment, or a wrapper template
|
|
|
|
// transclusion on this page? We don't know, but let's guess based on the namespace.
|
|
|
|
// (T289873)
|
|
|
|
// Continue examining the other ranges.
|
|
|
|
break;
|
|
|
|
} else {
|
2022-10-08 18:13:06 +00:00
|
|
|
return $simpleTransclTitle->getPrefixedText();
|
2021-11-18 22:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case 'contains':
|
|
|
|
// Comment contains the transclusion
|
|
|
|
|
|
|
|
// If the entire transclusion is contained within the comment range, that's just a
|
|
|
|
// template. This is the same as a transclusion in the middle of the comment, which we
|
|
|
|
// ignored earlier, it just takes us longer to get here in this case.
|
|
|
|
|
|
|
|
// Continue examining the other ranges.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'contained':
|
|
|
|
// Comment is contained within the transclusion
|
2022-10-08 18:13:06 +00:00
|
|
|
if ( $simpleTransclTitle === null ) {
|
2021-11-18 22:30:26 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2022-10-08 18:13:06 +00:00
|
|
|
return $simpleTransclTitle->getPrefixedText();
|
2021-11-18 22:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case 'after':
|
|
|
|
case 'before':
|
|
|
|
// Comment and transclusion do not overlap
|
|
|
|
|
|
|
|
// This should be impossible, because we ignored these ranges earlier.
|
|
|
|
throw new LogicException( 'Unexpected transclusion or comment range' );
|
|
|
|
|
|
|
|
case 'overlapstart':
|
|
|
|
case 'overlapend':
|
|
|
|
// Comment and transclusion overlap partially
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new LogicException( 'Unexpected return value from compareRanges()' );
|
|
|
|
}
|
2020-07-20 14:48:41 +00:00
|
|
|
}
|
|
|
|
|
2021-11-18 22:30:26 +00:00
|
|
|
// If we got here, the comment range was not contained by or overlapping any of the transclusion
|
|
|
|
// ranges. Comment is not transcluded.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-08 18:13:06 +00:00
|
|
|
* Return the page titles for each part of the transclusion, or nulls for each part that isn't
|
|
|
|
* transcluded from another page.
|
|
|
|
*
|
|
|
|
* If the node represents a single-page transclusion, this will return an array containing a
|
|
|
|
* single Title object.
|
2021-11-18 22:30:26 +00:00
|
|
|
*
|
|
|
|
* @param Element $node
|
2022-10-08 18:13:06 +00:00
|
|
|
* @return (?Title)[]
|
2021-11-18 22:30:26 +00:00
|
|
|
*/
|
2022-10-08 18:13:06 +00:00
|
|
|
private function getTransclusionTitles( Element $node ): array {
|
2021-07-29 02:16:15 +00:00
|
|
|
$dataMw = json_decode( $node->getAttribute( 'data-mw' ) ?? '', true );
|
2022-10-08 18:13:06 +00:00
|
|
|
$out = [];
|
|
|
|
|
|
|
|
foreach ( $dataMw['parts'] ?? [] as $part ) {
|
|
|
|
if (
|
|
|
|
!is_string( $part ) &&
|
|
|
|
// 'href' will be unset if this is a parser function rather than a template
|
|
|
|
isset( $part['template']['target']['href'] )
|
|
|
|
) {
|
|
|
|
$parsoidHref = $part['template']['target']['href'];
|
|
|
|
Assert::precondition( substr( $parsoidHref, 0, 2 ) === './', "href has valid format" );
|
|
|
|
$out[] = Title::newFromText( urldecode( substr( $parsoidHref, 2 ) ) );
|
|
|
|
} else {
|
|
|
|
$out[] = null;
|
|
|
|
}
|
2020-07-20 14:48:41 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:13:06 +00:00
|
|
|
return $out;
|
2021-11-18 22:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a transclusion's first node (e.g. returned by CommentUtils::getTranscludedFromElement()),
|
|
|
|
* return a range starting before the node and ending after the transclusion's last node.
|
|
|
|
*
|
|
|
|
* @param Element $startNode
|
|
|
|
* @return ImmutableRange
|
|
|
|
*/
|
2022-06-28 17:34:17 +00:00
|
|
|
private function getTransclusionRange( Element $startNode ): ImmutableRange {
|
2021-11-18 22:30:26 +00:00
|
|
|
$endNode = $startNode;
|
|
|
|
while (
|
|
|
|
// Phan doesn't realize that the conditions on $nextSibling can terminate the loop
|
|
|
|
// @phan-suppress-next-line PhanInfiniteLoop
|
|
|
|
$endNode &&
|
|
|
|
( $nextSibling = $endNode->nextSibling ) &&
|
|
|
|
$nextSibling instanceof Element &&
|
|
|
|
$nextSibling->getAttribute( 'about' ) === $endNode->getAttribute( 'about' )
|
|
|
|
) {
|
|
|
|
$endNode = $nextSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
$range = new ImmutableRange(
|
|
|
|
$startNode->parentNode,
|
|
|
|
CommentUtils::childIndexOf( $startNode ),
|
|
|
|
$endNode->parentNode,
|
|
|
|
CommentUtils::childIndexOf( $endNode ) + 1
|
|
|
|
);
|
|
|
|
|
|
|
|
return $range;
|
2020-07-20 14:48:41 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 18:25:34 +00:00
|
|
|
/**
|
|
|
|
* Get the HTML of this thread item
|
|
|
|
*
|
|
|
|
* @return string HTML
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getHTML(): string {
|
2020-07-22 18:25:34 +00:00
|
|
|
$fragment = $this->getRange()->cloneContents();
|
2020-11-20 00:21:30 +00:00
|
|
|
CommentModifier::unwrapFragment( $fragment );
|
2022-02-08 22:11:24 +00:00
|
|
|
return DOMUtils::getFragmentInnerHTML( $fragment );
|
2020-07-22 18:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the text of this thread item
|
|
|
|
*
|
|
|
|
* @return string Text
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getText(): string {
|
2022-02-10 20:34:05 +00:00
|
|
|
$html = $this->getHTML();
|
|
|
|
return Sanitizer::stripAllTags( $html );
|
2020-07-22 18:25:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
/**
|
|
|
|
* @return string Thread item type
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getType(): string {
|
2020-05-22 16:26:05 +00:00
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-01 19:36:11 +00:00
|
|
|
* @return int Indentation level
|
2020-05-22 16:26:05 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getLevel(): int {
|
2020-05-22 16:26:05 +00:00
|
|
|
return $this->level;
|
|
|
|
}
|
|
|
|
|
2020-10-01 19:36:11 +00:00
|
|
|
/**
|
2022-03-18 03:28:06 +00:00
|
|
|
* @return ContentThreadItem|null Parent thread item
|
2020-10-01 19:36:11 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getParent(): ?ThreadItem {
|
2020-10-01 19:36:11 +00:00
|
|
|
return $this->parent;
|
|
|
|
}
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
/**
|
2020-07-22 18:25:34 +00:00
|
|
|
* @return ImmutableRange Range of the entire thread item
|
2020-05-22 16:26:05 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getRange(): ImmutableRange {
|
2020-05-22 16:26:05 +00:00
|
|
|
return $this->range;
|
|
|
|
}
|
|
|
|
|
2020-07-29 23:57:51 +00:00
|
|
|
/**
|
2022-02-21 18:56:15 +00:00
|
|
|
* @return Element Root node (level is relative to this node)
|
2020-07-29 23:57:51 +00:00
|
|
|
*/
|
2022-02-21 18:56:15 +00:00
|
|
|
public function getRootNode(): Element {
|
2020-07-29 23:57:51 +00:00
|
|
|
return $this->rootNode;
|
|
|
|
}
|
|
|
|
|
2021-02-12 19:16:13 +00:00
|
|
|
/**
|
|
|
|
* @return string Thread item name
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getName(): string {
|
2021-02-12 19:16:13 +00:00
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
/**
|
2020-09-22 23:05:25 +00:00
|
|
|
* @return string Thread ID
|
2020-05-22 16:26:05 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getId(): string {
|
2020-05-22 16:26:05 +00:00
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-18 03:28:06 +00:00
|
|
|
* @return ContentThreadItem[] Replies to this thread item
|
2020-05-22 16:26:05 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getReplies(): array {
|
2020-05-22 16:26:05 +00:00
|
|
|
return $this->replies;
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:35:38 +00:00
|
|
|
/**
|
|
|
|
* @return string[] Warnings
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function getWarnings(): array {
|
2020-11-02 18:35:38 +00:00
|
|
|
return $this->warnings;
|
|
|
|
}
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
/**
|
2020-10-01 19:36:11 +00:00
|
|
|
* @param int $level Indentation level
|
2020-05-22 16:26:05 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function setLevel( int $level ): void {
|
2020-05-22 16:26:05 +00:00
|
|
|
$this->level = $level;
|
|
|
|
}
|
|
|
|
|
2020-10-01 19:36:11 +00:00
|
|
|
/**
|
2022-03-18 03:28:06 +00:00
|
|
|
* @param ContentThreadItem $parent
|
2020-10-01 19:36:11 +00:00
|
|
|
*/
|
2022-03-18 03:28:06 +00:00
|
|
|
public function setParent( ContentThreadItem $parent ): void {
|
2020-10-01 19:36:11 +00:00
|
|
|
$this->parent = $parent;
|
|
|
|
}
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
/**
|
|
|
|
* @param ImmutableRange $range Thread item range
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function setRange( ImmutableRange $range ): void {
|
2020-05-22 16:26:05 +00:00
|
|
|
$this->range = $range;
|
|
|
|
}
|
|
|
|
|
2020-07-29 23:57:51 +00:00
|
|
|
/**
|
2022-02-21 18:56:15 +00:00
|
|
|
* @param Element $rootNode Root node (level is relative to this node)
|
2020-07-29 23:57:51 +00:00
|
|
|
*/
|
2022-02-21 18:56:15 +00:00
|
|
|
public function setRootNode( Element $rootNode ): void {
|
2020-07-29 23:57:51 +00:00
|
|
|
$this->rootNode = $rootNode;
|
|
|
|
}
|
|
|
|
|
2021-02-12 19:16:13 +00:00
|
|
|
/**
|
|
|
|
* @param string|null $name Thread item name
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function setName( ?string $name ): void {
|
2021-02-12 19:16:13 +00:00
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
/**
|
|
|
|
* @param string|null $id Thread ID
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function setId( ?string $id ): void {
|
2020-05-22 16:26:05 +00:00
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:35:38 +00:00
|
|
|
/**
|
2020-11-11 08:31:59 +00:00
|
|
|
* @param string $warning
|
2020-11-02 18:35:38 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function addWarning( string $warning ): void {
|
2020-11-02 18:35:38 +00:00
|
|
|
$this->warnings[] = $warning;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-11 08:31:59 +00:00
|
|
|
* @param string[] $warnings
|
2020-11-02 18:35:38 +00:00
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function addWarnings( array $warnings ): void {
|
2020-11-02 18:35:38 +00:00
|
|
|
$this->warnings = array_merge( $this->warnings, $warnings );
|
|
|
|
}
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
/**
|
2022-03-18 03:28:06 +00:00
|
|
|
* @param ContentThreadItem $reply Reply comment
|
2020-05-22 16:26:05 +00:00
|
|
|
*/
|
2022-03-18 03:28:06 +00:00
|
|
|
public function addReply( ContentThreadItem $reply ): void {
|
2020-05-22 16:26:05 +00:00
|
|
|
$this->replies[] = $reply;
|
|
|
|
}
|
|
|
|
}
|