2022-03-18 03:28:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\ThreadItem;
|
|
|
|
|
2022-02-16 23:29:10 +00:00
|
|
|
use MediaWiki\Page\ProperPageIdentity;
|
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
2022-03-18 03:28:06 +00:00
|
|
|
class DatabaseHeadingItem extends DatabaseThreadItem implements HeadingItem {
|
|
|
|
use HeadingItemTrait;
|
|
|
|
|
|
|
|
/** @var bool */
|
|
|
|
private $placeholderHeading;
|
|
|
|
/** @var int */
|
|
|
|
private $headingLevel;
|
|
|
|
|
|
|
|
// Placeholder headings must have a level higher than real headings (1-6)
|
|
|
|
private const PLACEHOLDER_HEADING_LEVEL = 99;
|
|
|
|
|
|
|
|
/**
|
2022-02-16 23:29:10 +00:00
|
|
|
* @param ProperPageIdentity $page
|
|
|
|
* @param RevisionRecord $rev
|
2022-03-18 03:28:06 +00:00
|
|
|
* @param string $name
|
|
|
|
* @param string $id
|
|
|
|
* @param DatabaseThreadItem|null $parent
|
|
|
|
* @param bool|string $transcludedFrom
|
|
|
|
* @param int $level
|
|
|
|
* @param ?int $headingLevel Heading level (1-6). Use null for a placeholder heading.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-02-16 23:29:10 +00:00
|
|
|
ProperPageIdentity $page, RevisionRecord $rev,
|
2022-03-18 03:28:06 +00:00
|
|
|
string $name, string $id, ?DatabaseThreadItem $parent, $transcludedFrom, int $level,
|
|
|
|
?int $headingLevel
|
|
|
|
) {
|
2022-02-16 23:29:10 +00:00
|
|
|
parent::__construct( $page, $rev, 'heading', $name, $id, $parent, $transcludedFrom, $level );
|
2022-03-18 03:28:06 +00:00
|
|
|
$this->placeholderHeading = $headingLevel === null;
|
|
|
|
$this->headingLevel = $this->placeholderHeading ? static::PLACEHOLDER_HEADING_LEVEL : $headingLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getHeadingLevel(): int {
|
|
|
|
return $this->headingLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function isPlaceholderHeading(): bool {
|
|
|
|
return $this->placeholderHeading;
|
|
|
|
}
|
|
|
|
}
|