2020-05-22 16:26:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools;
|
|
|
|
|
2020-06-25 12:23:17 +00:00
|
|
|
/**
|
|
|
|
* A thread item, either a heading or a comment
|
|
|
|
*/
|
2020-05-22 16:26:05 +00:00
|
|
|
abstract class ThreadItem {
|
|
|
|
private $type;
|
|
|
|
private $range;
|
|
|
|
private $level;
|
|
|
|
|
|
|
|
private $id = null;
|
|
|
|
private $replies = [];
|
|
|
|
|
|
|
|
/**
|
2020-06-25 12:23:17 +00:00
|
|
|
* @param string $type `heading` or `comment`
|
|
|
|
* @param int $level Item level in the thread tree
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string Thread item type
|
|
|
|
*/
|
|
|
|
public function getType() : string {
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int Thread item level
|
|
|
|
*/
|
|
|
|
public function getLevel() : int {
|
|
|
|
return $this->level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ImmutableRange Thread item range
|
|
|
|
*/
|
|
|
|
public function getRange() : ImmutableRange {
|
|
|
|
return $this->range;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string|null Thread ID
|
|
|
|
*/
|
|
|
|
public function getId() : ?string {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-25 12:23:17 +00:00
|
|
|
* @return CommentItem[] Replies to this thread item
|
2020-05-22 16:26:05 +00:00
|
|
|
*/
|
|
|
|
public function getReplies() : array {
|
|
|
|
return $this->replies;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $level Thread item level
|
|
|
|
*/
|
|
|
|
public function setLevel( int $level ) : void {
|
|
|
|
$this->level = $level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ImmutableRange $range Thread item range
|
|
|
|
*/
|
|
|
|
public function setRange( ImmutableRange $range ) : void {
|
|
|
|
$this->range = $range;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|null $id Thread ID
|
|
|
|
*/
|
|
|
|
public function setId( ?string $id ) : void {
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param CommentItem $reply Reply comment
|
|
|
|
*/
|
|
|
|
public function addReply( CommentItem $reply ) : void {
|
|
|
|
$this->replies[] = $reply;
|
|
|
|
}
|
|
|
|
}
|