2016-06-21 14:42:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
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>
|
|
|
|
*
|
|
|
|
* @license GNU GPL v2+
|
|
|
|
*/
|
2016-07-21 13:00:54 +00:00
|
|
|
class EchoMentionStatusPresentationModel extends EchoEventPresentationModel {
|
2016-06-21 14:42:56 +00:00
|
|
|
use EchoPresentationModelSectionTrait;
|
|
|
|
|
|
|
|
public function getIconType() {
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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() {
|
|
|
|
return array(
|
|
|
|
// Need FullURL so the section is included
|
|
|
|
'url' => $this->getTitleWithSection()->getFullURL(),
|
|
|
|
'label' => $this->msg( 'notification-link-text-view-mention-failure' )
|
|
|
|
->numParams( $this->getBundleCount() )
|
|
|
|
->text()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
|
|
|
if ( $this->isBundled() ) {
|
2016-08-03 16:01:48 +00:00
|
|
|
return false;
|
2016-06-21 14:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$talkPageLink = $this->getPageLink(
|
|
|
|
$this->getTitleWithSection(),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
return array( $talkPageLink );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSubjectName() {
|
|
|
|
return $this->event->getExtraParam( 'subject-name', '' );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getFailureType() {
|
|
|
|
return $this->event->getExtraParam( 'failure-type', 'user-unknown' );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isTooManyMentionsFailure() {
|
2016-07-27 15:04:49 +00:00
|
|
|
return $this->getType() === 'mention-failure-too-many';
|
2016-06-21 14:42:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:00:54 +00:00
|
|
|
private function isMentionSuccess() {
|
|
|
|
return $this->getType() === 'mention-success';
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:42:56 +00:00
|
|
|
private function getMaxMentions() {
|
|
|
|
global $wgEchoMaxMentionsCount;
|
|
|
|
return $this->event->getExtraParam( 'max-mentions', $wgEchoMaxMentionsCount );
|
|
|
|
}
|
|
|
|
}
|