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