mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
880f9755e0
Rename ThreadItem to ContentThreadItem, then create a new ThreadItem interface containing only the methods that we'll be able to implement using only the persistently stored data (no parsing), then create a DatabaseThreadItem. Do the same for CommentItem and HeadingItem. ThreadItemSet gets a similar treatment, but it's basically only for Phan's type checking. (This is sad.) Change-Id: I1633049befe8ec169753b82eb876459af1f63fe8
45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\ThreadItem;
|
|
|
|
trait HeadingItemTrait {
|
|
// phpcs:disable Squiz.WhiteSpace, MediaWiki.Commenting
|
|
// Required ThreadItem methods (listed for Phan)
|
|
abstract public function getName(): string;
|
|
// Required HeadingItem methods (listed for Phan)
|
|
abstract public function getHeadingLevel(): int;
|
|
abstract public function isPlaceholderHeading(): bool;
|
|
// phpcs:enable
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @suppress PhanTraitParentReference
|
|
*/
|
|
public function jsonSerialize( bool $deep = false, ?callable $callback = null ): array {
|
|
return array_merge( parent::jsonSerialize( $deep, $callback ), [
|
|
'headingLevel' => $this->isPlaceholderHeading() ? null : $this->getHeadingLevel(),
|
|
// Used for topic subscriptions. Not added to CommentItem's yet as there is
|
|
// no use case for it.
|
|
'name' => $this->getName(),
|
|
] );
|
|
}
|
|
|
|
/**
|
|
* Check whether this heading can be used for topic subscriptions.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isSubscribable(): bool {
|
|
return (
|
|
// Placeholder headings have nothing to attach the button to.
|
|
!$this->isPlaceholderHeading() &&
|
|
// We only allow subscribing to level 2 headings, because the user interface for sub-headings
|
|
// would be difficult to present.
|
|
$this->getHeadingLevel() === 2 &&
|
|
// Check if the name corresponds to a section that contain no comments (only sub-sections).
|
|
// They can't be distinguished from each other, so disallow subscribing.
|
|
$this->getName() !== 'h-'
|
|
);
|
|
}
|
|
}
|