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 / 2
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 / 2
72
0.00% covered (danger)
0.00%
0 / 1
 onBeforeCreateEchoEvent
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 onEchoGetBundleRules
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2
3/**
4 * Hooks for Thanks extension
5 *
6 * @file
7 * @ingroup Extensions
8 */
9
10namespace MediaWiki\Extension\Thanks;
11
12use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook;
13use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook;
14use MediaWiki\Extension\Notifications\Model\Event;
15use MediaWiki\Registration\ExtensionRegistry;
16
17class EchoHooks implements BeforeCreateEchoEventHook, EchoGetBundleRulesHook {
18
19    /**
20     * @param array &$notifications array of Echo notifications
21     * @param array &$notificationCategories array of Echo notification categories
22     * @param array &$icons array of icon details
23     */
24    public function onBeforeCreateEchoEvent(
25        array &$notifications, array &$notificationCategories, array &$icons
26    ) {
27        // Only allow Flow thanks notifications when enabled
28        if ( !ExtensionRegistry::getInstance()->isLoaded( 'Flow' ) ) {
29            unset( $notifications['flow-thank'] );
30        }
31    }
32
33    /**
34     * Handler for EchoGetBundleRule hook, which defines the bundle rules for each notification.
35     *
36     * @param Event $event The event being notified.
37     * @param string &$bundleString Determines how the notification should be bundled.
38     */
39    public function onEchoGetBundleRules( Event $event, string &$bundleString ) {
40        switch ( $event->getType() ) {
41            case 'edit-thank':
42                $bundleString = 'edit-thank';
43                // Try to get either the revid or logid parameter.
44                $revOrLogId = $event->getExtraParam( 'logid' );
45                if ( $revOrLogId ) {
46                    // avoid collision with revision ids
47                    $revOrLogId = 'log' . $revOrLogId;
48                } else {
49                    $revOrLogId = $event->getExtraParam( 'revid' );
50                }
51                if ( $revOrLogId ) {
52                    $bundleString .= $revOrLogId;
53                }
54                break;
55            case 'flow-thank':
56                $bundleString = 'flow-thank';
57                $postId = $event->getExtraParam( 'post-id' );
58                if ( $postId ) {
59                    $bundleString .= $postId;
60                }
61                break;
62        }
63    }
64
65}