2015-11-17 15:10:33 +00:00
|
|
|
<?php
|
|
|
|
|
2019-04-17 15:46:06 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
2015-11-17 15:10:33 +00:00
|
|
|
class EchoRevertedPresentationModel extends EchoEventPresentationModel {
|
|
|
|
|
|
|
|
public function getIconType() {
|
|
|
|
return 'revert';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function canRender() {
|
|
|
|
return (bool)$this->event->getTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeaderMessage() {
|
|
|
|
$msg = parent::getHeaderMessage();
|
2016-01-20 21:19:54 +00:00
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
|
2015-11-17 15:10:33 +00:00
|
|
|
$msg->params( $this->getNumberOfEdits() );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2016-01-14 19:58:21 +00:00
|
|
|
public function getBodyMessage() {
|
|
|
|
$summary = $this->event->getExtraParam( 'summary' );
|
2019-04-17 15:46:06 +00:00
|
|
|
if (
|
|
|
|
!$this->isAutomaticSummary( $summary ) &&
|
|
|
|
$this->userCan( RevisionRecord::DELETED_COMMENT )
|
|
|
|
) {
|
2019-04-06 00:33:28 +00:00
|
|
|
$msg = $this->msg( 'notification-body-reverted' );
|
2016-04-19 01:14:42 +00:00
|
|
|
$msg->plaintextParams( $this->formatSummary( $summary ) );
|
2016-01-14 19:58:21 +00:00
|
|
|
return $msg;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function formatSummary( $wikitext ) {
|
2016-03-30 02:16:31 +00:00
|
|
|
return EchoDiscussionParser::getTextSnippetFromSummary( $wikitext, $this->language );
|
2016-01-14 19:58:21 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 15:10:33 +00:00
|
|
|
public function getPrimaryLink() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$url = $this->event->getTitle()->getLocalURL( [
|
2015-11-17 15:10:33 +00:00
|
|
|
'oldid' => 'prev',
|
|
|
|
'diff' => $this->event->getExtraParam( 'revid' )
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
|
|
|
return [
|
2015-12-16 16:52:02 +00:00
|
|
|
'url' => $url,
|
2016-02-23 16:55:07 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text()
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-11-17 15:10:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 15:57:13 +00:00
|
|
|
public function getSecondaryLinks() {
|
2017-07-31 22:08:26 +00:00
|
|
|
$links = [ $this->getAgentLink() ];
|
2016-02-17 17:27:49 +00:00
|
|
|
|
2017-07-31 22:08:26 +00:00
|
|
|
$title = $this->event->getTitle();
|
|
|
|
if ( $title->canHaveTalkPage() ) {
|
|
|
|
$links[] = $this->getPageLink(
|
2019-12-21 05:45:14 +00:00
|
|
|
$title->getTalkPage(), '', true
|
2017-07-31 22:08:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $links;
|
2015-12-22 15:57:13 +00:00
|
|
|
}
|
2015-11-17 15:10:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a number that represents if one or multiple edits
|
|
|
|
* have been reverted for formatting purposes.
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private function getNumberOfEdits() {
|
|
|
|
$method = $this->event->getExtraParam( 'method' );
|
|
|
|
if ( $method && $method === 'rollback' ) {
|
|
|
|
return 2;
|
2018-03-26 18:54:03 +00:00
|
|
|
} else {
|
|
|
|
return 1;
|
2015-11-17 15:10:33 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-14 19:58:21 +00:00
|
|
|
|
|
|
|
private function isAutomaticSummary( $summary ) {
|
2021-08-19 22:31:10 +00:00
|
|
|
$autoSummaryMsg = $this->msg( 'undo-summary' )->inContentLanguage();
|
2016-01-14 19:58:21 +00:00
|
|
|
$autoSummaryMsg->params( $this->event->getExtraParam( 'reverted-revision-id' ) );
|
|
|
|
$autoSummaryMsg->params( $this->getViewingUserForGender() );
|
|
|
|
$autoSummary = $autoSummaryMsg->text();
|
|
|
|
|
|
|
|
return $summary === $autoSummary;
|
|
|
|
}
|
2016-05-05 13:05:03 +00:00
|
|
|
|
|
|
|
protected function getSubjectMessageKey() {
|
|
|
|
return 'notification-reverted-email-subject2';
|
|
|
|
}
|
2019-04-04 21:37:03 +00:00
|
|
|
|
|
|
|
public function getSubjectMessage() {
|
|
|
|
return parent::getSubjectMessage()->params( $this->getNumberOfEdits() );
|
|
|
|
}
|
2015-11-17 15:10:33 +00:00
|
|
|
}
|