Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
CommentThanksPresentationModel
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 10
342
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getIconType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 canRender
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPrimaryLink
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getCommentLink
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 getHeaderMessageKey
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getHeaderMessage
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
 getCompactHeaderMessage
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getBodyMessage
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getSecondaryLinks
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * EchoEventPresentationModel for comment thanks notifications
4 *
5 * @file
6 * @ingroup Extensions
7 * @license MIT
8 */
9
10namespace MediaWiki\Extension\DiscussionTools\Notifications;
11
12use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel;
13use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection;
14use MediaWiki\Extension\Notifications\Model\Event;
15use MediaWiki\Language\Language;
16use MediaWiki\Language\RawMessage;
17use MediaWiki\Message\Message;
18use MediaWiki\Revision\RevisionRecord;
19use MediaWiki\User\User;
20
21class CommentThanksPresentationModel extends EchoEventPresentationModel {
22
23    use DiscussionToolsEventTrait;
24
25    private readonly EchoPresentationModelSection $section;
26
27    /**
28     * @inheritDoc
29     */
30    protected function __construct( Event $event, Language $language, User $user, $distributionType ) {
31        parent::__construct( $event, $language, $user, $distributionType );
32        $this->section = new EchoPresentationModelSection( $event, $user, $language );
33    }
34
35    /**
36     * @inheritDoc
37     */
38    public function getIconType() {
39        return 'thanks';
40    }
41
42    /**
43     * @inheritDoc
44     */
45    public function canRender() {
46        return (bool)$this->event->getTitle();
47    }
48
49    /**
50     * @inheritDoc
51     */
52    public function getPrimaryLink() {
53        return [
54            'url' => $this->getCommentLink() ?: $this->event->getTitle()->getFullURL(),
55            'label' => $this->msg( 'discussiontools-notification-subscribed-new-comment-view' )->text()
56        ];
57    }
58
59    /**
60     * Get a link to the individual comment, if available.
61     *
62     * @return string|null Full URL linking to the comment, null if not available
63     */
64    protected function getCommentLink(): ?string {
65        if ( !$this->userCan( RevisionRecord::DELETED_TEXT ) ) {
66            return null;
67        }
68        // Thanks notifications are bundled by comment-id, so the link will always be to a single comment
69        // (unlike in DiscussionToolsEventTrait)
70        $commentId = $this->event->getExtraParam( 'comment-id' );
71        if ( !$commentId ) {
72            return null;
73        }
74        $title = $this->event->getTitle();
75        return $title->createFragmentTarget( $commentId )->getFullURL();
76    }
77
78    /**
79     * @inheritDoc
80     */
81    protected function getHeaderMessageKey() {
82        if ( $this->isBundled() ) {
83            return 'discussiontools-notification-comment-thank-header-bundled';
84        } else {
85            return 'discussiontools-notification-comment-thank-header';
86        }
87    }
88
89    /**
90     * @inheritDoc
91     */
92    public function getHeaderMessage() {
93        $title = $this->section->getTruncatedSectionTitle();
94        if ( !$title ) {
95            // Comment could have been at the top of the page before
96            // any section titles. Use the page title instead.
97            $title = $this->event->getTitle()->getPrefixedText();
98        }
99        if ( $this->isBundled() ) {
100            $count = $this->getNotificationCountForOutput();
101            $msg = $this->msg( $this->getHeaderMessageKey() );
102
103            // Params 1, 2, 3:
104            $msg->numParams( $count );
105            $msg->plaintextParams( $title );
106            $msg->params( $this->getViewingUserForGender() );
107            return $msg;
108        } else {
109            $msg = parent::getHeaderMessage();
110            // Params 3, 4:
111            $msg->plaintextParams( $title );
112            $msg->params( $this->getViewingUserForGender() );
113            return $msg;
114        }
115    }
116
117    /**
118     * @inheritDoc
119     */
120    public function getCompactHeaderMessage() {
121        $msg = $this->getMessageWithAgent( 'discussiontools-notification-comment-thank-header-compact' );
122        // Param 3:
123        $msg->params( $this->getViewingUserForGender() );
124        return $msg;
125    }
126
127    /**
128     * @inheritDoc
129     */
130    public function getBodyMessage() {
131        if ( !$this->isBundled() ) {
132            return new RawMessage( '$1', [ Message::plaintextParam( $this->getContentSnippet() ) ] );
133        }
134    }
135
136    /**
137     * @inheritDoc
138     */
139    public function getSecondaryLinks() {
140        $pageLink = $this->getPageLink( $this->event->getTitle(), '', true );
141        if ( $this->isBundled() ) {
142            return [ $pageLink ];
143        } else {
144            return [ $this->getAgentLink(), $pageLink ];
145        }
146    }
147}