Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 55 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
EchoWatchlistChangePresentationModel | |
0.00% |
0 / 55 |
|
0.00% |
0 / 8 |
420 | |
0.00% |
0 / 1 |
getIconType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderMessage | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
getPrimaryLink | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
getSecondaryLinks | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
getBodyMessage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
isMultiUserBundle | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
isMultiTypeBundle | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
getViewChangesUrl | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Notifications\Formatters; |
4 | |
5 | use MediaWiki\SpecialPage\SpecialPage; |
6 | |
7 | class EchoWatchlistChangePresentationModel extends EchoEventPresentationModel { |
8 | |
9 | public function getIconType() { |
10 | return 'watchlist-progressive'; |
11 | } |
12 | |
13 | public function getHeaderMessage() { |
14 | if ( $this->isMultiTypeBundle() ) { |
15 | $status = "changed"; |
16 | } else { |
17 | $status = $this->event->getExtraParam( 'status' ); |
18 | } |
19 | if ( $this->isMultiUserBundle() ) { |
20 | // Messages: notification-header-watchlist-multiuser-changed, |
21 | // notification-header-watchlist-multiuser-created |
22 | // notification-header-watchlist-multiuser-deleted |
23 | // notification-header-watchlist-multiuser-moved |
24 | // notification-header-watchlist-multiuser-restored |
25 | $msg = $this->msg( "notification-header-watchlist-multiuser-" . $status ); |
26 | } else { |
27 | // Messages: notification-header-watchlist-changed, |
28 | // notification-header-watchlist-created |
29 | // notification-header-watchlist-deleted |
30 | // notification-header-watchlist-moved |
31 | // notification-header-watchlist-restored |
32 | $msg = $this->getMessageWithAgent( "notification-header-watchlist-" . $status ); |
33 | } |
34 | $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) ); |
35 | $msg->params( $this->getViewingUserForGender() ); |
36 | $msg->numParams( $this->getBundleCount() ); |
37 | return $msg; |
38 | } |
39 | |
40 | public function getPrimaryLink() { |
41 | if ( $this->isBundled() ) { |
42 | return [ |
43 | 'url' => $this->event->getTitle()->getLocalUrl(), |
44 | 'label' => $this->msg( 'notification-link-text-view-page' )->text() |
45 | ]; |
46 | } |
47 | return [ |
48 | 'url' => $this->getViewChangesUrl(), |
49 | 'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() ) |
50 | ->text(), |
51 | ]; |
52 | } |
53 | |
54 | public function getSecondaryLinks() { |
55 | if ( $this->isBundled() ) { |
56 | if ( $this->isMultiUserBundle() ) { |
57 | return []; |
58 | } else { |
59 | return [ $this->getAgentLink() ]; |
60 | } |
61 | } else { |
62 | $viewChangesLink = [ |
63 | 'url' => $this->getViewChangesUrl(), |
64 | 'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() ) |
65 | ->text(), |
66 | 'description' => '', |
67 | 'icon' => 'changes', |
68 | 'prioritized' => true, |
69 | ]; |
70 | return [ $this->getAgentLink(), $viewChangesLink ]; |
71 | } |
72 | } |
73 | |
74 | public function getBodyMessage() { |
75 | if ( $this->event->getExtraParam( 'emailonce' ) && $this->getDistributionType() == 'email' ) { |
76 | return $this->msg( 'notification-body-watchlist-once', $this->getViewingUserForGender() ); |
77 | } |
78 | return false; |
79 | } |
80 | |
81 | private function isMultiUserBundle() { |
82 | foreach ( $this->getBundledEvents() as $bundled ) { |
83 | if ( !$bundled->getAgent()->equals( $this->event->getAgent() ) ) { |
84 | return true; |
85 | } |
86 | } |
87 | return false; |
88 | } |
89 | |
90 | private function isMultiTypeBundle() { |
91 | foreach ( $this->getBundledEvents() as $bundled ) { |
92 | if ( $bundled->getExtraParam( 'status' ) !== $this->event->getExtraParam( 'status' ) ) { |
93 | return true; |
94 | } |
95 | } |
96 | return false; |
97 | } |
98 | |
99 | private function getViewChangesUrl() { |
100 | $revid = $this->event->getExtraParam( 'revid' ); |
101 | if ( $revid === 0 ) { |
102 | $url = SpecialPage::getTitleFor( 'Log' )->getLocalUrl( [ |
103 | 'logid' => $this->event->getExtraParam( 'logid' ) |
104 | ] ); |
105 | } else { |
106 | $url = $this->event->getTitle()->getLocalURL( [ |
107 | 'oldid' => 'prev', |
108 | 'diff' => $revid |
109 | ] ); |
110 | } |
111 | return $url; |
112 | } |
113 | } |