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