Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
DraftNotificationPresentationModel | |
0.00% |
0 / 38 |
|
0.00% |
0 / 6 |
182 | |
0.00% |
0 / 1 |
getIconType | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
getPrimaryLink | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
getHeaderMessage | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
getCompactHeaderMessage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getSecondaryLinks | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getYourTranslationsLink | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace ContentTranslation; |
4 | |
5 | use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; |
6 | use MediaWiki\Language\RawMessage; |
7 | use MediaWiki\SpecialPage\SpecialPage; |
8 | |
9 | /** |
10 | * Class that returns structured data for the Content Translation echo events |
11 | * when translation drafts are deleted from cx_corpora table or when user is notified |
12 | * that their drafts might be deleted. |
13 | * |
14 | * @copyright See AUTHORS.txt |
15 | * @license GPL-2.0-or-later |
16 | * |
17 | * @see https://www.mediawiki.org/wiki/Notifications/New_formatter_system |
18 | */ |
19 | class DraftNotificationPresentationModel extends EchoEventPresentationModel { |
20 | /** @inheritDoc */ |
21 | public function getIconType() { |
22 | if ( $this->getType() === 'cx-deleted-draft' ) { |
23 | return 'outdated'; |
24 | } elseif ( $this->getType() === 'cx-continue-translation' ) { |
25 | return 'cx-blue'; |
26 | } |
27 | |
28 | return 'cx'; |
29 | } |
30 | |
31 | /** @inheritDoc */ |
32 | public function getPrimaryLink() { |
33 | if ( $this->isBundled() ) { |
34 | return [ |
35 | 'url' => SpecialPage::getTitleFor( 'ContentTranslation' )->getLocalURL(), |
36 | 'label' => '', |
37 | ]; |
38 | } |
39 | |
40 | return [ |
41 | 'url' => SpecialPage::getTitleFor( 'ContentTranslation' )->getLocalURL( [ |
42 | 'from' => $this->event->getExtraParam( 'source' ), |
43 | 'to' => $this->event->getExtraParam( 'target' ), |
44 | 'page' => $this->event->getTitle()->getText() |
45 | ] ), |
46 | 'label' => '', |
47 | ]; |
48 | } |
49 | |
50 | /** @inheritDoc */ |
51 | public function getHeaderMessage() { |
52 | if ( $this->getType() === 'cx-deleted-draft' ) { |
53 | $msg = 'cx-notification-deleted-draft'; |
54 | } elseif ( $this->getType() === 'cx-continue-translation' ) { |
55 | $msg = 'cx-notification-continue-translation'; |
56 | } else { |
57 | return parent::getHeaderMessage(); |
58 | } |
59 | |
60 | if ( $this->isBundled() ) { |
61 | return $this->msg( $msg . '-bundle' )->numParams( $this->getBundleCount() ); |
62 | } |
63 | |
64 | return $this->msg( $msg, wfEscapeWikiText( $this->event->getTitle()->getText() ) ); |
65 | } |
66 | |
67 | /** @inheritDoc */ |
68 | public function getCompactHeaderMessage() { |
69 | $msg = new RawMessage( '$1' ); |
70 | $msg->plaintextParams( $this->event->getTitle()->getText() ); |
71 | return $msg; |
72 | } |
73 | |
74 | /** @inheritDoc */ |
75 | public function getSecondaryLinks() { |
76 | if ( $this->isBundled() ) { |
77 | return []; |
78 | } |
79 | |
80 | return [ $this->getYourTranslationsLink() ]; |
81 | } |
82 | |
83 | private function getYourTranslationsLink(): array { |
84 | return [ |
85 | 'url' => SpecialPage::getTitleFor( 'ContentTranslation' )->getLocalURL(), |
86 | 'icon' => 'article', |
87 | 'label' => $this->msg( 'cx-your-translations-link' ), |
88 | 'prioritized' => true |
89 | ]; |
90 | } |
91 | } |