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