| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Extension\OATHAuth\Notifications; |
| 22 |
|
| 23 |
use MediaWiki\Extension\Notifications\Model\Event; |
| 24 |
use MediaWiki\Extension\OATHAuth\OATHUser; |
| 25 |
use MediaWiki\Registration\ExtensionRegistry; |
| 26 |
use MediaWiki\SpecialPage\SpecialPage; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class Manager { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
private static function isEnabled(): bool { |
| 39 |
return ExtensionRegistry::getInstance()->isLoaded( 'Echo' ); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public static function notifyDisabled( OATHUser $oUser, bool $self ) { |
| 49 |
if ( !self::isEnabled() ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
Event::create( [ |
| 53 |
|
| 54 |
'type' => 'oathauth-disable', |
| 55 |
'title' => SpecialPage::getTitleFor( 'Preferences' ), |
| 56 |
'agent' => $oUser->getUser(), |
| 57 |
'extra' => [ |
| 58 |
'self' => $self, |
| 59 |
'activeDevices' => count( $oUser->getKeys() ), |
| 60 |
] |
| 61 |
] ); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public static function notifyEnabled( OATHUser $oUser ) { |
| 70 |
if ( !self::isEnabled() ) { |
| 71 |
return; |
| 72 |
} |
| 73 |
Event::create( [ |
| 74 |
|
| 75 |
'type' => 'oathauth-enable', |
| 76 |
'title' => SpecialPage::getTitleFor( 'Preferences' ), |
| 77 |
'agent' => $oUser->getUser(), |
| 78 |
'extra' => [ |
| 79 |
'activeDevices' => count( $oUser->getKeys() ), |
| 80 |
], |
| 81 |
] ); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public static function notifyRecoveryTokensRemaining( OATHUser $oUser, int $tokenCount, int $generatedCount ) { |
| 92 |
if ( !self::isEnabled() ) { |
| 93 |
return; |
| 94 |
} |
| 95 |
Event::create( [ |
| 96 |
|
| 97 |
'type' => 'oathauth-recoverycodes-count', |
| 98 |
'agent' => $oUser->getUser(), |
| 99 |
'extra' => [ |
| 100 |
'codeCount' => $tokenCount, |
| 101 |
'generatedCount' => $generatedCount, |
| 102 |
], |
| 103 |
] ); |
| 104 |
} |
| 105 |
} |