Debian Codegraph @

extensions/DiscussionTools/includes/ThreadItem/HeadingItemTrait.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\DiscussionTools\ThreadItem;
4
5 trait HeadingItemTrait {
6 // phpcs:disable Squiz.WhiteSpace, MediaWiki.Commenting
7 // Required ThreadItem methods (listed for Phan)
8 abstract public function getName(): string;
9 // Required HeadingItem methods (listed for Phan)
10 abstract public function getHeadingLevel(): int;
11 abstract public function isPlaceholderHeading(): bool;
12 // phpcs:enable
13
14 /**
15 * @inheritDoc
16 * @suppress PhanTraitParentReference
17 */
18 public function jsonSerialize( bool $deep = false, ?callable $callback = null ): array {
19 return array_merge( [
20 'headingLevel' => $this->isPlaceholderHeading() ? null : $this->getHeadingLevel(),
21 // Used for topic subscriptions. Not added to CommentItem's yet as there is
22 // no use case for it.
23 'name' => $this->getName(),
24 ], parent::jsonSerialize( $deep, $callback ) );
25 }
26
27 /**
28 * Check whether this heading can be used for topic subscriptions.
29 */
30 public function isSubscribable(): bool {
31 return (
32 // Placeholder headings have nothing to attach the button to.
33 !$this->isPlaceholderHeading() &&
34 // We only allow subscribing to level 2 headings, because the user interface for sub-headings
35 // would be difficult to present.
36 $this->getHeadingLevel() === 2 &&
37 // Check if the name corresponds to a section that contain no comments (only sub-sections).
38 // They can't be distinguished from each other, so disallow subscribing.
39 $this->getName() !== 'h-'
40 );
41 }
42 }