Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
EchoNotificationPresentationModel | |
0.00% |
0 / 40 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
getIconType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPrimaryLink | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
12 | |||
getHeaderMessageKey | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderMessage | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace ContentTranslation; |
4 | |
5 | use SpecialPage; |
6 | |
7 | /** |
8 | * Class that returns structured data for the content translation echo events. |
9 | * @see https://www.mediawiki.org/wiki/Notifications/New_formatter_system |
10 | */ |
11 | class EchoNotificationPresentationModel extends \EchoEventPresentationModel { |
12 | |
13 | public function getIconType() { |
14 | return 'cx'; |
15 | } |
16 | |
17 | public function getPrimaryLink() { |
18 | if ( $this->type === 'cx-first-translation' ) { |
19 | $user = $this->getViewingUserForGender(); |
20 | $title = SpecialPage::getTitleFor( 'Contributions', $user ); |
21 | return [ |
22 | 'url' => $title->getCanonicalURL(), |
23 | 'label' => $this->msg( 'cx-contributions-link' ) |
24 | ]; |
25 | } elseif ( $this->type === 'cx-suggestions-available' ) { |
26 | $title = SpecialPage::getTitleFor( 'ContentTranslation', false, 'suggestions' ); |
27 | return [ |
28 | 'url' => $title->getCanonicalURL(), |
29 | 'label' => $this->msg( 'cx' ) |
30 | ]; |
31 | } else { |
32 | $title = SpecialPage::getTitleFor( 'ContentTranslation' ); |
33 | return [ |
34 | 'url' => $title->getCanonicalURL(), |
35 | 'label' => $this->msg( 'cx-your-translations-link' ) |
36 | ]; |
37 | } |
38 | } |
39 | |
40 | /** |
41 | * @return string Message key that will be used in getHeaderMessage |
42 | */ |
43 | protected function getHeaderMessageKey() { |
44 | // The messages already exist and have translations, so in this |
45 | // case we want to map the messages to the existing old messsage |
46 | $map = [ |
47 | 'cx-first-translation' => 'cx-notification-first-translation', |
48 | 'cx-tenth-translation' => 'cx-notification-tenth-translation', |
49 | 'cx-hundredth-translation' => 'cx-notification-hundredth-translation', |
50 | 'cx-suggestions-available' => 'cx-notification-suggestions-available' |
51 | ]; |
52 | return $map[ $this->type ]; |
53 | } |
54 | |
55 | public function getHeaderMessage() { |
56 | $key = $this->getHeaderMessageKey(); |
57 | $msg = $this->msg( $key ); |
58 | if ( $key === 'cx-notification-suggestions-available' ) { |
59 | $truncatedTitle = $this->language->truncateForVisual( |
60 | $this->event->getExtraParam( 'lastTranslationTitle' ), |
61 | self::PAGE_NAME_RECOMMENDED_LENGTH, |
62 | '...', |
63 | false |
64 | ); |
65 | $msg->params( |
66 | $truncatedTitle, |
67 | $this->getViewingUserForGender() |
68 | ); |
69 | } |
70 | return $msg; |
71 | } |
72 | } |