mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-28 02:00:57 +00:00
Add JSON serialize methods
Change-Id: Iaa24c39842cbe76370aaeba01eab2c991d290b8c
This commit is contained in:
parent
221f5c5884
commit
2a03b6e420
|
@ -35,6 +35,16 @@ class CommentItem extends ThreadItem {
|
||||||
$this->author = $author;
|
$this->author = $author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array JSON-serializable array
|
||||||
|
*/
|
||||||
|
public function jsonSerialize() : array {
|
||||||
|
return array_merge( parent::jsonSerialize(), [
|
||||||
|
'timestamp' => $this->timestamp,
|
||||||
|
'author' => $this->author,
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the HTML of this comment's body
|
* Get the HTML of this comment's body
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,6 +16,15 @@ class HeadingItem extends ThreadItem {
|
||||||
$this->placeholderHeading = $placeholderHeading;
|
$this->placeholderHeading = $placeholderHeading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array JSON-serializable array
|
||||||
|
*/
|
||||||
|
public function jsonSerialize() : array {
|
||||||
|
return array_merge( parent::jsonSerialize(), [
|
||||||
|
'placeholderHeading' => $this->placeholderHeading,
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
namespace MediaWiki\Extension\DiscussionTools;
|
namespace MediaWiki\Extension\DiscussionTools;
|
||||||
|
|
||||||
use DOMNode;
|
use DOMNode;
|
||||||
|
use JsonSerializable;
|
||||||
use Wikimedia\Parsoid\Utils\DOMCompat;
|
use Wikimedia\Parsoid\Utils\DOMCompat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A thread item, either a heading or a comment
|
* A thread item, either a heading or a comment
|
||||||
*/
|
*/
|
||||||
abstract class ThreadItem {
|
abstract class ThreadItem implements JsonSerializable {
|
||||||
protected $type;
|
protected $type;
|
||||||
protected $range;
|
protected $range;
|
||||||
protected $rootNode;
|
protected $rootNode;
|
||||||
|
@ -31,6 +32,20 @@ abstract class ThreadItem {
|
||||||
$this->range = $range;
|
$this->range = $range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array JSON-serializable array
|
||||||
|
*/
|
||||||
|
public function jsonSerialize() : array {
|
||||||
|
return [
|
||||||
|
'type' => $this->type,
|
||||||
|
'level' => $this->level,
|
||||||
|
'id' => $this->id,
|
||||||
|
'replies' => array_map( function ( CommentItem $comment ) {
|
||||||
|
return $comment->getId();
|
||||||
|
}, $this->replies )
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of authors in the comment tree below this thread item.
|
* Get the list of authors in the comment tree below this thread item.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue