Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
EchoRevertedPresentationModel | |
0.00% |
0 / 44 |
|
0.00% |
0 / 11 |
420 | |
0.00% |
0 / 1 |
getIconType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
canRender | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderMessage | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getBodyMessage | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
formatSummary | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
getPrimaryLink | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getSecondaryLinks | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
getNumberOfEdits | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
isAutomaticSummary | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getSubjectMessageKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSubjectMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Notifications\Formatters; |
4 | |
5 | use MediaWiki\Extension\Notifications\DiscussionParser; |
6 | use MediaWiki\Revision\RevisionRecord; |
7 | |
8 | class EchoRevertedPresentationModel extends EchoEventPresentationModel { |
9 | |
10 | public function getIconType() { |
11 | return 'revert'; |
12 | } |
13 | |
14 | public function canRender() { |
15 | return (bool)$this->event->getTitle(); |
16 | } |
17 | |
18 | public function getHeaderMessage() { |
19 | $msg = parent::getHeaderMessage(); |
20 | $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) ); |
21 | $msg->params( $this->getNumberOfEdits() ); |
22 | return $msg; |
23 | } |
24 | |
25 | public function getBodyMessage() { |
26 | $summary = $this->event->getExtraParam( 'summary' ); |
27 | if ( |
28 | !$this->isAutomaticSummary( $summary ) && |
29 | $this->userCan( RevisionRecord::DELETED_COMMENT ) |
30 | ) { |
31 | $msg = $this->msg( 'notification-body-reverted' ); |
32 | $msg->plaintextParams( $this->formatSummary( $summary ) ); |
33 | return $msg; |
34 | } else { |
35 | return false; |
36 | } |
37 | } |
38 | |
39 | /** |
40 | * @param string|null $wikitext |
41 | * @return string |
42 | */ |
43 | private function formatSummary( $wikitext ) { |
44 | if ( $wikitext === null || $wikitext === '' ) { |
45 | return ''; |
46 | } |
47 | return DiscussionParser::getTextSnippetFromSummary( $wikitext, $this->language ); |
48 | } |
49 | |
50 | public function getPrimaryLink() { |
51 | $url = $this->event->getTitle()->getLocalURL( [ |
52 | 'oldid' => 'prev', |
53 | 'diff' => $this->event->getExtraParam( 'revid' ) |
54 | ] ); |
55 | return [ |
56 | 'url' => $url, |
57 | 'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text() |
58 | ]; |
59 | } |
60 | |
61 | public function getSecondaryLinks() { |
62 | $links = [ $this->getAgentLink() ]; |
63 | |
64 | $title = $this->event->getTitle(); |
65 | if ( $title->canHaveTalkPage() ) { |
66 | $links[] = $this->getPageLink( |
67 | $title->getTalkPage(), '', true |
68 | ); |
69 | } |
70 | |
71 | return $links; |
72 | } |
73 | |
74 | /** |
75 | * Return a number that represents if one or multiple edits |
76 | * have been reverted for formatting purposes. |
77 | * @return int |
78 | */ |
79 | private function getNumberOfEdits() { |
80 | $method = $this->event->getExtraParam( 'method' ); |
81 | if ( $method && $method === 'rollback' ) { |
82 | return 2; |
83 | } else { |
84 | return 1; |
85 | } |
86 | } |
87 | |
88 | /** |
89 | * @param string|null $summary |
90 | * @return bool |
91 | */ |
92 | private function isAutomaticSummary( $summary ) { |
93 | if ( $summary === null || $summary === '' ) { |
94 | return false; |
95 | } |
96 | $autoSummaryMsg = $this->msg( 'undo-summary' )->inContentLanguage(); |
97 | $autoSummaryMsg->params( $this->event->getExtraParam( 'reverted-revision-id' ) ); |
98 | $autoSummaryMsg->params( $this->getViewingUserForGender() ); |
99 | $autoSummary = $autoSummaryMsg->text(); |
100 | |
101 | return $summary === $autoSummary; |
102 | } |
103 | |
104 | protected function getSubjectMessageKey() { |
105 | return 'notification-reverted-email-subject2'; |
106 | } |
107 | |
108 | public function getSubjectMessage() { |
109 | return parent::getSubjectMessage()->params( $this->getNumberOfEdits() ); |
110 | } |
111 | } |