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