Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 71 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
EchoHooks | |
0.00% |
0 / 71 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
onBeforeCreateEchoEvent | |
0.00% |
0 / 59 |
|
0.00% |
0 / 1 |
2 | |||
onEchoGetBundleRules | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
onEchoGetEventsForRevision | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * DiscussionTools echo hooks |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | * @license MIT |
8 | */ |
9 | |
10 | namespace MediaWiki\Extension\DiscussionTools\Hooks; |
11 | |
12 | use EchoUserLocator; |
13 | use MediaWiki\Extension\DiscussionTools\Notifications\AddedTopicPresentationModel; |
14 | use MediaWiki\Extension\DiscussionTools\Notifications\EnhancedEchoEditUserTalkPresentationModel; |
15 | use MediaWiki\Extension\DiscussionTools\Notifications\EnhancedEchoMentionPresentationModel; |
16 | use MediaWiki\Extension\DiscussionTools\Notifications\EventDispatcher; |
17 | use MediaWiki\Extension\DiscussionTools\Notifications\RemovedTopicPresentationModel; |
18 | use MediaWiki\Extension\DiscussionTools\Notifications\SubscribedNewCommentPresentationModel; |
19 | use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook; |
20 | use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook; |
21 | use MediaWiki\Extension\Notifications\Hooks\EchoGetEventsForRevisionHook; |
22 | use MediaWiki\Extension\Notifications\Model\Event; |
23 | use MediaWiki\Revision\RevisionRecord; |
24 | use Wikimedia\Parsoid\Core\ResourceLimitExceededException; |
25 | |
26 | class EchoHooks implements |
27 | BeforeCreateEchoEventHook, |
28 | EchoGetBundleRulesHook, |
29 | EchoGetEventsForRevisionHook |
30 | { |
31 | /** |
32 | * Add notification events to Echo |
33 | */ |
34 | public function onBeforeCreateEchoEvent( |
35 | array &$notifications, |
36 | array &$notificationCategories, |
37 | array &$icons |
38 | ) { |
39 | // The following messages are generated upstream |
40 | // * echo-category-title-dt-subscription |
41 | $notificationCategories['dt-subscription'] = [ |
42 | 'priority' => 3, |
43 | 'tooltip' => 'echo-pref-tooltip-dt-subscription', |
44 | ]; |
45 | $notifications['dt-subscribed-new-comment'] = [ |
46 | 'category' => 'dt-subscription', |
47 | 'group' => 'interactive', |
48 | 'section' => 'message', |
49 | 'user-locators' => [ |
50 | [ [ EventDispatcher::class, 'locateSubscribedUsers' ] ] |
51 | ], |
52 | // Exclude mentioned users and talk page owner from our notification, to avoid |
53 | // duplicate notifications for a single comment |
54 | 'user-filters' => [ |
55 | [ |
56 | [ EchoUserLocator::class, 'locateFromEventExtra' ], |
57 | [ 'mentioned-users' ] |
58 | ], |
59 | [ [ EchoUserLocator::class, 'locateTalkPageOwner' ] ], |
60 | ], |
61 | 'presentation-model' => SubscribedNewCommentPresentationModel::class, |
62 | 'bundle' => [ |
63 | 'web' => true, |
64 | 'email' => true, |
65 | 'expandable' => true, |
66 | ], |
67 | ]; |
68 | |
69 | // The following messages are generated upstream |
70 | // * echo-category-title-dt-subscription-archiving |
71 | $notificationCategories['dt-subscription-archiving'] = [ |
72 | 'priority' => 3, |
73 | 'tooltip' => 'echo-pref-tooltip-dt-subscription-archiving', |
74 | ]; |
75 | $notifications['dt-removed-topic'] = [ |
76 | 'category' => 'dt-subscription-archiving', |
77 | 'group' => 'interactive', |
78 | 'section' => 'message', |
79 | 'user-locators' => [ |
80 | [ [ EventDispatcher::class, 'locateSubscribedUsers' ] ] |
81 | ], |
82 | 'presentation-model' => RemovedTopicPresentationModel::class, |
83 | 'bundle' => [ |
84 | 'web' => true, |
85 | 'email' => true, |
86 | 'expandable' => true, |
87 | ], |
88 | ]; |
89 | $notifications['dt-added-topic'] = [ |
90 | 'category' => 'dt-subscription', |
91 | 'group' => 'interactive', |
92 | 'section' => 'message', |
93 | 'user-locators' => [ |
94 | [ [ EventDispatcher::class, 'locateSubscribedUsers' ] ] |
95 | ], |
96 | 'presentation-model' => AddedTopicPresentationModel::class, |
97 | 'bundle' => [ |
98 | 'web' => true, |
99 | 'email' => true, |
100 | 'expandable' => true, |
101 | ], |
102 | ]; |
103 | |
104 | // Override default handlers |
105 | $notifications['edit-user-talk']['presentation-model'] = EnhancedEchoEditUserTalkPresentationModel::class; |
106 | $notifications['mention']['presentation-model'] = EnhancedEchoMentionPresentationModel::class; |
107 | } |
108 | |
109 | public function onEchoGetBundleRules( Event $event, string &$bundleString ) { |
110 | switch ( $event->getType() ) { |
111 | case 'dt-subscribed-new-comment': |
112 | $bundleString = $event->getType() . '-' . $event->getExtraParam( 'subscribed-comment-name' ); |
113 | break; |
114 | case 'dt-added-topic': |
115 | case 'dt-removed-topic': |
116 | $bundleString = $event->getType() . '-' . $event->getTitle()->getNamespace() |
117 | . '-' . $event->getTitle()->getDBkey(); |
118 | break; |
119 | } |
120 | } |
121 | |
122 | /** |
123 | * @throws ResourceLimitExceededException |
124 | */ |
125 | public function onEchoGetEventsForRevision( array &$events, RevisionRecord $revision, bool $isRevert ) { |
126 | if ( $isRevert ) { |
127 | return; |
128 | } |
129 | EventDispatcher::generateEventsForRevision( $events, $revision ); |
130 | } |
131 | } |