Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 54 |
PresentationModel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
110 | |
0.00% |
0 / 54 |
getIconType | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
getPrimaryLink | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
getSubjectMessage | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 14 |
|||
getHeaderMessage | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 24 |
|||
getSecondaryLinks | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 9 |
<?php | |
namespace LoginNotify; | |
use EchoEvent; | |
use EchoEventPresentationModel; | |
use Message; | |
use SpecialPage; | |
class PresentationModel extends EchoEventPresentationModel { | |
/** | |
* Show an user avatar. | |
* | |
* @return string Name of icon | |
*/ | |
public function getIconType() { | |
return 'LoginNotify-user-avatar'; | |
} | |
/** | |
* Link to help page on mediawiki | |
* | |
* @return array URL to link to | |
*/ | |
public function getPrimaryLink() { | |
return [ | |
'url' => 'https://mediawiki.org/wiki/Special:MyLanguage/Help:Login_notifications', | |
'label' => $this->msg( 'loginnotify-primary-link' )->text() | |
]; | |
} | |
/** | |
* Define the email subject string | |
* | |
* @return Message Email subject | |
*/ | |
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; | |
} | |
/** | |
* Include the number of attempts in the message if needed | |
* | |
* @return Message | |
*/ | |
public function getHeaderMessage() { | |
switch ( $this->event->getType() ) { | |
// Known IP? Don't bundle because we issue notifications after every 5 attempts anyway | |
case 'login-fail-known': | |
$msg = $this->msg( 'notification-known-header-login-fail' ); | |
$msg->params( $this->event->getExtraParam( 'count', 0 ) ); | |
break; | |
// New IP? | |
case 'login-fail-new': | |
// If it's a bundle, pass it the bundle count as param | |
if ( $this->isBundled() ) { | |
$msg = $this->msg( 'notification-new-bundled-header-login-fail' ); | |
$totalAttempts = array_reduce( | |
$this->getBundledEvents(), | |
static function ( $sum, EchoEvent $event ) { | |
return $sum + $event->getExtraParam( 'count', 0 ); | |
}, | |
0 | |
); | |
$msg->params( $totalAttempts ); | |
} else { | |
// If the bundle is read or user goes to Special:Notifications, show | |
// one notification per attempt (aligned with how unbundled bundles work) | |
$msg = $this->msg( 'notification-new-unbundled-header-login-fail' ); | |
$msg->params( $this->event->getExtraParam( 'count', 0 ) ); | |
} | |
break; | |
default: | |
$msg = $this->msg( 'notification-header-login-success', $this->getUser()->getName() ); | |
} | |
return $msg; | |
} | |
/** | |
* Get links to be used in the notification | |
* | |
* @return array Link to Special:ChangePassword | |
*/ | |
public function getSecondaryLinks() { | |
$changePasswordLink = [ | |
'url' => SpecialPage::getTitleFor( 'ChangePassword' )->getFullURL(), | |
'label' => $this->msg( 'changepassword' )->text(), | |
'description' => '', | |
'icon' => 'lock', | |
'prioritized' => true, | |
]; | |
return [ $changePasswordLink ]; | |
} | |
} |