Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| DisablePresentationModel | |
0.00% |
0 / 30 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| getIconType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHeaderMessageKey | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getPrimaryLink | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getSecondaryLinks | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| getBodyMessage | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright (C) 2022 Kunal Mehta <legoktm@debian.org> |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | namespace MediaWiki\Extension\OATHAuth\Notifications; |
| 9 | |
| 10 | use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; |
| 11 | use MediaWiki\SpecialPage\SpecialPage; |
| 12 | use MediaWiki\Title\Title; |
| 13 | |
| 14 | class DisablePresentationModel extends EchoEventPresentationModel { |
| 15 | |
| 16 | /** @inheritDoc */ |
| 17 | public function getIconType() { |
| 18 | return 'site'; |
| 19 | } |
| 20 | |
| 21 | /** @inheritDoc */ |
| 22 | protected function getHeaderMessageKey() { |
| 23 | return $this->event->getExtraParam( 'activeDevices', 0 ) === 0 |
| 24 | ? 'notification-header-oathauth-disable' |
| 25 | : 'notification-header-oathauth-remove-device'; |
| 26 | } |
| 27 | |
| 28 | /** @inheritDoc */ |
| 29 | public function getPrimaryLink() { |
| 30 | return [ |
| 31 | 'url' => SpecialPage::getTitleFor( 'OATHManage' )->getLocalURL(), |
| 32 | 'label' => $this->msg( 'oathauth-notifications-disable-primary' )->text() |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | /** @inheritDoc */ |
| 37 | public function getSecondaryLinks() { |
| 38 | $link = $this->msg( 'oathauth-notifications-disable-helplink' )->inContentLanguage(); |
| 39 | $title = Title::newFromText( $link->plain() ); |
| 40 | if ( !$title ) { |
| 41 | // Invalid title, skip |
| 42 | return []; |
| 43 | } |
| 44 | return [ [ |
| 45 | 'url' => $title->getLocalURL(), |
| 46 | 'label' => $this->msg( 'oathauth-notifications-disable-help' )->text(), |
| 47 | 'icon' => 'help', |
| 48 | ] ]; |
| 49 | } |
| 50 | |
| 51 | /** @inheritDoc */ |
| 52 | public function getBodyMessage() { |
| 53 | $helpMessageKey = $this->event->getExtraParam( 'self', true ) |
| 54 | ? 'notification-body-oathauth-disable' |
| 55 | : 'notification-body-oathauth-disable-other'; |
| 56 | $message = $this->getMessageWithAgent( $helpMessageKey ); |
| 57 | |
| 58 | if ( $this->event->getExtraParam( 'activeDevices', 0 ) >= 1 ) { |
| 59 | $remainingMessage = $this->getMessageWithAgent( 'notification-body-oathauth-disable-remaining' ); |
| 60 | $remainingMessage->params( $this->event->getExtraParam( 'activeDevices', 0 ) ); |
| 61 | |
| 62 | $message = $this->msg( 'rawmessage' )->rawParams( |
| 63 | $message->escaped() |
| 64 | . $this->msg( 'word-separator' )->escaped() |
| 65 | . $remainingMessage->escaped() |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | return $message; |
| 70 | } |
| 71 | } |