Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
DraftNotificationPresentationModel
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 6
182
0.00% covered (danger)
0.00%
0 / 1
 getIconType
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getPrimaryLink
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
 getHeaderMessage
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
 getCompactHeaderMessage
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getSecondaryLinks
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getYourTranslationsLink
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace ContentTranslation;
4
5use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel;
6use MediaWiki\Language\RawMessage;
7use 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 */
19class DraftNotificationPresentationModel extends EchoEventPresentationModel {
20    public function getIconType() {
21        if ( $this->getType() === 'cx-deleted-draft' ) {
22            return 'outdated';
23        } elseif ( $this->getType() === 'cx-continue-translation' ) {
24            return 'cx-blue';
25        }
26
27        return 'cx';
28    }
29
30    public function getPrimaryLink() {
31        if ( $this->isBundled() ) {
32            return [
33                'url' => SpecialPage::getTitleFor( 'ContentTranslation' )->getLocalURL(),
34                'label' => '',
35            ];
36        }
37
38        return [
39            'url' => SpecialPage::getTitleFor( 'ContentTranslation' )->getLocalURL( [
40                'from' => $this->event->getExtraParam( 'source' ),
41                'to' => $this->event->getExtraParam( 'target' ),
42                'page' => $this->event->getTitle()->getText()
43            ] ),
44            'label' => '',
45        ];
46    }
47
48    public function getHeaderMessage() {
49        if ( $this->getType() === 'cx-deleted-draft' ) {
50            $msg = 'cx-notification-deleted-draft';
51        } elseif ( $this->getType() === 'cx-continue-translation' ) {
52            $msg = 'cx-notification-continue-translation';
53        } else {
54            return parent::getHeaderMessage();
55        }
56
57        if ( $this->isBundled() ) {
58            return $this->msg( $msg . '-bundle' )->numParams( $this->getBundleCount() );
59        }
60
61        return $this->msg( $msg, wfEscapeWikiText( $this->event->getTitle()->getText() ) );
62    }
63
64    public function getCompactHeaderMessage() {
65        $msg = new RawMessage( '$1' );
66        $msg->plaintextParams( $this->event->getTitle()->getText() );
67        return $msg;
68    }
69
70    public function getSecondaryLinks() {
71        if ( $this->isBundled() ) {
72            return [];
73        }
74
75        return [ $this->getYourTranslationsLink() ];
76    }
77
78    private function getYourTranslationsLink() {
79        return [
80            'url' => SpecialPage::getTitleFor( 'ContentTranslation' )->getLocalURL(),
81            'icon' => 'article',
82            'label' => $this->msg( 'cx-your-translations-link' ),
83            'prioritized' => true
84        ];
85    }
86}