Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PlaintextEchoPresentationModelSection
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 getParsedSectionTitle
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getTitleWithSection
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
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
10namespace MediaWiki\Extension\DiscussionTools\Notifications;
11
12use MediaWiki\Extension\Notifications\DiscussionParser;
13use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection;
14use 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 */
23class 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}