2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class EchoMentionPresentationModel extends EchoEventPresentationModel {
|
2016-04-22 02:33:35 +00:00
|
|
|
use EchoPresentationModelSectionTrait;
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
public function getIconType() {
|
2016-01-13 04:24:11 +00:00
|
|
|
return 'mention';
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-28 17:15:25 +00:00
|
|
|
public function canRender() {
|
|
|
|
return (bool)$this->event->getTitle();
|
|
|
|
}
|
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
protected function getHeaderMessageKey() {
|
2016-01-19 22:09:15 +00:00
|
|
|
if ( $this->onArticleTalkpage() ) {
|
2016-04-22 02:33:35 +00:00
|
|
|
return $this->hasSection() ?
|
|
|
|
'notification-header-mention-article-talkpage' :
|
|
|
|
'notification-header-mention-article-talkpage-nosection';
|
2016-01-19 22:09:15 +00:00
|
|
|
} elseif ( $this->onAgentTalkpage() ) {
|
2016-04-22 02:33:35 +00:00
|
|
|
return $this->hasSection() ?
|
|
|
|
'notification-header-mention-agent-talkpage' :
|
|
|
|
'notification-header-mention-agent-talkpage-nosection';
|
2016-01-19 22:09:15 +00:00
|
|
|
} elseif ( $this->onUserTalkpage() ) {
|
2016-04-22 02:33:35 +00:00
|
|
|
return $this->hasSection() ?
|
|
|
|
'notification-header-mention-user-talkpage-v2' :
|
|
|
|
'notification-header-mention-user-talkpage-nosection';
|
2016-01-19 22:09:15 +00:00
|
|
|
} else {
|
2016-04-22 02:33:35 +00:00
|
|
|
return $this->hasSection() ?
|
|
|
|
'notification-header-mention-other' :
|
|
|
|
'notification-header-mention-other-nosection';
|
2016-01-19 22:09:15 +00:00
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeaderMessage() {
|
2016-01-19 22:09:15 +00:00
|
|
|
$msg = $this->getMessageWithAgent( $this->getHeaderMessageKey() );
|
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
|
|
|
|
|
|
if ( $this->onArticleTalkpage() ) {
|
2016-01-20 21:19:54 +00:00
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle() ) );
|
2016-01-19 22:09:15 +00:00
|
|
|
} elseif ( $this->onAgentTalkpage() ) {
|
|
|
|
// No params to add here.
|
|
|
|
// If we remove this check, onUserTalkpage() has to
|
|
|
|
// make sure it is a user talk page but NOT the agent's talk page.
|
|
|
|
} elseif ( $this->onUserTalkpage() ) {
|
2016-01-29 16:08:51 +00:00
|
|
|
$username = $this->event->getTitle()->getText();
|
2016-03-11 22:38:25 +00:00
|
|
|
$msg->params( $this->getTruncatedUsername( User::newFromName( $username, false ) ) );
|
2016-01-29 16:08:51 +00:00
|
|
|
$msg->params( $username );
|
2016-01-19 22:09:15 +00:00
|
|
|
} else {
|
2016-01-20 21:19:54 +00:00
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
|
2016-01-19 22:09:15 +00:00
|
|
|
}
|
|
|
|
|
2016-04-22 02:33:35 +00:00
|
|
|
if ( $this->hasSection() ) {
|
|
|
|
$msg->plaintextParams( $this->getTruncatedSectionTitle( $this->getSection() ) );
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2016-01-20 01:19:05 +00:00
|
|
|
public function getBodyMessage() {
|
|
|
|
$content = $this->event->getExtraParam( 'content' );
|
|
|
|
if ( $content && $this->userCan( Revision::DELETED_TEXT ) ) {
|
|
|
|
$msg = $this->msg( 'notification-body-mention' );
|
2016-04-19 01:14:42 +00:00
|
|
|
$msg->plaintextParams(
|
2016-01-20 01:19:05 +00:00
|
|
|
EchoDiscussionParser::getTextSnippet(
|
|
|
|
$content,
|
|
|
|
$this->language
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $msg;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
public function getPrimaryLink() {
|
|
|
|
return array(
|
2016-01-19 17:35:26 +00:00
|
|
|
// Need FullURL so the section is included
|
2016-04-22 02:33:35 +00:00
|
|
|
'url' => $this->getTitleWithSection()->getFullURL(),
|
2015-12-16 16:52:02 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-view-mention' )->text()
|
2015-08-19 20:22:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
2016-01-19 22:09:15 +00:00
|
|
|
$title = $this->event->getTitle();
|
|
|
|
|
|
|
|
$url = $title->getLocalURL( array(
|
2015-08-19 20:22:45 +00:00
|
|
|
'oldid' => 'prev',
|
|
|
|
'diff' => $this->event->getExtraParam( 'revid' )
|
|
|
|
) );
|
2015-12-22 15:57:13 +00:00
|
|
|
$viewChangesLink = array(
|
|
|
|
'url' => $url,
|
2016-02-23 16:55:07 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(),
|
2015-12-22 15:57:13 +00:00
|
|
|
'description' => '',
|
2016-01-15 06:34:04 +00:00
|
|
|
'icon' => 'changes',
|
2015-12-22 15:57:13 +00:00
|
|
|
'prioritized' => true,
|
2015-08-19 20:22:45 +00:00
|
|
|
);
|
2016-01-19 22:09:15 +00:00
|
|
|
|
2016-02-26 22:16:23 +00:00
|
|
|
return array( $this->getAgentLink(), $viewChangesLink );
|
2016-01-19 22:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function onArticleTalkpage() {
|
|
|
|
return $this->event->getTitle()->getNamespace() === NS_TALK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function onAgentTalkpage() {
|
2016-03-15 22:50:40 +00:00
|
|
|
return $this->event->getTitle()->equals( $this->event->getAgent()->getTalkPage() );
|
2016-01-19 22:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function onUserTalkpage() {
|
2016-03-23 14:19:41 +00:00
|
|
|
return $this->event->getTitle()->getNamespace() === NS_USER_TALK &&
|
|
|
|
$this->event->getTitle()->isTalkPage() &&
|
|
|
|
!$this->event->getTitle()->isSubpage();
|
2016-01-19 22:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function isTalk() {
|
|
|
|
return $this->event->getTitle()->isTalkPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isArticle() {
|
|
|
|
$ns = $this->event->getTitle()->getNamespace();
|
|
|
|
return $ns === NS_MAIN || $ns === NS_TALK;
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
2016-05-05 13:05:03 +00:00
|
|
|
|
|
|
|
protected function getSubjectMessageKey() {
|
|
|
|
return 'notification-mention-email-subject';
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|