1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Notifications; |
4
|
|
|
|
5
|
|
|
use EchoEvent; |
6
|
|
|
use EchoAttributeManager; |
7
|
|
|
use SMW\Notifications\ChangeNotification\ChangeNotificationFilter; |
8
|
|
|
use SMW\Notifications\ChangeNotification\ChangeNotificationFormatter; |
9
|
|
|
use SMW\Notifications\ChangeNotification\ChangeNotificationPresentationModel; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class EchoNotificationsManager { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @see Echo::BeforeCreateEchoEvent |
21
|
|
|
* |
22
|
|
|
* @since 1.0 |
23
|
|
|
* |
24
|
|
|
* @param array &$notifications |
25
|
|
|
* @param array &$notificationCategories |
26
|
|
|
* @param array &$icons |
27
|
|
|
*/ |
28
|
1 |
|
public static function initNotificationsDefinitions( array &$notifications, array &$notificationCategories, array &$icons ) { |
29
|
|
|
|
30
|
1 |
|
$valueChangeNotificationType = ChangeNotificationFilter::VALUE_CHANGE; |
31
|
1 |
|
$specificationChangeNotificationType = ChangeNotificationFilter::SPECIFICATION_CHANGE; |
32
|
|
|
|
33
|
1 |
|
$notificationCategories[$valueChangeNotificationType] = array( |
34
|
|
|
'priority' => 5, |
35
|
|
|
'tooltip' => 'echo-pref-tooltip-smw-value-change', |
36
|
|
|
); |
37
|
|
|
|
38
|
1 |
|
$notificationCategories[$specificationChangeNotificationType] = array( |
39
|
|
|
'priority' => 5, |
40
|
|
|
'tooltip' => 'echo-pref-tooltip-smw-specification-change', |
41
|
|
|
); |
42
|
|
|
|
43
|
1 |
|
$notifications[$valueChangeNotificationType] = array( |
44
|
1 |
|
EchoAttributeManager::ATTR_LOCATORS => [ |
45
|
|
|
'\SMW\Notifications\ChangeNotification\UserLocator::doLocateEventSubscribers' |
46
|
|
|
], |
47
|
1 |
|
'category' => 'smw-value-change', |
48
|
1 |
|
'group' => 'neutral', |
49
|
1 |
|
'section' => 'alert', |
50
|
|
|
'presentation-model' => ChangeNotificationPresentationModel::class, |
51
|
|
|
'formatter-class' => ChangeNotificationFormatter::class, |
52
|
1 |
|
'title-message' => "notification-{$valueChangeNotificationType}", |
53
|
|
|
'title-params' => array( |
54
|
|
|
'agent', 'difflink', 'title' |
55
|
|
|
), |
56
|
1 |
|
'flyout-message' => "notification-{$valueChangeNotificationType}-flyout", |
57
|
|
|
'flyout-params' => array( |
58
|
|
|
'agent', 'difflink', 'title' |
59
|
|
|
), |
60
|
|
|
'payload' => array( 'extra' ), |
61
|
|
|
'bundle' => array( |
62
|
|
|
'web' => true, |
63
|
|
|
'email' => false |
64
|
|
|
), |
65
|
1 |
|
'email-subject-message' => "notification-{$valueChangeNotificationType}-email-subject", |
66
|
|
|
'email-subject-params' => array( |
67
|
|
|
'user', |
68
|
|
|
'agent' |
69
|
|
|
), |
70
|
1 |
|
'email-body-batch-message' => "notification-{$valueChangeNotificationType}-email-batch-body", |
71
|
|
|
'email-body-batch-params' => array( |
72
|
|
|
'title', |
73
|
|
|
'agent' |
74
|
|
|
), |
75
|
1 |
|
'icon' => $valueChangeNotificationType, |
76
|
|
|
); |
77
|
|
|
|
78
|
1 |
|
$notifications[$specificationChangeNotificationType] = array( |
79
|
1 |
|
EchoAttributeManager::ATTR_LOCATORS => [ |
80
|
|
|
'\SMW\Notifications\ChangeNotification\UserLocator::doLocateEventSubscribers' |
81
|
|
|
], |
82
|
1 |
|
'category' => 'smw-specification-change', |
83
|
1 |
|
'group' => 'neutral', |
84
|
1 |
|
'section' => 'alert', |
85
|
|
|
'presentation-model' => ChangeNotificationPresentationModel::class, |
86
|
|
|
'formatter-class' => ChangeNotificationFormatter::class, |
87
|
1 |
|
'title-message' => "notification-{$valueChangeNotificationType}", |
88
|
|
|
'title-params' => array( |
89
|
|
|
'agent', 'difflink', 'title' |
90
|
|
|
), |
91
|
1 |
|
'flyout-message' => "notification-{$valueChangeNotificationType}-flyout", |
92
|
|
|
'flyout-params' => array( |
93
|
|
|
'agent', 'difflink', 'title' |
94
|
|
|
), |
95
|
|
|
'payload' => array( 'extra' ), |
96
|
|
|
'bundle' => array( |
97
|
|
|
'web' => true, |
98
|
|
|
'email' => false |
99
|
|
|
), |
100
|
1 |
|
'email-subject-message' => "notification-{$valueChangeNotificationType}-email-subject", |
101
|
|
|
'email-subject-params' => array( |
102
|
|
|
'user', |
103
|
|
|
'agent' |
104
|
|
|
), |
105
|
1 |
|
'email-body-batch-message' => "notification-{$valueChangeNotificationType}-email-batch-body", |
106
|
|
|
'email-body-batch-params' => array( |
107
|
|
|
'title', |
108
|
|
|
'agent', |
109
|
|
|
'item' |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
|
113
|
1 |
|
$icons[$valueChangeNotificationType] = array( |
114
|
|
|
'path' => "SemanticNotifications/res/smw-entity-change-yellow.png" |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
// Resolved in ChangeNotificationPresentationModel::getIconType |
118
|
1 |
|
$icons[$specificationChangeNotificationType . '-property'] = array( |
119
|
|
|
'path' => "SemanticNotifications/res/smw-entity-change-blue.png" |
120
|
|
|
); |
121
|
|
|
|
122
|
1 |
|
$icons[$specificationChangeNotificationType . '-category'] = array( |
123
|
|
|
'path' => "SemanticNotifications/res/smw-entity-change-green.png" |
124
|
|
|
); |
125
|
1 |
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @see https://www.mediawiki.org/wiki/Notifications/Developer_guide#Conventions |
129
|
|
|
* |
130
|
|
|
* @since 1.0 |
131
|
|
|
* |
132
|
|
|
* @param array &$defaultOptions |
133
|
|
|
* |
134
|
|
|
*/ |
135
|
1 |
|
public function addDefaultOptions( array &$defaultOptions ) { |
136
|
1 |
|
$defaultOptions['echo-subscriptions-web-' . ChangeNotificationFilter::VALUE_CHANGE] = true; |
137
|
1 |
|
return true; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @see https://www.mediawiki.org/wiki/Notifications/Developer_guide#Bundled_notification |
142
|
|
|
* |
143
|
|
|
* @since 1.0 |
144
|
|
|
* |
145
|
|
|
* @param EchoEvent $event |
146
|
|
|
* @param string &$bundleString |
147
|
|
|
*/ |
148
|
1 |
|
public function getNotificationsBundle( EchoEvent $event, &$bundleString ) { |
149
|
|
|
|
150
|
1 |
|
$extra = $event->getExtra(); |
151
|
|
|
|
152
|
|
|
if ( |
153
|
1 |
|
$event->getType() === ChangeNotificationFilter::VALUE_CHANGE || |
154
|
1 |
|
$event->getType() === ChangeNotificationFilter::SPECIFICATION_CHANGE ) { |
155
|
1 |
|
$bundleString = $extra['subject']->getHash() . $extra['revid']; |
156
|
|
|
} |
157
|
1 |
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @since 1.0 |
161
|
|
|
* |
162
|
|
|
* @param array $event |
163
|
|
|
* |
164
|
|
|
* @return EchoEvent |
165
|
|
|
*/ |
166
|
1 |
|
public function createEvent( array $event ) { |
167
|
|
|
|
168
|
1 |
|
if ( $event === array() ) { |
169
|
|
|
return; |
170
|
|
|
} |
171
|
|
|
|
172
|
1 |
|
wfDebugLog( 'smw', 'EchoEvent triggered' ); |
173
|
|
|
|
174
|
1 |
|
return EchoEvent::create( $event ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @see https://www.mediawiki.org/wiki/Notifications/Developer_guide#Create_the_notification_via_the_Echo_extension |
179
|
|
|
* |
180
|
|
|
* @since 1.0 |
181
|
|
|
* |
182
|
|
|
* @param EchoEvent $event |
183
|
|
|
* @param array &$users |
184
|
|
|
*/ |
185
|
1 |
|
public function getDefaultRecipientsByType( EchoEvent $event, &$users ) { |
186
|
|
|
|
187
|
1 |
|
$extra = $event->getExtra(); |
188
|
|
|
|
189
|
1 |
|
if ( $event->getType() === ChangeNotificationFilter::VALUE_CHANGE ) { |
190
|
1 |
|
if ( isset( $extra['recipients'] ) ) { |
191
|
|
|
foreach ( $extra['recipients'] as $key => $recipient ) { |
192
|
|
|
$users[] = \User::newFromName( $recipient, false ); |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
} |
196
|
1 |
|
} |
197
|
|
|
|
198
|
|
|
} |
199
|
|
|
|