2016-04-22 02:33:35 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Trait that adds section title handling to an EchoEventPresentationModel subclass.
|
|
|
|
*/
|
|
|
|
trait EchoPresentationModelSectionTrait {
|
2016-09-27 23:04:44 +00:00
|
|
|
private $rawSectionTitle = null;
|
|
|
|
private $parsedSectionTitle = null;
|
2016-04-22 02:33:35 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-27 23:04:44 +00:00
|
|
|
* Get the raw (unparsed) section title
|
2016-04-22 02:33:35 +00:00
|
|
|
* @return string Section title
|
|
|
|
*/
|
2016-09-27 23:04:44 +00:00
|
|
|
protected function getRawSectionTitle() {
|
|
|
|
if ( $this->rawSectionTitle !== null ) {
|
|
|
|
return $this->rawSectionTitle;
|
2016-04-22 02:33:35 +00:00
|
|
|
}
|
|
|
|
$sectionTitle = $this->event->getExtraParam( 'section-title' );
|
|
|
|
if ( !$sectionTitle ) {
|
2016-09-27 23:04:44 +00:00
|
|
|
$this->rawSectionTitle = false;
|
2016-04-22 02:33:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Check permissions
|
|
|
|
if ( !$this->userCan( Revision::DELETED_TEXT ) ) {
|
2016-09-27 23:04:44 +00:00
|
|
|
$this->rawSectionTitle = false;
|
2016-04-22 02:33:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-27 23:04:44 +00:00
|
|
|
$this->rawSectionTitle = $sectionTitle;
|
|
|
|
return $this->rawSectionTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the section title parsed to plain text
|
|
|
|
* @return string Section title (plain text)
|
|
|
|
*/
|
|
|
|
protected function getParsedSectionTitle() {
|
|
|
|
if ( $this->parsedSectionTitle !== null ) {
|
|
|
|
return $this->parsedSectionTitle;
|
|
|
|
}
|
|
|
|
$rawSectionTitle = $this->getRawSectionTitle();
|
|
|
|
if ( !$rawSectionTitle ) {
|
|
|
|
$this->parsedSectionTitle = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$this->parsedSectionTitle = EchoDiscussionParser::getTextSnippet(
|
|
|
|
$rawSectionTitle,
|
|
|
|
$this->language,
|
|
|
|
150,
|
|
|
|
$this->event->getTitle()
|
|
|
|
);
|
|
|
|
return $this->parsedSectionTitle;
|
2016-04-22 02:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
2016-09-27 23:04:44 +00:00
|
|
|
return (bool)$this->getRawSectionTitle();
|
2016-04-22 02:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a Title pointing to the section, if available.
|
|
|
|
* @return Title
|
|
|
|
*/
|
|
|
|
protected function getTitleWithSection() {
|
|
|
|
$title = $this->event->getTitle();
|
2016-09-27 23:04:44 +00:00
|
|
|
$section = $this->getParsedSectionTitle();
|
|
|
|
// Like Parser::guessSectionNameFromWikiText() but without the link stripping
|
|
|
|
$fragment = Sanitizer::escapeId(
|
|
|
|
Sanitizer::normalizeSectionNameWhitespace( $section ),
|
|
|
|
'noninitial'
|
|
|
|
);
|
2016-04-22 02:33:35 +00:00
|
|
|
if ( $section ) {
|
|
|
|
$title = Title::makeTitle(
|
|
|
|
$title->getNamespace(),
|
|
|
|
$title->getDBkey(),
|
2016-09-27 00:14:05 +00:00
|
|
|
$fragment
|
2016-04-22 02:33:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $title;
|
|
|
|
}
|
2016-09-27 23:04:44 +00:00
|
|
|
|
|
|
|
protected function getTruncatedSectionTitle() {
|
|
|
|
return $this->language->embedBidi( $this->language->truncate(
|
|
|
|
$this->getParsedSectionTitle(),
|
|
|
|
self::SECTION_TITLE_RECOMMENDED_LENGTH,
|
|
|
|
'...',
|
|
|
|
false
|
|
|
|
) );
|
|
|
|
}
|
2016-04-22 02:33:35 +00:00
|
|
|
}
|