2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DiscussionParser;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
2024-10-19 22:55:03 +00:00
|
|
|
use MediaWiki\Language\Language;
|
2019-04-17 15:46:06 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\User;
|
2019-04-17 15:46:06 +00:00
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
class EchoMentionPresentationModel extends EchoEventPresentationModel {
|
2019-04-05 20:50:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var EchoPresentationModelSection
|
|
|
|
*/
|
2022-01-20 22:29:39 +00:00
|
|
|
protected $section;
|
2019-04-05 20:50:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2022-11-02 21:34:17 +00:00
|
|
|
protected function __construct( Event $event, Language $language, User $user, $distributionType ) {
|
2019-04-05 20:50:03 +00:00
|
|
|
parent::__construct( $event, $language, $user, $distributionType );
|
|
|
|
$this->section = new EchoPresentationModelSection( $event, $user, $language );
|
|
|
|
}
|
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() {
|
2019-04-05 20:50:03 +00:00
|
|
|
$hasSection = $this->section->exists();
|
2016-08-12 01:41:08 +00:00
|
|
|
if ( $this->onArticleTalkpage() ) {
|
2019-04-05 20:50:03 +00:00
|
|
|
return $hasSection ?
|
2016-04-22 02:33:35 +00:00
|
|
|
'notification-header-mention-article-talkpage' :
|
|
|
|
'notification-header-mention-article-talkpage-nosection';
|
2016-01-19 22:09:15 +00:00
|
|
|
} elseif ( $this->onAgentTalkpage() ) {
|
2019-04-05 20:50:03 +00:00
|
|
|
return $hasSection ?
|
2016-04-22 02:33:35 +00:00
|
|
|
'notification-header-mention-agent-talkpage' :
|
|
|
|
'notification-header-mention-agent-talkpage-nosection';
|
2016-01-19 22:09:15 +00:00
|
|
|
} elseif ( $this->onUserTalkpage() ) {
|
2019-04-05 20:50:03 +00:00
|
|
|
return $hasSection ?
|
2016-04-22 02:33:35 +00:00
|
|
|
'notification-header-mention-user-talkpage-v2' :
|
|
|
|
'notification-header-mention-user-talkpage-nosection';
|
2016-01-19 22:09:15 +00:00
|
|
|
} else {
|
2019-04-05 20:50:03 +00:00
|
|
|
return $hasSection ?
|
2016-04-22 02:33:35 +00:00
|
|
|
'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-08-12 01:41:08 +00:00
|
|
|
$msg = $this->getMessageWithAgent( $this->getHeaderMessageKey() );
|
2016-01-19 22:09:15 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2019-04-05 20:50:03 +00:00
|
|
|
if ( $this->section->exists() ) {
|
|
|
|
$msg->plaintextParams( $this->section->getTruncatedSectionTitle() );
|
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' );
|
2019-04-17 15:46:06 +00:00
|
|
|
if ( $content && $this->userCan( RevisionRecord::DELETED_TEXT ) ) {
|
2016-01-20 01:19:05 +00:00
|
|
|
$msg = $this->msg( 'notification-body-mention' );
|
2016-04-19 01:14:42 +00:00
|
|
|
$msg->plaintextParams(
|
2022-11-12 07:19:00 +00:00
|
|
|
DiscussionParser::getTextSnippet(
|
2016-01-20 01:19:05 +00:00
|
|
|
$content,
|
2016-09-01 20:48:56 +00:00
|
|
|
$this->language,
|
2022-11-12 07:19:00 +00:00
|
|
|
DiscussionParser::DEFAULT_SNIPPET_LENGTH,
|
2016-09-01 20:48:56 +00:00
|
|
|
$this->event->getTitle()
|
2016-01-20 01:19:05 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
return $msg;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
public function getPrimaryLink() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2016-01-19 17:35:26 +00:00
|
|
|
// Need FullURL so the section is included
|
2019-04-05 20:50:03 +00:00
|
|
|
'url' => $this->section->getTitleWithSection()->getFullURL(),
|
2015-12-16 16:52:02 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-view-mention' )->text()
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
2022-11-01 21:39:23 +00:00
|
|
|
$url = $this->event->getTitle()->getLocalURL( [
|
2015-08-19 20:22:45 +00:00
|
|
|
'oldid' => 'prev',
|
|
|
|
'diff' => $this->event->getExtraParam( 'revid' )
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
|
|
|
$viewChangesLink = [
|
2015-12-22 15:57:13 +00:00
|
|
|
'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,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-01-19 22:09:15 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ $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() {
|
2019-12-27 13:04:45 +00:00
|
|
|
$title = $this->event->getTitle();
|
|
|
|
return $title->getNamespace() === NS_USER_TALK && !$title->isSubpage();
|
2016-01-19 22:09:15 +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
|
|
|
}
|
2022-11-01 22:01:23 +00:00
|
|
|
|
|
|
|
class_alias( EchoMentionPresentationModel::class, 'EchoMentionPresentationModel' );
|