|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MediaWiki\Extension\Notifications\Notifications; |
| 4 | + |
| 5 | +use MediaWiki\Notification\AgentAware; |
| 6 | +use MediaWiki\Notification\Notification; |
| 7 | +use MediaWiki\User\UserIdentity; |
| 8 | + |
| 9 | +/** |
| 10 | + * MediaWiki Core notification that represents user rights change |
| 11 | + * |
| 12 | + * @since 1.44 |
| 13 | + * @unstable |
| 14 | + */ |
| 15 | +class UserRightsNotification extends Notification implements AgentAware { |
| 16 | + |
| 17 | + private UserIdentity $agent; |
| 18 | + |
| 19 | + /** |
| 20 | + * Create new notification |
| 21 | + * |
| 22 | + * @param UserIdentity $target |
| 23 | + * @param UserIdentity $agent |
| 24 | + * @param string $reason |
| 25 | + */ |
| 26 | + public function __construct( UserIdentity $target, UserIdentity $agent, string $reason ) { |
| 27 | + parent::__construct( 'user-rights', [ |
| 28 | + // user is required in presentation |
| 29 | + 'user' => $target->getId(), |
| 30 | + 'reason' => $reason, |
| 31 | + ] ); |
| 32 | + $this->agent = $agent; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Named constructor to create a Notification to represent expiration change |
| 37 | + * |
| 38 | + * @param UserIdentity $target |
| 39 | + * @param UserIdentity $agent |
| 40 | + * @param string $reason |
| 41 | + * @param string[] $expiryChanged strings corresponding to rights with updated expiry |
| 42 | + * @return UserRightsNotification |
| 43 | + */ |
| 44 | + public static function newForExpiryChanged( |
| 45 | + UserIdentity $target, UserIdentity $agent, string $reason, array $expiryChanged |
| 46 | + ): self { |
| 47 | + $notification = new self( $target, $agent, $reason ); |
| 48 | + $notification->setProperty( 'expiry-changed', $expiryChanged ); |
| 49 | + return $notification; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Named constructor to create a Notification to represent user rights change |
| 54 | + * |
| 55 | + * @param UserIdentity $target |
| 56 | + * @param UserIdentity $agent |
| 57 | + * @param string $reason |
| 58 | + * @param string[] $added strings corresponding to rights added |
| 59 | + * @param string[] $removed strings corresponding to rights added |
| 60 | + * @return UserRightsNotification |
| 61 | + */ |
| 62 | + public static function newForRightsChange( |
| 63 | + UserIdentity $target, UserIdentity $agent, string $reason, array $added, array $removed |
| 64 | + ): self { |
| 65 | + $notification = new self( $target, $agent, $reason ); |
| 66 | + $notification->setProperty( 'add', $added ); |
| 67 | + $notification->setProperty( 'remove', $removed ); |
| 68 | + return $notification; |
| 69 | + } |
| 70 | + |
| 71 | + public function getAgent(): UserIdentity { |
| 72 | + return $this->agent; |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments