2022-01-20 23:08:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Our override of the built-in Echo helper for displaying section titles.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Notifications;
|
|
|
|
|
2024-05-28 14:46:27 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DiscussionParser;
|
2023-06-08 08:16:15 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection;
|
2022-10-28 18:24:02 +00:00
|
|
|
use RuntimeException;
|
2022-01-20 23:08:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Built-in Echo events store section titles as wikitext, and when displaying or linking to them,
|
|
|
|
* they parse it and then strip the formatting to get the plaintext versions.
|
|
|
|
*
|
|
|
|
* Our subscription notifications store section titles as plaintext already, so this processing is
|
|
|
|
* unnecessary and incorrect (text that looks like markup can disappear).
|
|
|
|
*/
|
|
|
|
class PlaintextEchoPresentationModelSection extends EchoPresentationModelSection {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
protected function getParsedSectionTitle() {
|
|
|
|
$plaintext = $this->getRawSectionTitle();
|
|
|
|
if ( !$plaintext ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$plaintext = trim( $plaintext );
|
2024-05-28 14:46:27 +00:00
|
|
|
return $this->language->truncateForVisual( $plaintext, DiscussionParser::DEFAULT_SNIPPET_LENGTH );
|
2022-01-20 23:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTitleWithSection() {
|
|
|
|
$title = $this->event->getTitle();
|
|
|
|
if ( $title === null ) {
|
2022-10-28 18:24:02 +00:00
|
|
|
throw new RuntimeException( 'Event #' . $this->event->getId() . ' with no title' );
|
2022-01-20 23:08:01 +00:00
|
|
|
}
|
|
|
|
$section = $this->getParsedSectionTitle();
|
|
|
|
if ( $section ) {
|
|
|
|
$title = $title->createFragmentTarget( $section );
|
|
|
|
}
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
}
|