2016-03-28 08:26:48 +00:00
|
|
|
<?php
|
2017-06-15 22:56:12 +00:00
|
|
|
|
|
|
|
namespace LoginNotify;
|
|
|
|
|
|
|
|
use EchoEventPresentationModel;
|
|
|
|
use Message;
|
|
|
|
use SpecialPage;
|
|
|
|
|
|
|
|
class PresentationModel extends EchoEventPresentationModel {
|
2016-03-28 08:26:48 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-17 20:26:31 +00:00
|
|
|
* Show an user avatar.
|
2016-03-28 08:26:48 +00:00
|
|
|
*
|
2017-06-16 00:11:58 +00:00
|
|
|
* @return string Name of icon
|
2016-03-28 08:26:48 +00:00
|
|
|
*/
|
|
|
|
public function getIconType() {
|
2017-03-17 20:26:31 +00:00
|
|
|
return 'LoginNotify-user-avatar';
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-27 22:00:48 +00:00
|
|
|
* Link to help page on mediawiki
|
2016-03-28 08:26:48 +00:00
|
|
|
*
|
2017-06-16 00:11:58 +00:00
|
|
|
* @return array URL to link to
|
2016-03-28 08:26:48 +00:00
|
|
|
*/
|
|
|
|
public function getPrimaryLink() {
|
2017-04-27 22:00:48 +00:00
|
|
|
return [
|
2017-04-28 18:41:18 +00:00
|
|
|
'url' => 'https://mediawiki.org/wiki/Help:Login_notifications',
|
|
|
|
'label' => $this->msg( 'loginnotify-primary-link' )->text()
|
2017-04-27 22:00:48 +00:00
|
|
|
];
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 18:41:18 +00:00
|
|
|
/**
|
|
|
|
* Define the email subject string
|
|
|
|
*
|
2017-06-16 01:12:39 +00:00
|
|
|
* @return Message Email subject
|
2017-04-28 18:41:18 +00:00
|
|
|
*/
|
|
|
|
public function getSubjectMessage() {
|
|
|
|
switch ( $this->event->getType() ) {
|
|
|
|
case 'login-fail-known':
|
|
|
|
case 'login-fail-new':
|
|
|
|
$msg = $this->msg( 'notification-loginnotify-login-fail-email-subject' );
|
|
|
|
$msg->params( $this->getUser()->getName() );
|
|
|
|
$msg->params( $this->event->getExtraParam( 'count', 0 ) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$msg = $this->msg( 'notification-loginnotify-login-success-email-subject' );
|
|
|
|
$msg->params( $this->getUser()->getName() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2016-03-28 08:26:48 +00:00
|
|
|
/**
|
2017-04-26 17:59:48 +00:00
|
|
|
* Include the number of attempts in the message if needed
|
2016-03-28 08:26:48 +00:00
|
|
|
*
|
|
|
|
* @return Message
|
|
|
|
*/
|
|
|
|
public function getHeaderMessage() {
|
2017-04-20 18:14:04 +00:00
|
|
|
switch ( $this->event->getType() ) {
|
|
|
|
case 'login-fail-known':
|
2017-04-26 17:59:48 +00:00
|
|
|
$msg = $this->msg( 'notification-known-header-login-fail' );
|
|
|
|
$msg->params( $this->event->getExtraParam( 'count', 0 ) );
|
2017-04-20 18:14:04 +00:00
|
|
|
break;
|
|
|
|
case 'login-fail-new':
|
2017-04-26 17:59:48 +00:00
|
|
|
if ( $this->isBundled() ) {
|
2017-04-20 18:14:04 +00:00
|
|
|
$msg = $this->msg( 'notification-new-bundled-header-login-fail' );
|
|
|
|
$msg->params( $this->event->getExtraParam( 'count', 0 ) );
|
|
|
|
} else {
|
2017-04-26 17:59:48 +00:00
|
|
|
$msg = $this->msg( 'notification-new-unbundled-header-login-fail' );
|
|
|
|
$msg->params( $this->event->getExtraParam( 'count', 0 ) );
|
2017-04-20 18:14:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-04-26 17:59:48 +00:00
|
|
|
default:
|
|
|
|
$msg = $this->msg( 'notification-header-login-success' );
|
2017-04-07 21:48:57 +00:00
|
|
|
}
|
2017-04-20 18:14:04 +00:00
|
|
|
return $msg;
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-17 20:26:31 +00:00
|
|
|
* Get links to be used in the notification
|
|
|
|
*
|
|
|
|
* @return array Link to Special:ChangePassword
|
2016-03-28 08:26:48 +00:00
|
|
|
*/
|
|
|
|
public function getSecondaryLinks() {
|
2017-03-17 20:26:31 +00:00
|
|
|
$changePasswordLink = [
|
|
|
|
'url' => SpecialPage::getTitleFor( 'ChangePassword' )->getFullURL(),
|
|
|
|
'label' => $this->msg( 'changepassword' )->text(),
|
|
|
|
'description' => '',
|
|
|
|
'icon' => 'lock',
|
|
|
|
'prioritized' => true,
|
|
|
|
];
|
|
|
|
|
|
|
|
return [ $changePasswordLink ];
|
2016-03-28 08:26:48 +00:00
|
|
|
}
|
|
|
|
}
|