Debian Codegraph @

extensions/DiscussionTools/includes/Notifications/PlaintextEchoPresentationModelSection.php

raw symbols SCIP
1 <?php
2 /**
3 * Our override of the built-in Echo helper for displaying section titles.
4 *
5 * @file
6 * @ingroup Extensions
7 * @license MIT
8 */
9
10 namespace MediaWiki\Extension\DiscussionTools\Notifications;
11
12 use MediaWiki\Extension\Notifications\DiscussionParser;
13 use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection;
14 use RuntimeException;
15
16 /**
17 * Built-in Echo events store section titles as wikitext, and when displaying or linking to them,
18 * they parse it and then strip the formatting to get the plaintext versions.
19 *
20 * Our subscription notifications store section titles as plaintext already, so this processing is
21 * unnecessary and incorrect (text that looks like markup can disappear).
22 */
23 class PlaintextEchoPresentationModelSection extends EchoPresentationModelSection {
24
25 /**
26 * @inheritDoc
27 */
28 protected function getParsedSectionTitle() {
29 $plaintext = $this->getRawSectionTitle();
30 if ( !$plaintext ) {
31 return false;
32 }
33 $plaintext = trim( $plaintext );
34 return $this->language->truncateForVisual( $plaintext, DiscussionParser::DEFAULT_SNIPPET_LENGTH );
35 }
36
37 /**
38 * @inheritDoc
39 */
40 public function getTitleWithSection() {
41 $title = $this->event->getTitle();
42 if ( $title === null ) {
43 throw new RuntimeException( 'Event #' . $this->event->getId() . ' with no title' );
44 }
45 $section = $this->getParsedSectionTitle();
46 if ( $section ) {
47 $title = $title->createFragmentTarget( $section );
48 }
49 return $title;
50 }
51
52 /**
53 * Get truncated section title, according to user's language
54 * or a placeholder text if the section title is not available.
55 *
56 * @return string
57 */
58 public function getTruncatedSectionTitle() {
59 if ( $this->exists() ) {
60 return parent::getTruncatedSectionTitle();
61 }
62
63 return wfMessage( 'discussiontools-notification-topic-hidden' )->inLanguage( $this->language )->text();
64 }
65 }