Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| RecentChangeNotificationHandler | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| checkNotificationRequirements | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| notify | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\RecentChanges; |
| 4 | |
| 5 | use MediaWiki\Notification\Notification; |
| 6 | use MediaWiki\Notification\NotificationHandler; |
| 7 | use MediaWiki\Notification\RecipientSet; |
| 8 | use MediaWiki\Title\TitleFactory; |
| 9 | use MediaWiki\User\User; |
| 10 | use MediaWiki\User\UserFactory; |
| 11 | |
| 12 | /** |
| 13 | * Accept notification events and notify users about them. |
| 14 | * |
| 15 | * @internal |
| 16 | */ |
| 17 | class RecentChangeNotificationHandler implements NotificationHandler { |
| 18 | |
| 19 | private UserFactory $userFactory; |
| 20 | private TitleFactory $titleFactory; |
| 21 | |
| 22 | public function __construct( UserFactory $userFactory, TitleFactory $titleFactory ) { |
| 23 | $this->userFactory = $userFactory; |
| 24 | $this->titleFactory = $titleFactory; |
| 25 | } |
| 26 | |
| 27 | public function checkNotificationRequirements( Notification $notification, User $user ): bool { |
| 28 | return $user->isEmailConfirmed(); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Notify users about an event occurring. |
| 33 | */ |
| 34 | public function notify( Notification $notification, RecipientSet $recipients ): void { |
| 35 | if ( !$notification instanceof RecentChangeNotification ) { |
| 36 | return; |
| 37 | } |
| 38 | $sourceMap = [ |
| 39 | RecentChangeNotification::ADMIN_NOTIFICATION => RecentChangeMailComposer::ALL_CHANGES, |
| 40 | RecentChangeNotification::TALK_NOTIFICATION => RecentChangeMailComposer::USER_TALK, |
| 41 | RecentChangeNotification::WATCHLIST_NOTIFICATION => RecentChangeMailComposer::WATCHLIST, |
| 42 | ]; |
| 43 | $source = $sourceMap[ $notification->getSource() ] ?? RecentChangeMailComposer::ALL_CHANGES; |
| 44 | |
| 45 | $composer = new RecentChangeMailComposer( |
| 46 | $this->userFactory->newFromUserIdentity( $notification->getAgent() ), |
| 47 | $this->titleFactory->newFromPageIdentity( $notification->getTitle() ), |
| 48 | $notification->getRecentChange(), |
| 49 | $notification->getPageStatus(), |
| 50 | ); |
| 51 | foreach ( $recipients as $recipient ) { |
| 52 | $user = $this->userFactory->newFromUserIdentity( $recipient ); |
| 53 | if ( $this->checkNotificationRequirements( $notification, $user ) ) { |
| 54 | $composer->compose( $user, $source ); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |