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