Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 78
0.00% covered (danger)
0.00%
0 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
RemovedTopicPresentationModel
0.00% covered (danger)
0.00%
0 / 78
0.00% covered (danger)
0.00%
0 / 9
342
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getIconType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 canRender
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 / 14
0.00% covered (danger)
0.00%
0 / 1
20
 getHeaderMessageKey
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getHeaderMessage
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 getCompactHeaderMessage
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getBodyMessage
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getSecondaryLinks
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * EchoEventPresentationModel for removed subscribable section headings
4 *
5 * @file
6 * @ingroup Extensions
7 * @license MIT
8 */
9
10namespace MediaWiki\Extension\DiscussionTools\Notifications;
11
12use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel;
13use MediaWiki\Extension\Notifications\Model\Event;
14use MediaWiki\Language\Language;
15use MediaWiki\MediaWikiServices;
16use MediaWiki\SpecialPage\SpecialPage;
17use MediaWiki\User\User;
18
19class RemovedTopicPresentationModel extends EchoEventPresentationModel {
20
21    protected PlaintextEchoPresentationModelSection $section;
22
23    /**
24     * @inheritDoc
25     */
26    protected function __construct( Event $event, Language $language, User $user, $distributionType ) {
27        parent::__construct( $event, $language, $user, $distributionType );
28        $this->section = new PlaintextEchoPresentationModelSection( $event, $user, $language );
29    }
30
31    /**
32     * @inheritDoc
33     */
34    public function getIconType() {
35        return 'placeholder';
36    }
37
38    /**
39     * @inheritDoc
40     */
41    public function canRender() {
42        return (bool)$this->event->getTitle();
43    }
44
45    /**
46     * @inheritDoc
47     */
48    public function getPrimaryLink() {
49        $rev = $this->event->getExtraParam( 'revid' );
50
51        if ( $this->isBundled() ) {
52            // No link, unless all of these events are from one edit
53            foreach ( $this->getBundledEvents() as $event ) {
54                if ( $event->getExtraParam( 'revid' ) !== $rev ) {
55                    return false;
56                }
57            }
58        }
59
60        $title = $this->event->getTitle();
61        $url = $title->getLocalURL( [
62            'oldid' => 'prev',
63            'diff' => $rev
64        ] );
65
66        return [
67            'url' => $url,
68            'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(),
69        ];
70    }
71
72    /**
73     * @inheritDoc
74     */
75    protected function getHeaderMessageKey() {
76        if ( $this->isBundled() ) {
77            return 'discussiontools-notification-removed-topic-header-bundled';
78        } else {
79            return 'discussiontools-notification-removed-topic-header';
80        }
81    }
82
83    /**
84     * @inheritDoc
85     */
86    public function getHeaderMessage() {
87        if ( $this->isBundled() ) {
88            $msg = $this->msg( $this->getHeaderMessageKey() );
89            $msg->numParams( $this->getNotificationCountForOutput() );
90            $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
91            return $msg;
92        } else {
93            $msg = parent::getHeaderMessage();
94            $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
95            $msg->plaintextParams( $this->section->getTruncatedSectionTitle() );
96            return $msg;
97        }
98    }
99
100    /**
101     * @inheritDoc
102     */
103    public function getCompactHeaderMessage() {
104        $msg = $this->getMessageWithAgent( 'discussiontools-notification-removed-topic-header-compact' );
105        $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
106        $msg->plaintextParams( $this->section->getTruncatedSectionTitle() );
107        return $msg;
108    }
109
110    /**
111     * @inheritDoc
112     */
113    public function getBodyMessage() {
114        return $this->msg( 'discussiontools-notification-removed-topic-body' )
115            ->numParams( $this->getNotificationCountForOutput() );
116    }
117
118    /**
119     * @inheritDoc
120     */
121    public function getSecondaryLinks() {
122        global $wgEchoNotifiers;
123
124        $viewPageLink = [
125            'url' => $this->event->getTitle()->getFullURL(),
126            'label' => $this->msg( 'discussiontools-notification-removed-topic-view' )->text(),
127            'description' => '',
128            'icon' => 'article',
129            'prioritized' => true,
130        ];
131
132        $links = [
133            $viewPageLink,
134        ];
135
136        // Known preferences used below:
137        // * echo-subscriptions-email-dt-subscription-archiving
138        // * echo-subscriptions-push-dt-subscription-archiving
139        // * echo-subscriptions-web-dt-subscription-archiving
140
141        $category = $this->getCategory();
142        $isDisabled = true;
143        $optionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
144        foreach ( $wgEchoNotifiers as $notifierType => $unused ) {
145            if ( $optionsLookup->getOption( $this->getUser(), "echo-subscriptions-$notifierType-$category" ) ) {
146                $isDisabled = false;
147            }
148        }
149
150        if ( !$isDisabled ) {
151            $setPrefs = [];
152            foreach ( $wgEchoNotifiers as $notifierType => $unused ) {
153                $setPrefs[] = "echo-subscriptions-$notifierType-$category=0";
154            }
155
156            $links[] = $this->getDynamicActionLink(
157                SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo-echosubscriptions' ),
158                'unbell',
159                $this->msg( 'discussiontools-notification-removed-topic-disable' )->text(),
160                null,
161                [
162                    'tokenType' => 'csrf',
163                    'params' => [
164                        'action' => 'options',
165                        'change' => implode( '|', $setPrefs ),
166                    ],
167                    'messages' => [
168                        'confirmation' => [
169                            'title' => $this->msg( 'discussiontools-notification-removed-topic-disabled-title' ),
170                            'description' => $this->msg( 'discussiontools-notification-removed-topic-disabled-body' )
171                        ]
172                    ]
173                ],
174                []
175            );
176        }
177
178        return $links;
179    }
180}