| 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 |
|
| 20 |
$msg = parent::getHeaderMessage(); |
| 21 |
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) ); |
| 22 |
$msg->params( $this->getNumberOfEdits() ); |
| 23 |
return $msg; |
| 24 |
} |
| 25 |
|
| 26 |
public function getBodyMessage() { |
| 27 |
$summary = $this->event->getExtraParam( 'summary' ); |
| 28 |
if ( |
| 29 |
!$this->isAutomaticSummary( $summary ) && |
| 30 |
$this->userCan( RevisionRecord::DELETED_COMMENT ) |
| 31 |
) { |
| 32 |
$msg = $this->msg( 'notification-body-reverted' ); |
| 33 |
$msg->plaintextParams( $this->formatSummary( $summary ) ); |
| 34 |
return $msg; |
| 35 |
} else { |
| 36 |
return false; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
private function formatSummary( $wikitext ) { |
| 45 |
if ( $wikitext === null || $wikitext === '' ) { |
| 46 |
return ''; |
| 47 |
} |
| 48 |
return DiscussionParser::getTextSnippetFromSummary( $wikitext, $this->language ); |
| 49 |
} |
| 50 |
|
| 51 |
public function getPrimaryLink() { |
| 52 |
$url = $this->event->getTitle()->getLocalURL( [ |
| 53 |
'oldid' => 'prev', |
| 54 |
'diff' => $this->event->getExtraParam( 'revid' ) |
| 55 |
] ); |
| 56 |
return [ |
| 57 |
'url' => $url, |
| 58 |
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text() |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
public function getSecondaryLinks() { |
| 63 |
$links = [ $this->getAgentLink() ]; |
| 64 |
|
| 65 |
$title = $this->event->getTitle(); |
| 66 |
if ( $title->canHaveTalkPage() ) { |
| 67 |
$links[] = $this->getPageLink( |
| 68 |
$title->getTalkPage(), '', true |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
return $links; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
private function getNumberOfEdits() { |
| 81 |
$method = $this->event->getExtraParam( 'method' ); |
| 82 |
if ( $method && $method === 'rollback' ) { |
| 83 |
return 2; |
| 84 |
} else { |
| 85 |
return 1; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
private function isAutomaticSummary( $summary ) { |
| 94 |
if ( $summary === null || $summary === '' ) { |
| 95 |
return false; |
| 96 |
} |
| 97 |
$autoSummaryMsg = $this->msg( 'undo-summary' )->inContentLanguage(); |
| 98 |
$autoSummaryMsg->params( $this->event->getExtraParam( 'reverted-revision-id' ) ); |
| 99 |
$autoSummaryMsg->params( $this->getViewingUserForGender() ); |
| 100 |
$autoSummary = $autoSummaryMsg->text(); |
| 101 |
|
| 102 |
return $summary === $autoSummary; |
| 103 |
} |
| 104 |
|
| 105 |
protected function getSubjectMessageKey() { |
| 106 |
return 'notification-reverted-email-subject2'; |
| 107 |
} |
| 108 |
|
| 109 |
public function getSubjectMessage() { |
| 110 |
return parent::getSubjectMessage()->params( $this->getNumberOfEdits() ); |
| 111 |
} |
| 112 |
} |