2021-02-09 21:51:09 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DiscussionTools echo hooks
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
|
|
|
|
|
|
|
use EchoEvent;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\Notifications\EventDispatcher;
|
2021-04-11 14:47:08 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-02-09 21:51:09 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
|
|
|
class EchoHooks {
|
|
|
|
/**
|
|
|
|
* Add notification events to Echo
|
|
|
|
*
|
|
|
|
* @param array &$notifications
|
|
|
|
* @param array &$notificationCategories
|
|
|
|
* @param array &$icons
|
|
|
|
*/
|
|
|
|
public static function onBeforeCreateEchoEvent(
|
|
|
|
array &$notifications,
|
|
|
|
array &$notificationCategories,
|
|
|
|
array &$icons
|
|
|
|
) {
|
2021-04-11 14:47:08 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
|
2021-06-07 20:45:54 +00:00
|
|
|
if ( !$dtConfig->get( 'DiscussionToolsEnableTopicSubscriptionBackend' ) ) {
|
2021-04-11 14:47:08 +00:00
|
|
|
// Topic subscriptions not available on wiki.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:51:09 +00:00
|
|
|
$notificationCategories['dt-subscription'] = [
|
|
|
|
'priority' => 3,
|
|
|
|
'tooltip' => 'echo-pref-tooltip-dt-subscription',
|
|
|
|
];
|
|
|
|
|
|
|
|
$notifications['dt-subscribed-new-comment'] = [
|
|
|
|
'category' => 'dt-subscription',
|
|
|
|
'group' => 'interactive',
|
|
|
|
'section' => 'message',
|
|
|
|
'user-locators' => [
|
|
|
|
'MediaWiki\\Extension\\DiscussionTools\\Notifications\\EventDispatcher::locateSubscribedUsers'
|
|
|
|
],
|
2021-06-02 23:24:30 +00:00
|
|
|
// Exclude mentioned users and talk page owner from our notification, to avoid
|
|
|
|
// duplicate notifications for a single comment
|
2021-02-09 21:51:09 +00:00
|
|
|
'user-filters' => [
|
|
|
|
[
|
|
|
|
"EchoUserLocator::locateFromEventExtra",
|
|
|
|
[ "mentioned-users" ]
|
2021-06-02 23:24:30 +00:00
|
|
|
],
|
|
|
|
"EchoUserLocator::locateTalkPageOwner"
|
2021-02-09 21:51:09 +00:00
|
|
|
],
|
|
|
|
'presentation-model' =>
|
|
|
|
'MediaWiki\\Extension\\DiscussionTools\\Notifications\\SubscribedNewCommentPresentationModel',
|
|
|
|
'bundle' => [
|
|
|
|
'web' => true,
|
|
|
|
'email' => true,
|
|
|
|
'expandable' => true,
|
|
|
|
],
|
|
|
|
];
|
2021-04-30 16:07:31 +00:00
|
|
|
|
|
|
|
// Override default handlers
|
|
|
|
$notifications['edit-user-talk']['presentation-model'] =
|
|
|
|
'MediaWiki\\Extension\\DiscussionTools\\Notifications\\EnhancedEchoEditUserTalkPresentationModel';
|
|
|
|
$notifications['mention']['presentation-model'] =
|
|
|
|
'MediaWiki\\Extension\\DiscussionTools\\Notifications\\EnhancedEchoMentionPresentationModel';
|
2021-02-09 21:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param EchoEvent $event
|
|
|
|
* @param string &$bundleString
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public static function onEchoGetBundleRules( EchoEvent $event, string &$bundleString ): bool {
|
2021-02-09 21:51:09 +00:00
|
|
|
switch ( $event->getType() ) {
|
|
|
|
case 'dt-subscribed-new-comment':
|
|
|
|
$bundleString = $event->getType() . '-' . $event->getExtraParam( 'subscribed-comment-name' );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array &$events
|
|
|
|
* @param RevisionRecord $revision
|
|
|
|
* @param bool $isRevert
|
|
|
|
*/
|
|
|
|
public static function onEchoGetEventsForRevision( array &$events, RevisionRecord $revision, bool $isRevert ) {
|
|
|
|
if ( $isRevert ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EventDispatcher::generateEventsForRevision( $events, $revision );
|
|
|
|
}
|
|
|
|
}
|