Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
EchoEditUserPagePresentationModel | |
0.00% |
0 / 45 |
|
0.00% |
0 / 10 |
380 | |
0.00% |
0 / 1 |
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 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getHeaderMessage | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
getCompactHeaderMessage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getBodyMessage | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |||
getDiffLinkUrl | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
getRevBeforeFirstNotification | |
0.00% |
0 / 7 |
|
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 MediaWiki\Language\RawMessage; |
6 | use MediaWiki\MediaWikiServices; |
7 | use MediaWiki\Parser\Sanitizer; |
8 | use MediaWiki\Revision\RevisionRecord; |
9 | use Message; |
10 | |
11 | class EchoEditUserPagePresentationModel extends EchoEventPresentationModel { |
12 | |
13 | public function canRender() { |
14 | return (bool)$this->event->getTitle(); |
15 | } |
16 | |
17 | public function getIconType() { |
18 | return 'edit-user-page'; |
19 | } |
20 | |
21 | public function getPrimaryLink() { |
22 | return [ |
23 | 'url' => $this->getDiffLinkUrl(), |
24 | 'label' => $this->msg( 'notification-link-text-view-edit' )->text() |
25 | ]; |
26 | } |
27 | |
28 | public function getSecondaryLinks() { |
29 | if ( $this->isBundled() ) { |
30 | return []; |
31 | } else { |
32 | return [ $this->getAgentLink() ]; |
33 | } |
34 | } |
35 | |
36 | public function getHeaderMessage() { |
37 | if ( $this->isBundled() ) { |
38 | $msg = $this->msg( 'notification-bundle-header-edit-user-page' ); |
39 | $count = $this->getNotificationCountForOutput(); |
40 | |
41 | $msg->numParams( $count ); |
42 | $msg->params( $this->getViewingUserForGender() ); |
43 | return $msg; |
44 | } else { |
45 | $msg = parent::getHeaderMessage(); |
46 | $msg->params( $this->getViewingUserForGender() ); |
47 | return $msg; |
48 | } |
49 | } |
50 | |
51 | public function getCompactHeaderMessage() { |
52 | $msg = $this->getMessageWithAgent( 'notification-compact-header-edit-user-page' ); |
53 | $msg->params( $this->getViewingUserForGender() ); |
54 | return $msg; |
55 | } |
56 | |
57 | public function getBodyMessage() { |
58 | $revision = $this->event->getRevision(); |
59 | if ( $revision && $revision->getComment() && $this->userCan( RevisionRecord::DELETED_COMMENT ) ) { |
60 | $summary = $revision->getComment()->text; |
61 | $summary = MediaWikiServices::getInstance()->getCommentFormatter()->format( $summary ); |
62 | $summary = Sanitizer::stripAllTags( $summary ); |
63 | } else { |
64 | $summary = false; |
65 | } |
66 | if ( !$this->isBundled() ) { |
67 | return new RawMessage( '$1', [ Message::plaintextParam( $summary ) ] ); |
68 | } |
69 | return false; |
70 | } |
71 | |
72 | private function getDiffLinkUrl() { |
73 | $revId = $this->event->getExtraParam( 'revid' ); |
74 | $oldId = $this->isBundled() ? $this->getRevBeforeFirstNotification() : 'prev'; |
75 | $query = [ |
76 | 'oldid' => $oldId, |
77 | 'diff' => $revId, |
78 | ]; |
79 | return $this->event->getTitle()->getFullURL( $query ); |
80 | } |
81 | |
82 | private function getRevBeforeFirstNotification() { |
83 | $events = $this->getBundledEvents(); |
84 | $firstNotificationRevId = end( $events )->getExtraParam( 'revid' ); |
85 | $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup(); |
86 | $revisionRecord = $revisionLookup->getRevisionById( $firstNotificationRevId ); |
87 | $previousRevision = $revisionRecord ? $revisionLookup->getPreviousRevision( $revisionRecord ) : null; |
88 | $oldRevisionID = $previousRevision ? $previousRevision->getId() : 0; |
89 | |
90 | return $oldRevisionID; |
91 | } |
92 | |
93 | protected function getSubjectMessageKey() { |
94 | return 'notification-edit-user-page-email-subject'; |
95 | } |
96 | } |