Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
EnhancedEchoEditUserTalkPresentationModel
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 getPrimaryLink
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getBodyMessage
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Our override of the built-in Echo presentation model for user talk page notifications.
4 *
5 * @file
6 * @ingroup Extensions
7 * @license MIT
8 */
9
10namespace MediaWiki\Extension\DiscussionTools\Notifications;
11
12use EchoEditUserTalkPresentationModel;
13use Message;
14use RawMessage;
15
16class EnhancedEchoEditUserTalkPresentationModel extends EchoEditUserTalkPresentationModel {
17
18    use DiscussionToolsEventTrait;
19
20    /**
21     * @inheritDoc
22     */
23    public function getPrimaryLink() {
24        $linkInfo = parent::getPrimaryLink();
25        // For events enhanced by DiscussionTools: link to the individual comment
26        $link = $this->getCommentLink();
27        if ( $link ) {
28            $linkInfo['url'] = $link;
29        }
30        return $linkInfo;
31    }
32
33    /**
34     * @inheritDoc
35     */
36    public function getBodyMessage() {
37        if ( !$this->isBundled() ) {
38            // For events enhanced by DiscussionTools: add a text snippet
39            // (Echo can only do this for new sections, not for every comment)
40            $snippet = $this->getContentSnippet();
41            if ( $snippet ) {
42                return new RawMessage( '$1', [ Message::plaintextParam( $snippet ) ] );
43            }
44        }
45        return parent::getBodyMessage();
46    }
47
48    /**
49     * @inheritDoc
50     */
51    public function jsonSerialize(): array {
52        $array = parent::jsonSerialize();
53
54        $array['links']['legacyPrimary'] = $this->addMarkAsRead( parent::getPrimaryLink() ) ?: [];
55
56        return $array;
57    }
58}