Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 62 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
EchoEditUserTalkPresentationModel | |
0.00% |
0 / 61 |
|
0.00% |
0 / 11 |
506 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
canRender | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIconType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPrimaryLink | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getSecondaryLinks | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
getHeaderMessage | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
getCompactHeaderMessage | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
getBodyMessage | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
getDiffLinkUrl | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
getRevBeforeFirstNotification | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
getSubjectMessageKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Notifications\Formatters; |
4 | |
5 | use Language; |
6 | use MediaWiki\Extension\Notifications\Model\Event; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\User\User; |
9 | |
10 | class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel { |
11 | |
12 | /** |
13 | * @var EchoPresentationModelSection |
14 | */ |
15 | protected $section; |
16 | |
17 | /** |
18 | * @inheritDoc |
19 | */ |
20 | protected function __construct( Event $event, Language $language, User $user, $distributionType ) { |
21 | parent::__construct( $event, $language, $user, $distributionType ); |
22 | $this->section = new EchoPresentationModelSection( $event, $user, $language ); |
23 | } |
24 | |
25 | public function canRender() { |
26 | return (bool)$this->event->getTitle(); |
27 | } |
28 | |
29 | public function getIconType() { |
30 | return 'edit-user-talk'; |
31 | } |
32 | |
33 | public function getPrimaryLink() { |
34 | return [ |
35 | // Need FullURL so the section is included |
36 | 'url' => $this->section->getTitleWithSection()->getFullURL(), |
37 | 'label' => $this->msg( 'notification-link-text-view-message' )->text() |
38 | ]; |
39 | } |
40 | |
41 | public function getSecondaryLinks() { |
42 | $diffLink = [ |
43 | 'url' => $this->getDiffLinkUrl(), |
44 | 'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(), |
45 | 'description' => '', |
46 | 'icon' => 'changes', |
47 | 'prioritized' => true |
48 | ]; |
49 | |
50 | if ( $this->isBundled() ) { |
51 | return [ $diffLink ]; |
52 | } else { |
53 | return [ $this->getAgentLink(), $diffLink ]; |
54 | } |
55 | } |
56 | |
57 | public function getHeaderMessage() { |
58 | if ( $this->isBundled() ) { |
59 | $msg = $this->msg( 'notification-bundle-header-edit-user-talk-v2' ); |
60 | $count = $this->getNotificationCountForOutput(); |
61 | |
62 | // Repeat is B/C until unused parameter is removed from translations |
63 | $msg->numParams( $count, $count ); |
64 | $msg->params( $this->getViewingUserForGender() ); |
65 | return $msg; |
66 | } elseif ( $this->section->exists() ) { |
67 | $msg = $this->getMessageWithAgent( 'notification-header-edit-user-talk-with-section' ); |
68 | $msg->params( $this->getViewingUserForGender() ); |
69 | $msg->plaintextParams( $this->section->getTruncatedSectionTitle() ); |
70 | return $msg; |
71 | } else { |
72 | $msg = parent::getHeaderMessage(); |
73 | $msg->params( $this->getViewingUserForGender() ); |
74 | return $msg; |
75 | } |
76 | } |
77 | |
78 | public function getCompactHeaderMessage() { |
79 | $hasSection = $this->section->exists(); |
80 | $key = $hasSection |
81 | ? 'notification-compact-header-edit-user-talk-with-section' |
82 | : 'notification-compact-header-edit-user-talk'; |
83 | $msg = $this->getMessageWithAgent( $key ); |
84 | $msg->params( $this->getViewingUserForGender() ); |
85 | if ( $hasSection ) { |
86 | $msg->params( $this->section->getTruncatedSectionTitle() ); |
87 | } |
88 | return $msg; |
89 | } |
90 | |
91 | public function getBodyMessage() { |
92 | $sectionText = $this->event->getExtraParam( 'section-text' ); |
93 | if ( !$this->isBundled() && $this->section->exists() && is_string( $sectionText ) ) { |
94 | $msg = $this->msg( 'notification-body-edit-user-talk-with-section' ); |
95 | // section-text is safe to use here, because section->exists() returns false if the revision is deleted |
96 | $msg->plaintextParams( $sectionText ); |
97 | return $msg; |
98 | } else { |
99 | return false; |
100 | } |
101 | } |
102 | |
103 | private function getDiffLinkUrl() { |
104 | $revId = $this->event->getExtraParam( 'revid' ); |
105 | $oldId = $this->isBundled() ? $this->getRevBeforeFirstNotification() : 'prev'; |
106 | $query = [ |
107 | 'oldid' => $oldId, |
108 | 'diff' => $revId, |
109 | ]; |
110 | return $this->event->getTitle()->getFullURL( $query ); |
111 | } |
112 | |
113 | private function getRevBeforeFirstNotification() { |
114 | $events = $this->getBundledEvents(); |
115 | $firstNotificationRevId = end( $events )->getExtraParam( 'revid' ); |
116 | $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup(); |
117 | $revisionRecord = $revisionLookup->getRevisionById( $firstNotificationRevId ); |
118 | $previousRevision = $revisionRecord ? $revisionLookup->getPreviousRevision( $revisionRecord ) : null; |
119 | return $previousRevision ? $previousRevision->getId() : 0; |
120 | } |
121 | |
122 | protected function getSubjectMessageKey() { |
123 | return 'notification-edit-talk-page-email-subject2'; |
124 | } |
125 | } |
126 | |
127 | class_alias( EchoEditUserTalkPresentationModel::class, 'EchoEditUserTalkPresentationModel' ); |