mediawiki-extensions-Echo/includes/formatters/PresentationModelSectionTrait.php
Roan Kattouw 33124f35a8 Move section methods into a trait
Change-Id: Ief2005918b92945ff93aea85d17e595c7c38adf2
2016-04-28 20:52:09 +00:00

60 lines
1.3 KiB
PHP

<?php
/**
* Trait that adds section title handling to an EchoEventPresentationModel subclass.
*/
trait EchoPresentationModelSectionTrait {
private $sectionTitle = null;
/**
* Get the section title
* @return string Section title
*/
protected function getSection() {
if ( $this->sectionTitle !== null ) {
return $this->sectionTitle;
}
$sectionTitle = $this->event->getExtraParam( 'section-title' );
if ( !$sectionTitle ) {
$this->sectionTitle = false;
return false;
}
// Check permissions
if ( !$this->userCan( Revision::DELETED_TEXT ) ) {
$this->sectionTitle = false;
return false;
}
$this->sectionTitle = $sectionTitle;
return $this->sectionTitle;
}
/**
* Check if there is a section.
*
* This also returns false if the revision is deleted,
* even if there is a section, because the section can't
* be viewed in that case.
* @return boolean Whether there is a section
*/
protected function hasSection() {
return (bool)$this->getSection();
}
/**
* Get a Title pointing to the section, if available.
* @return Title
*/
protected function getTitleWithSection() {
$title = $this->event->getTitle();
$section = $this->getSection();
if ( $section ) {
$title = Title::makeTitle(
$title->getNamespace(),
$title->getDBkey(),
$section
);
}
return $title;
}
}