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