mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 01:30:15 +00:00
d002512f09
Do this by default in EventPresentationModel so it automatically works for all email subject messages. Update messages to use this parameter. Also update email subject messages that were trying to use parameters that didn't exist, and fix message documentation that was completely wrong about what the parameters were. Also update translated messages to account for parameter shifts (in many cases, these messages were using the wrong parameter or a nonexistent one). Bug: T219620 Change-Id: Ia420c4db13c95d91e1bfc4c7950942df5858379b
90 lines
2.3 KiB
PHP
90 lines
2.3 KiB
PHP
<?php
|
|
|
|
class EchoRevertedPresentationModel extends EchoEventPresentationModel {
|
|
|
|
public function getIconType() {
|
|
return 'revert';
|
|
}
|
|
|
|
public function canRender() {
|
|
return (bool)$this->event->getTitle();
|
|
}
|
|
|
|
public function getHeaderMessage() {
|
|
$msg = parent::getHeaderMessage();
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
|
|
$msg->params( $this->getNumberOfEdits() );
|
|
return $msg;
|
|
}
|
|
|
|
public function getBodyMessage() {
|
|
$summary = $this->event->getExtraParam( 'summary' );
|
|
if ( !$this->isAutomaticSummary( $summary ) && $this->userCan( Revision::DELETED_COMMENT ) ) {
|
|
$msg = $this->msg( "notification-body-{$this->type}" );
|
|
$msg->plaintextParams( $this->formatSummary( $summary ) );
|
|
return $msg;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private function formatSummary( $wikitext ) {
|
|
return EchoDiscussionParser::getTextSnippetFromSummary( $wikitext, $this->language );
|
|
}
|
|
|
|
public function getPrimaryLink() {
|
|
$url = $this->event->getTitle()->getLocalURL( [
|
|
'oldid' => 'prev',
|
|
'diff' => $this->event->getExtraParam( 'revid' )
|
|
] );
|
|
return [
|
|
'url' => $url,
|
|
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text()
|
|
];
|
|
}
|
|
|
|
public function getSecondaryLinks() {
|
|
$links = [ $this->getAgentLink() ];
|
|
|
|
$title = $this->event->getTitle();
|
|
if ( $title->canHaveTalkPage() ) {
|
|
$links[] = $this->getPageLink(
|
|
$title->getTalkPage(), null, true
|
|
);
|
|
}
|
|
|
|
return $links;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
private function isAutomaticSummary( $summary ) {
|
|
$autoSummaryMsg = wfMessage( 'undo-summary' )->inContentLanguage();
|
|
$autoSummaryMsg->params( $this->event->getExtraParam( 'reverted-revision-id' ) );
|
|
$autoSummaryMsg->params( $this->getViewingUserForGender() );
|
|
$autoSummary = $autoSummaryMsg->text();
|
|
|
|
return $summary === $autoSummary;
|
|
}
|
|
|
|
protected function getSubjectMessageKey() {
|
|
return 'notification-reverted-email-subject2';
|
|
}
|
|
|
|
public function getSubjectMessage() {
|
|
return parent::getSubjectMessage()->params( $this->getNumberOfEdits() );
|
|
}
|
|
}
|