Debian Codegraph @

extensions/DiscussionTools/includes/Notifications/RemovedTopicPresentationModel.php

raw symbols SCIP
1 <?php
2 /**
3 * EchoEventPresentationModel for removed subscribable section headings
4 *
5 * @file
6 * @ingroup Extensions
7 * @license MIT
8 */
9
10 namespace MediaWiki\Extension\DiscussionTools\Notifications;
11
12 use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel;
13 use MediaWiki\Extension\Notifications\Model\Event;
14 use MediaWiki\Language\Language;
15 use MediaWiki\MediaWikiServices;
16 use MediaWiki\SpecialPage\SpecialPage;
17 use MediaWiki\User\User;
18
19 class 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 }