Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Notification | |
0.00% |
0 / 28 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
| firstTranslation | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| tenthTranslation | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| hundredthTranslation | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| suggestionsAvailable | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| draftNotification | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace ContentTranslation; |
| 4 | |
| 5 | use ContentTranslation\Exception\InvalidNotificationTitleException; |
| 6 | use MediaWiki\MediaWikiServices; |
| 7 | use MediaWiki\Notification\Notification as CoreNotification; |
| 8 | use MediaWiki\Notification\RecipientSet; |
| 9 | use MediaWiki\Notification\Types\TitleNotification; |
| 10 | use MediaWiki\Title\Title; |
| 11 | use MediaWiki\User\User; |
| 12 | use MediaWiki\User\UserIdentity; |
| 13 | |
| 14 | class Notification { |
| 15 | |
| 16 | /** |
| 17 | * Notify the user on the first published translation. |
| 18 | */ |
| 19 | public static function firstTranslation( User $recipient ) { |
| 20 | MediaWikiServices::getInstance()->getNotificationService()->notify( |
| 21 | new CoreNotification( 'cx-first-translation' ), |
| 22 | new RecipientSet( $recipient ) |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Notify the user on the 10th published translation. |
| 28 | */ |
| 29 | public static function tenthTranslation( User $recipient ) { |
| 30 | MediaWikiServices::getInstance()->getNotificationService()->notify( |
| 31 | new CoreNotification( 'cx-tenth-translation' ), |
| 32 | new RecipientSet( $recipient ) |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Notify the user on the 100th published translation. |
| 38 | */ |
| 39 | public static function hundredthTranslation( User $recipient ) { |
| 40 | MediaWikiServices::getInstance()->getNotificationService()->notify( |
| 41 | new CoreNotification( 'cx-hundredth-translation' ), |
| 42 | new RecipientSet( $recipient ) |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Notify the user about the availability of personalized suggestions. |
| 48 | * @param User $recipient |
| 49 | * @param string $lastTranslationTitle |
| 50 | */ |
| 51 | public static function suggestionsAvailable( User $recipient, $lastTranslationTitle ) { |
| 52 | MediaWikiServices::getInstance()->getNotificationService()->notify( |
| 53 | new CoreNotification( 'cx-suggestions-available', [ |
| 54 | 'lastTranslationTitle' => $lastTranslationTitle |
| 55 | ] ), |
| 56 | new RecipientSet( $recipient ) |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Notify user about the status of his/her old unpublished draft, |
| 62 | * depending on notification type: |
| 63 | * - That their draft is getting old and may be deleted in the future |
| 64 | * - That their draft was too old and thus deleted |
| 65 | * |
| 66 | * @param string $type 'cx-deleted-draft' or 'cx-continue-translation' |
| 67 | * @param UserIdentity $recipient The user receiving this notification. |
| 68 | * @param string $title Title of unpublished draft page which is deleted. |
| 69 | * @param string $sourceLanguage |
| 70 | * @param string $targetLanguage |
| 71 | * @throws InvalidNotificationTitleException |
| 72 | */ |
| 73 | public static function draftNotification( |
| 74 | string $type, UserIdentity $recipient, $title, $sourceLanguage, $targetLanguage |
| 75 | ) { |
| 76 | $titleObj = Title::newFromText( $title ); |
| 77 | if ( !$titleObj ) { |
| 78 | // PurgeUnpublishedDrafts only catches InvalidNotificationTitleException |
| 79 | // See also https://phabricator.wikimedia.org/T264855 |
| 80 | throw new InvalidNotificationTitleException( $title ); |
| 81 | } |
| 82 | |
| 83 | MediaWikiServices::getInstance()->getNotificationService()->notify( |
| 84 | new TitleNotification( $type, $titleObj, [ |
| 85 | 'source' => $sourceLanguage, |
| 86 | 'target' => $targetLanguage |
| 87 | ] ), |
| 88 | new RecipientSet( $recipient ) |
| 89 | ); |
| 90 | } |
| 91 | } |