2016-06-21 14:42:56 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
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;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\User;
|
2022-11-01 22:01:23 +00:00
|
|
|
|
2016-06-21 14:42:56 +00:00
|
|
|
/**
|
2016-07-21 13:00:54 +00:00
|
|
|
* Presenter for 'mention-failure' and 'mention-success' notifications
|
2016-06-21 14:42:56 +00:00
|
|
|
*
|
|
|
|
* @author Christoph Fischer <christoph.fischer@wikimedia.de>
|
|
|
|
*
|
2017-06-21 00:31:55 +00:00
|
|
|
* @license MIT
|
2016-06-21 14:42:56 +00:00
|
|
|
*/
|
2016-07-21 13:00:54 +00:00
|
|
|
class EchoMentionStatusPresentationModel 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-06-21 14:42:56 +00:00
|
|
|
|
|
|
|
public function getIconType() {
|
2016-07-29 10:15:34 +00:00
|
|
|
if ( $this->isMixedBundle() ) {
|
|
|
|
return 'mention-status-bundle';
|
|
|
|
}
|
2016-07-21 13:00:54 +00:00
|
|
|
if ( $this->isMentionSuccess() ) {
|
|
|
|
return 'mention-success';
|
|
|
|
}
|
2016-06-21 14:42:56 +00:00
|
|
|
return 'mention-failure';
|
|
|
|
}
|
|
|
|
|
2016-09-06 21:44:51 +00:00
|
|
|
public function canRender() {
|
|
|
|
return (bool)$this->event->getTitle();
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:42:56 +00:00
|
|
|
public function getHeaderMessage() {
|
|
|
|
if ( $this->isTooManyMentionsFailure() ) {
|
|
|
|
$msg = $this->getMessageWithAgent( 'notification-header-mention-failure-too-many' );
|
|
|
|
$msg->numParams( $this->getMaxMentions() );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->isBundled() ) {
|
2016-07-29 10:15:34 +00:00
|
|
|
if ( $this->isMixedBundle() ) {
|
|
|
|
$successCount = $this->getBundleSuccessCount();
|
|
|
|
|
|
|
|
$msg = $this->getMessageWithAgent( 'notification-header-mention-status-bundle' );
|
|
|
|
$msg->numParams( $this->getBundleCount() );
|
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle() ) );
|
|
|
|
$msg->numParams( $this->getBundleCount() - $successCount );
|
|
|
|
$msg->numParams( $successCount );
|
|
|
|
return $msg;
|
|
|
|
}
|
2016-07-21 13:00:54 +00:00
|
|
|
if ( $this->isMentionSuccess() ) {
|
|
|
|
$msgKey = 'notification-header-mention-success-bundle';
|
|
|
|
} else {
|
|
|
|
$msgKey = 'notification-header-mention-failure-bundle';
|
|
|
|
}
|
|
|
|
$msg = $this->getMessageWithAgent( $msgKey );
|
2016-06-21 14:42:56 +00:00
|
|
|
$msg->numParams( $this->getBundleCount() );
|
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle() ) );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:00:54 +00:00
|
|
|
if ( $this->isMentionSuccess() ) {
|
|
|
|
$msgKey = 'notification-header-mention-success';
|
|
|
|
} else {
|
|
|
|
// Messages that can be used here:
|
|
|
|
// * notification-header-mention-failure-user-unknown
|
|
|
|
// * notification-header-mention-failure-user-anonymous
|
|
|
|
$msgKey = 'notification-header-mention-failure-' . $this->getFailureType();
|
|
|
|
}
|
|
|
|
$msg = $this->getMessageWithAgent( $msgKey );
|
2016-06-21 14:42:56 +00:00
|
|
|
$msg->params( $this->getSubjectName() );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCompactHeaderMessage() {
|
2016-07-21 13:00:54 +00:00
|
|
|
if ( $this->isMentionSuccess() ) {
|
|
|
|
$msg = $this->getMessageWithAgent( 'notification-compact-header-mention-success' );
|
|
|
|
} else {
|
|
|
|
// Messages that can be used here:
|
|
|
|
// * notification-compact-header-mention-failure-user-unknown
|
|
|
|
// * notification-compact-header-mention-failure-user-anonymous
|
|
|
|
$msg = $this->msg( 'notification-compact-header-mention-failure-' . $this->getFailureType() );
|
|
|
|
}
|
2016-06-21 14:42:56 +00:00
|
|
|
$msg->params( $this->getSubjectName() );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrimaryLink() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2016-06-21 14:42:56 +00:00
|
|
|
// Need FullURL so the section is included
|
2019-04-05 20:50:03 +00:00
|
|
|
'url' => $this->section->getTitleWithSection()->getFullURL(),
|
2016-06-21 14:42:56 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-view-mention-failure' )
|
|
|
|
->numParams( $this->getBundleCount() )
|
|
|
|
->text()
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-06-21 14:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
|
|
|
if ( $this->isBundled() ) {
|
2016-09-09 19:59:09 +00:00
|
|
|
return [];
|
2016-06-21 14:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$talkPageLink = $this->getPageLink(
|
2019-04-05 20:50:03 +00:00
|
|
|
$this->section->getTitleWithSection(),
|
2016-06-21 14:42:56 +00:00
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ $talkPageLink ];
|
2016-06-21 14:42:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
public function isMentionSuccessEvent( Event $event ) {
|
2016-07-29 10:15:34 +00:00
|
|
|
return $event->getType() === 'mention-success';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isMentionSuccess() {
|
|
|
|
return $this->isMentionSuccessEvent( $this->event );
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:42:56 +00:00
|
|
|
private function getSubjectName() {
|
|
|
|
return $this->event->getExtraParam( 'subject-name', '' );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getFailureType() {
|
|
|
|
return $this->event->getExtraParam( 'failure-type', 'user-unknown' );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isTooManyMentionsFailure() {
|
2017-04-20 16:21:02 +00:00
|
|
|
return $this->getFailureType() === 'too-many' ||
|
|
|
|
$this->getType() === 'mention-failure-too-many';
|
2016-06-21 14:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getMaxMentions() {
|
|
|
|
global $wgEchoMaxMentionsCount;
|
|
|
|
return $this->event->getExtraParam( 'max-mentions', $wgEchoMaxMentionsCount );
|
|
|
|
}
|
2016-07-29 10:15:34 +00:00
|
|
|
|
|
|
|
private function getBundleSuccessCount() {
|
2017-05-03 08:35:42 +00:00
|
|
|
$events = array_merge( $this->getBundledEvents(), [ $this->event ] );
|
|
|
|
return count( array_filter( $events, [ $this, 'isMentionSuccessEvent' ] ) );
|
2016-07-29 10:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function isMixedBundle() {
|
|
|
|
$successCount = $this->getBundleSuccessCount();
|
|
|
|
$failCount = $this->getBundleCount() - $successCount;
|
|
|
|
return $successCount > 0 && $failCount > 0;
|
|
|
|
}
|
2016-06-21 14:42:56 +00:00
|
|
|
}
|
2022-11-01 22:01:23 +00:00
|
|
|
|
|
|
|
class_alias( EchoMentionStatusPresentationModel::class, 'EchoMentionStatusPresentationModel' );
|