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 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | */ |
20 | |
21 | namespace MediaWiki\Extension\OATHAuth\Notifications; |
22 | |
23 | use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; |
24 | use MediaWiki\SpecialPage\SpecialPage; |
25 | use MediaWiki\Title\Title; |
26 | |
27 | class DisablePresentationModel extends EchoEventPresentationModel { |
28 | |
29 | /** |
30 | * @inheritDoc |
31 | */ |
32 | public function getIconType() { |
33 | return 'site'; |
34 | } |
35 | |
36 | /** @inheritDoc */ |
37 | protected function getHeaderMessageKey() { |
38 | return $this->event->getExtraParam( 'activeDevices', 0 ) === 0 |
39 | ? 'notification-header-oathauth-disable' |
40 | : 'notification-header-oathauth-remove-device'; |
41 | } |
42 | |
43 | /** |
44 | * @inheritDoc |
45 | */ |
46 | public function getPrimaryLink() { |
47 | return [ |
48 | 'url' => SpecialPage::getTitleFor( 'OATHManage' )->getLocalURL(), |
49 | 'label' => $this->msg( 'oathauth-notifications-disable-primary' )->text() |
50 | ]; |
51 | } |
52 | |
53 | /** |
54 | * @inheritDoc |
55 | */ |
56 | public function getSecondaryLinks() { |
57 | $link = $this->msg( 'oathauth-notifications-disable-helplink' )->inContentLanguage(); |
58 | $title = Title::newFromText( $link->plain() ); |
59 | if ( !$title ) { |
60 | // Invalid title, skip |
61 | return []; |
62 | } |
63 | return [ [ |
64 | 'url' => $title->getLocalURL(), |
65 | 'label' => $this->msg( 'oathauth-notifications-disable-help' )->text(), |
66 | 'icon' => 'help', |
67 | ] ]; |
68 | } |
69 | |
70 | /** |
71 | * @inheritDoc |
72 | */ |
73 | public function getBodyMessage() { |
74 | $helpMessageKey = $this->event->getExtraParam( 'self', true ) |
75 | ? 'notification-body-oathauth-disable' |
76 | : 'notification-body-oathauth-disable-other'; |
77 | $message = $this->getMessageWithAgent( $helpMessageKey ); |
78 | |
79 | if ( $this->event->getExtraParam( 'activeDevices', 0 ) >= 1 ) { |
80 | $remainingMessage = $this->getMessageWithAgent( 'notification-body-oathauth-disable-remaining' ); |
81 | $remainingMessage->params( $this->event->getExtraParam( 'activeDevices', 0 ) ); |
82 | |
83 | $message = $this->msg( 'rawmessage' )->rawParams( |
84 | $message->escaped() |
85 | . $this->msg( 'word-separator' )->escaped() |
86 | . $remainingMessage->escaped() |
87 | ); |
88 | } |
89 | |
90 | return $message; |
91 | } |
92 | } |