Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| RecoveryCodesGeneratedForUserPresentationModel | |
0.00% |
0 / 39 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
| getIconType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPrimaryLink | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getSecondaryLinks | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 | |||
| getHeaderMessage | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getBodyMessage | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\OATHAuth\Notifications; |
| 4 | |
| 5 | use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; |
| 6 | use MediaWiki\MediaWikiServices; |
| 7 | use MediaWiki\SpecialPage\SpecialPage; |
| 8 | use MediaWiki\Title\Title; |
| 9 | |
| 10 | class RecoveryCodesGeneratedForUserPresentationModel extends EchoEventPresentationModel { |
| 11 | |
| 12 | /** @inheritDoc */ |
| 13 | public function getIconType() { |
| 14 | return 'site'; |
| 15 | } |
| 16 | |
| 17 | /** @inheritDoc */ |
| 18 | public function getPrimaryLink() { |
| 19 | return [ |
| 20 | 'url' => SpecialPage::getTitleFor( 'OATHManage' )->getLocalURL(), |
| 21 | 'label' => $this->msg( 'oathauth-notifications-recoverycodes-generated-for-user-primary' )->text() |
| 22 | ]; |
| 23 | } |
| 24 | |
| 25 | /** @inheritDoc */ |
| 26 | public function getSecondaryLinks() { |
| 27 | $links = []; |
| 28 | |
| 29 | $helpLink = $this->msg( 'oathauth-notifications-recoverycodes-generated-for-user-helplink' ) |
| 30 | ->inContentLanguage(); |
| 31 | $helpTitle = Title::newFromText( $helpLink->plain() ); |
| 32 | if ( $helpTitle ) { |
| 33 | $links[] = [ |
| 34 | 'url' => $helpTitle->getLocalURL(), |
| 35 | 'label' => $this->msg( 'oathauth-notifications-recoverycodes-generated-for-user-help' )->text(), |
| 36 | 'icon' => 'help', |
| 37 | ]; |
| 38 | } |
| 39 | |
| 40 | $contactUrl = $this->msg( 'oathauth-notifications-recoverycodes-generated-for-user-contacturl' ) |
| 41 | ->inContentLanguage()->plain(); |
| 42 | if ( $contactUrl ) { |
| 43 | // Ensure that the URL is valid and uses supported scheme (to guard from e.g. javascript:) |
| 44 | $parsedUrl = MediaWikiServices::getInstance()->getUrlUtils()->parse( $contactUrl ); |
| 45 | if ( $parsedUrl !== null ) { |
| 46 | $links[] = [ |
| 47 | 'url' => $contactUrl, |
| 48 | 'label' => $this->msg( 'oathauth-notifications-recoverycodes-generated-for-user-contact' )->text(), |
| 49 | 'icon' => 'message', |
| 50 | ]; |
| 51 | } |
| 52 | } |
| 53 | return $links; |
| 54 | } |
| 55 | |
| 56 | /** @inheritDoc */ |
| 57 | public function getHeaderMessage() { |
| 58 | $msg = $this->msg( $this->getHeaderMessageKey() ); |
| 59 | // Leave 'agent' params unused, just in case we use them in future |
| 60 | $msg->params( '', '' ); |
| 61 | $msg->params( $this->event->getExtraParam( 'codeCount', 0 ) ); |
| 62 | return $msg; |
| 63 | } |
| 64 | |
| 65 | /** @inheritDoc */ |
| 66 | public function getBodyMessage() { |
| 67 | $msg = $this->msg( 'notification-body-oathauth-recoverycodes-generated-for-user' ); |
| 68 | $msg->params( $this->event->getExtraParam( 'codeCount', 0 ) ); |
| 69 | $msg->params( |
| 70 | $this->event->getExtraParam( |
| 71 | 'generatedCount', |
| 72 | MediaWikiServices::getInstance()->getMainConfig()->get( 'OATHRecoveryCodesCount' ) |
| 73 | ) |
| 74 | ); |
| 75 | return $msg; |
| 76 | } |
| 77 | |
| 78 | } |