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