2015-11-17 13:37:39 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
|
|
|
use Language;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
2021-02-10 20:33:05 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\User;
|
2021-02-10 20:33:05 +00:00
|
|
|
|
2015-11-17 13:37:39 +00:00
|
|
|
class EchoEditUserTalkPresentationModel 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 );
|
|
|
|
}
|
2016-04-22 01:31:12 +00:00
|
|
|
|
2015-11-17 13:37:39 +00:00
|
|
|
public function canRender() {
|
|
|
|
return (bool)$this->event->getTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIconType() {
|
2016-01-13 04:24:11 +00:00
|
|
|
return 'edit-user-talk';
|
2015-11-17 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrimaryLink() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2016-04-22 01:31:12 +00:00
|
|
|
// Need FullURL so the section is included
|
2019-04-05 20:50:03 +00:00
|
|
|
'url' => $this->section->getTitleWithSection()->getFullURL(),
|
2015-11-17 13:37:39 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-view-message' )->text()
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-11-17 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$diffLink = [
|
2015-11-17 13:37:39 +00:00
|
|
|
'url' => $this->getDiffLinkUrl(),
|
2016-02-23 16:55:07 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(),
|
2015-12-16 16:52:02 +00:00
|
|
|
'description' => '',
|
2016-01-15 06:34:04 +00:00
|
|
|
'icon' => 'changes',
|
2015-11-17 13:37:39 +00:00
|
|
|
'prioritized' => true
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-01-14 19:33:21 +00:00
|
|
|
|
|
|
|
if ( $this->isBundled() ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ $diffLink ];
|
2016-01-14 19:33:21 +00:00
|
|
|
} else {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ $this->getAgentLink(), $diffLink ];
|
2016-01-14 19:33:21 +00:00
|
|
|
}
|
2015-11-17 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeaderMessage() {
|
2016-01-14 19:33:21 +00:00
|
|
|
if ( $this->isBundled() ) {
|
2019-04-06 00:33:28 +00:00
|
|
|
$msg = $this->msg( 'notification-bundle-header-edit-user-talk-v2' );
|
2016-03-09 04:50:31 +00:00
|
|
|
$count = $this->getNotificationCountForOutput();
|
|
|
|
|
|
|
|
// Repeat is B/C until unused parameter is removed from translations
|
|
|
|
$msg->numParams( $count, $count );
|
2016-01-14 19:33:21 +00:00
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
2015-11-17 13:37:39 +00:00
|
|
|
return $msg;
|
2019-04-05 20:50:03 +00:00
|
|
|
} elseif ( $this->section->exists() ) {
|
2019-04-06 00:33:28 +00:00
|
|
|
$msg = $this->getMessageWithAgent( 'notification-header-edit-user-talk-with-section' );
|
2015-11-17 13:37:39 +00:00
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
2019-04-05 20:50:03 +00:00
|
|
|
$msg->plaintextParams( $this->section->getTruncatedSectionTitle() );
|
2015-11-17 13:37:39 +00:00
|
|
|
return $msg;
|
|
|
|
} else {
|
|
|
|
$msg = parent::getHeaderMessage();
|
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-20 09:26:24 +00:00
|
|
|
public function getCompactHeaderMessage() {
|
2019-04-05 20:50:03 +00:00
|
|
|
$hasSection = $this->section->exists();
|
2017-10-20 09:26:24 +00:00
|
|
|
$key = $hasSection
|
2019-04-06 00:33:28 +00:00
|
|
|
? 'notification-compact-header-edit-user-talk-with-section'
|
|
|
|
: 'notification-compact-header-edit-user-talk';
|
2017-10-20 09:26:24 +00:00
|
|
|
$msg = $this->getMessageWithAgent( $key );
|
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
|
|
if ( $hasSection ) {
|
2019-04-05 20:50:03 +00:00
|
|
|
$msg->params( $this->section->getTruncatedSectionTitle() );
|
2017-10-20 09:26:24 +00:00
|
|
|
}
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2015-11-17 13:37:39 +00:00
|
|
|
public function getBodyMessage() {
|
2016-05-13 23:37:34 +00:00
|
|
|
$sectionText = $this->event->getExtraParam( 'section-text' );
|
2019-05-21 15:31:12 +00:00
|
|
|
if ( !$this->isBundled() && $this->section->exists() && is_string( $sectionText ) ) {
|
2015-11-17 13:37:39 +00:00
|
|
|
$msg = $this->msg( 'notification-body-edit-user-talk-with-section' );
|
2019-05-21 15:31:12 +00:00
|
|
|
// section-text is safe to use here, because section->exists() returns false if the revision is deleted
|
2016-05-13 23:37:34 +00:00
|
|
|
$msg->plaintextParams( $sectionText );
|
2015-11-17 13:37:39 +00:00
|
|
|
return $msg;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getDiffLinkUrl() {
|
|
|
|
$revId = $this->event->getExtraParam( 'revid' );
|
|
|
|
$oldId = $this->isBundled() ? $this->getRevBeforeFirstNotification() : 'prev';
|
2016-12-05 18:51:07 +00:00
|
|
|
$query = [
|
2015-11-17 13:37:39 +00:00
|
|
|
'oldid' => $oldId,
|
|
|
|
'diff' => $revId,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-11-17 13:37:39 +00:00
|
|
|
return $this->event->getTitle()->getFullURL( $query );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getRevBeforeFirstNotification() {
|
2016-01-14 19:58:21 +00:00
|
|
|
$events = $this->getBundledEvents();
|
|
|
|
$firstNotificationRevId = end( $events )->getExtraParam( 'revid' );
|
2021-02-10 20:33:05 +00:00
|
|
|
$revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
|
|
|
|
$revisionRecord = $revisionLookup->getRevisionById( $firstNotificationRevId );
|
|
|
|
$previousRevision = $revisionRecord ? $revisionLookup->getPreviousRevision( $revisionRecord ) : null;
|
2022-11-01 21:39:23 +00:00
|
|
|
return $previousRevision ? $previousRevision->getId() : 0;
|
2015-11-17 13:37:39 +00:00
|
|
|
}
|
2016-05-05 13:05:03 +00:00
|
|
|
|
|
|
|
protected function getSubjectMessageKey() {
|
|
|
|
return 'notification-edit-talk-page-email-subject2';
|
|
|
|
}
|
2015-11-17 13:37:39 +00:00
|
|
|
}
|
2022-11-01 22:01:23 +00:00
|
|
|
|
|
|
|
class_alias( EchoEditUserTalkPresentationModel::class, 'EchoEditUserTalkPresentationModel' );
|