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