Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 87 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
SubscribedNewCommentPresentationModel | |
0.00% |
0 / 87 |
|
0.00% |
0 / 11 |
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 | |||
jsonSerialize | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getHeaderMessageKey | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getHeaderMessage | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
getCompactHeaderMessage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getBodyMessage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getSecondaryLinks | |
0.00% |
0 / 51 |
|
0.00% |
0 / 1 |
12 | |||
getUnsubscribeConfirmationMessageKeys | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * EchoEventPresentationModel for new comments in a subscribed section |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | * @license MIT |
8 | */ |
9 | |
10 | namespace MediaWiki\Extension\DiscussionTools\Notifications; |
11 | |
12 | use EchoEventPresentationModel; |
13 | use Language; |
14 | use MediaWiki\Extension\DiscussionTools\SubscriptionStore; |
15 | use MediaWiki\Extension\Notifications\Model\Event; |
16 | use MediaWiki\Language\RawMessage; |
17 | use MediaWiki\MediaWikiServices; |
18 | use MediaWiki\User\User; |
19 | use Message; |
20 | use Wikimedia\Timestamp\TimestampException; |
21 | |
22 | class SubscribedNewCommentPresentationModel extends EchoEventPresentationModel { |
23 | use DiscussionToolsEventTrait; |
24 | |
25 | protected PlaintextEchoPresentationModelSection $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 PlaintextEchoPresentationModelSection( $event, $user, $language ); |
33 | } |
34 | |
35 | /** |
36 | * @inheritDoc |
37 | */ |
38 | public function getIconType() { |
39 | return 'chat'; |
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->section->getTitleWithSection()->getFullURL(), |
55 | 'label' => $this->msg( 'discussiontools-notification-subscribed-new-comment-view' )->text() |
56 | ]; |
57 | } |
58 | |
59 | /** |
60 | * @inheritDoc |
61 | * @throws TimestampException |
62 | */ |
63 | public function jsonSerialize(): array { |
64 | $array = parent::jsonSerialize(); |
65 | |
66 | $legacyPrimaryLink = $this->getPrimaryLink(); |
67 | $legacyPrimaryLink['url'] = $this->section->getTitleWithSection()->getFullURL(); |
68 | $array['links']['legacyPrimary'] = $this->addMarkAsRead( $legacyPrimaryLink ) ?: []; |
69 | |
70 | return $array; |
71 | } |
72 | |
73 | /** |
74 | * @inheritDoc |
75 | */ |
76 | protected function getHeaderMessageKey() { |
77 | if ( $this->isBundled() ) { |
78 | return 'discussiontools-notification-subscribed-new-comment-header-bundled'; |
79 | } else { |
80 | return 'discussiontools-notification-subscribed-new-comment-header'; |
81 | } |
82 | } |
83 | |
84 | /** |
85 | * @inheritDoc |
86 | */ |
87 | public function getHeaderMessage() { |
88 | if ( $this->isBundled() ) { |
89 | $count = $this->getNotificationCountForOutput(); |
90 | $msg = $this->msg( $this->getHeaderMessageKey() ); |
91 | |
92 | // Repeat is B/C until unused parameter is removed from translations |
93 | $msg->numParams( $count, $count ); |
94 | $msg->plaintextParams( $this->section->getTruncatedSectionTitle() ); |
95 | return $msg; |
96 | } else { |
97 | $msg = parent::getHeaderMessage(); |
98 | $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) ); |
99 | $msg->plaintextParams( $this->section->getTruncatedSectionTitle() ); |
100 | return $msg; |
101 | } |
102 | } |
103 | |
104 | /** |
105 | * @inheritDoc |
106 | */ |
107 | public function getCompactHeaderMessage() { |
108 | $msg = $this->getMessageWithAgent( 'discussiontools-notification-subscribed-new-comment-header-compact' ); |
109 | $msg->plaintextParams( $this->getContentSnippet() ); |
110 | return $msg; |
111 | } |
112 | |
113 | /** |
114 | * @inheritDoc |
115 | */ |
116 | public function getBodyMessage() { |
117 | if ( !$this->isBundled() ) { |
118 | return new RawMessage( '$1', [ Message::plaintextParam( $this->getContentSnippet() ) ] ); |
119 | } |
120 | return false; |
121 | } |
122 | |
123 | /** |
124 | * @inheritDoc |
125 | */ |
126 | public function getSecondaryLinks() { |
127 | $title = $this->event->getTitle(); |
128 | |
129 | $url = $title->getLocalURL( [ |
130 | 'oldid' => 'prev', |
131 | 'diff' => $this->event->getExtraParam( 'revid' ) |
132 | ] ); |
133 | $viewChangesLink = [ |
134 | 'url' => $url, |
135 | 'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(), |
136 | 'description' => '', |
137 | 'icon' => 'changes', |
138 | 'prioritized' => true, |
139 | ]; |
140 | |
141 | $links = [ |
142 | $this->getAgentLink(), |
143 | $viewChangesLink, |
144 | ]; |
145 | |
146 | /** @var SubscriptionStore $parser */ |
147 | $subscriptionStore = MediaWikiServices::getInstance()->getService( 'DiscussionTools.SubscriptionStore' ); |
148 | $items = $subscriptionStore->getSubscriptionItemsForUser( |
149 | $this->getUser(), |
150 | [ $this->event->getExtraParam( 'subscribed-comment-name' ) ] |
151 | ); |
152 | $isSubscribed = count( $items ) && !$items[0]->isMuted(); |
153 | if ( $isSubscribed ) { |
154 | $commentName = $this->event->getExtraParam( 'subscribed-comment-name' ); |
155 | $messageKeys = $this->getUnsubscribeConfirmationMessageKeys(); |
156 | $links[] = $this->getDynamicActionLink( |
157 | $this->event->getTitle(), |
158 | 'bellOutline', |
159 | $this->msg( 'discussiontools-topicsubscription-action-unsubscribe-button' )->text(), |
160 | null, |
161 | [ |
162 | 'tokenType' => 'csrf', |
163 | 'params' => [ |
164 | 'action' => 'discussiontoolssubscribe', |
165 | 'page' => $this->event->getTitle(), |
166 | 'commentname' => $commentName, |
167 | // 'subscribe' is unset |
168 | ], |
169 | 'messages' => [ |
170 | 'confirmation' => [ |
171 | 'title' => $this->msg( $messageKeys[ 'title' ] ), |
172 | 'description' => $this->msg( $messageKeys[ 'description' ] ), |
173 | ] |
174 | ] |
175 | ], |
176 | [ |
177 | 'action' => 'dtunsubscribe', |
178 | 'commentname' => $commentName, |
179 | ] |
180 | ); |
181 | } |
182 | |
183 | return $links; |
184 | } |
185 | |
186 | /** |
187 | * Get message keys for the unsubscribe confirmation popup |
188 | * |
189 | * @return array Array with 'title' and 'description' keys |
190 | */ |
191 | protected function getUnsubscribeConfirmationMessageKeys() { |
192 | return [ |
193 | 'title' => 'discussiontools-topicsubscription-notify-unsubscribed-title', |
194 | 'description' => 'discussiontools-topicsubscription-notify-unsubscribed-body', |
195 | ]; |
196 | } |
197 | } |