2015-10-28 07:23:38 +00:00
|
|
|
<?php
|
2018-02-21 03:46:30 +00:00
|
|
|
class EchoCoreThanksPresentationModel extends EchoEventPresentationModel {
|
2015-10-28 07:23:38 +00:00
|
|
|
public function canRender() {
|
|
|
|
return (bool)$this->event->getTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIconType() {
|
|
|
|
return 'thanks';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeaderMessage() {
|
2018-02-09 07:04:06 +00:00
|
|
|
$type = $this->event->getExtraParam( 'logid' ) ? 'log' : 'rev';
|
2016-06-16 16:12:38 +00:00
|
|
|
if ( $this->isBundled() ) {
|
2018-02-09 07:04:06 +00:00
|
|
|
$msg = $this->msg( "notification-bundle-header-$type-thank" );
|
2016-06-16 16:12:38 +00:00
|
|
|
$msg->params( $this->getBundleCount() );
|
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
|
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
|
|
return $msg;
|
|
|
|
} else {
|
2018-02-09 07:04:06 +00:00
|
|
|
$msg = $this->getMessageWithAgent( "notification-header-$type-thank" );
|
2016-06-16 16:12:38 +00:00
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
|
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 10:42:53 +00:00
|
|
|
public function getCompactHeaderMessage() {
|
|
|
|
$msg = parent::getCompactHeaderMessage();
|
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2016-06-16 16:12:38 +00:00
|
|
|
public function getBodyMessage() {
|
2018-02-09 07:04:06 +00:00
|
|
|
$comment = $this->getRevOrLogComment();
|
2016-06-16 16:12:38 +00:00
|
|
|
if ( $comment ) {
|
|
|
|
$msg = new RawMessage( '$1' );
|
|
|
|
$msg->plaintextParams( $comment );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getRevisionEditSummary() {
|
|
|
|
if ( !$this->userCan( Revision::DELETED_COMMENT ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$revId = $this->event->getExtraParam( 'revid', false );
|
|
|
|
if ( !$revId ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$revision = Revision::newFromId( $revId );
|
|
|
|
if ( !$revision ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$summary = $revision->getComment( Revision::RAW );
|
|
|
|
return $summary ?: false;
|
|
|
|
}
|
|
|
|
|
2018-02-09 07:04:06 +00:00
|
|
|
/**
|
|
|
|
* Get the comment/summary/excerpt of the log entry or revision,
|
|
|
|
* for use in the notification body.
|
|
|
|
* @return string|bool The comment or false if it could not be retrieved.
|
|
|
|
*/
|
|
|
|
protected function getRevOrLogComment() {
|
|
|
|
if ( $this->event->getExtraParam( 'logid' ) ) {
|
|
|
|
// Use the saved log entry excerpt.
|
|
|
|
$excerpt = $this->event->getExtraParam( 'excerpt', false );
|
|
|
|
// Turn wikitext into plaintext
|
|
|
|
$excerpt = Linker::formatComment( $excerpt );
|
|
|
|
$excerpt = Sanitizer::stripAllTags( $excerpt );
|
|
|
|
return $excerpt;
|
|
|
|
} else {
|
|
|
|
// Try to get edit summary.
|
|
|
|
$summary = $this->getRevisionEditSummary();
|
|
|
|
if ( $summary ) {
|
|
|
|
return $summary;
|
|
|
|
}
|
|
|
|
// Fallback on edit excerpt.
|
|
|
|
if ( $this->userCan( Revision::DELETED_TEXT ) ) {
|
|
|
|
return $this->event->getExtraParam( 'excerpt', false );
|
|
|
|
}
|
2016-06-16 16:12:38 +00:00
|
|
|
}
|
2015-10-28 07:23:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrimaryLink() {
|
2018-02-09 07:04:06 +00:00
|
|
|
if ( $this->event->getExtraParam( 'logid' ) ) {
|
|
|
|
$logId = $this->event->getExtraParam( 'logid' );
|
|
|
|
$url = Title::newFromText( "Special:Redirect/logid/$logId" )->getCanonicalURL();
|
|
|
|
$label = 'notification-link-text-view-logentry';
|
|
|
|
} else {
|
|
|
|
$url = $this->event->getTitle()->getLocalURL( [
|
2015-10-28 07:23:38 +00:00
|
|
|
'oldid' => 'prev',
|
|
|
|
'diff' => $this->event->getExtraParam( 'revid' )
|
2018-02-09 07:04:06 +00:00
|
|
|
] );
|
|
|
|
$label = 'notification-link-text-view-edit';
|
|
|
|
}
|
|
|
|
return [
|
|
|
|
'url' => $url,
|
|
|
|
// Label is only used for non-JS clients.
|
|
|
|
'label' => $this->msg( $label )->text(),
|
2016-04-22 20:13:56 +00:00
|
|
|
];
|
2015-10-28 07:23:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
2016-06-16 16:12:38 +00:00
|
|
|
$pageLink = $this->getPageLink( $this->event->getTitle(), null, true );
|
|
|
|
if ( $this->isBundled() ) {
|
|
|
|
return [ $pageLink ];
|
|
|
|
} else {
|
|
|
|
return [ $this->getAgentLink(), $pageLink ];
|
|
|
|
}
|
2015-10-28 07:23:38 +00:00
|
|
|
}
|
|
|
|
}
|