2021-02-09 21:51:09 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DiscussionTools echo hooks
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
|
|
|
|
2023-06-08 16:52:12 +00:00
|
|
|
use EchoUserLocator;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\Notifications\AddedTopicPresentationModel;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\Notifications\EnhancedEchoEditUserTalkPresentationModel;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\Notifications\EnhancedEchoMentionPresentationModel;
|
2021-02-09 21:51:09 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\Notifications\EventDispatcher;
|
2023-06-08 16:52:12 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\Notifications\RemovedTopicPresentationModel;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\Notifications\SubscribedNewCommentPresentationModel;
|
2023-08-15 22:39:43 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook;
|
|
|
|
use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook;
|
|
|
|
use MediaWiki\Extension\Notifications\Hooks\EchoGetEventsForRevisionHook;
|
2023-06-08 08:16:15 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
2021-02-09 21:51:09 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
2023-08-15 22:39:43 +00:00
|
|
|
class EchoHooks implements
|
|
|
|
BeforeCreateEchoEventHook,
|
|
|
|
EchoGetBundleRulesHook,
|
|
|
|
EchoGetEventsForRevisionHook
|
|
|
|
{
|
2021-02-09 21:51:09 +00:00
|
|
|
/**
|
|
|
|
* Add notification events to Echo
|
|
|
|
*
|
|
|
|
* @param array &$notifications
|
|
|
|
* @param array &$notificationCategories
|
|
|
|
* @param array &$icons
|
|
|
|
*/
|
2023-08-15 22:39:43 +00:00
|
|
|
public function onBeforeCreateEchoEvent(
|
2021-02-09 21:51:09 +00:00
|
|
|
array &$notifications,
|
|
|
|
array &$notificationCategories,
|
|
|
|
array &$icons
|
|
|
|
) {
|
2023-11-02 16:29:54 +00:00
|
|
|
// The following messages are generated upstream
|
|
|
|
// * echo-category-title-dt-subscription
|
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' => [
|
2023-06-08 16:52:12 +00:00
|
|
|
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ]
|
2021-02-09 21:51:09 +00:00
|
|
|
],
|
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' => [
|
|
|
|
[
|
2023-06-08 16:52:12 +00:00
|
|
|
[ EchoUserLocator::class, 'locateFromEventExtra' ],
|
|
|
|
[ 'mentioned-users' ]
|
2021-06-02 23:24:30 +00:00
|
|
|
],
|
2023-06-08 16:52:12 +00:00
|
|
|
[ [ EchoUserLocator::class, 'locateTalkPageOwner' ] ],
|
2021-02-09 21:51:09 +00:00
|
|
|
],
|
2023-06-08 16:52:12 +00:00
|
|
|
'presentation-model' => SubscribedNewCommentPresentationModel::class,
|
2021-02-09 21:51:09 +00:00
|
|
|
'bundle' => [
|
|
|
|
'web' => true,
|
|
|
|
'email' => true,
|
|
|
|
'expandable' => true,
|
|
|
|
],
|
|
|
|
];
|
2021-04-30 16:07:31 +00:00
|
|
|
|
2023-11-02 16:29:54 +00:00
|
|
|
// The following messages are generated upstream
|
|
|
|
// * echo-category-title-dt-subscription-archiving
|
2022-07-30 21:59:55 +00:00
|
|
|
$notificationCategories['dt-subscription-archiving'] = [
|
|
|
|
'priority' => 3,
|
|
|
|
'tooltip' => 'echo-pref-tooltip-dt-subscription-archiving',
|
|
|
|
];
|
|
|
|
$notifications['dt-removed-topic'] = [
|
|
|
|
'category' => 'dt-subscription-archiving',
|
|
|
|
'group' => 'interactive',
|
|
|
|
'section' => 'message',
|
|
|
|
'user-locators' => [
|
2023-06-08 16:52:12 +00:00
|
|
|
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ]
|
2022-07-30 21:59:55 +00:00
|
|
|
],
|
2023-06-08 16:52:12 +00:00
|
|
|
'presentation-model' => RemovedTopicPresentationModel::class,
|
2022-07-30 21:59:55 +00:00
|
|
|
'bundle' => [
|
|
|
|
'web' => true,
|
|
|
|
'email' => true,
|
|
|
|
'expandable' => true,
|
|
|
|
],
|
|
|
|
];
|
2023-02-06 15:29:28 +00:00
|
|
|
$notifications['dt-added-topic'] = [
|
|
|
|
'category' => 'dt-subscription',
|
|
|
|
'group' => 'interactive',
|
|
|
|
'section' => 'message',
|
|
|
|
'user-locators' => [
|
2023-06-08 16:52:12 +00:00
|
|
|
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ]
|
2023-02-06 15:29:28 +00:00
|
|
|
],
|
2023-06-08 16:52:12 +00:00
|
|
|
'presentation-model' => AddedTopicPresentationModel::class,
|
2023-02-06 15:29:28 +00:00
|
|
|
'bundle' => [
|
|
|
|
'web' => true,
|
|
|
|
'email' => true,
|
|
|
|
'expandable' => true,
|
|
|
|
],
|
|
|
|
];
|
2022-07-30 21:59:55 +00:00
|
|
|
|
2021-04-30 16:07:31 +00:00
|
|
|
// Override default handlers
|
2023-06-08 16:52:12 +00:00
|
|
|
$notifications['edit-user-talk']['presentation-model'] = EnhancedEchoEditUserTalkPresentationModel::class;
|
|
|
|
$notifications['mention']['presentation-model'] = EnhancedEchoMentionPresentationModel::class;
|
2021-02-09 21:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-06-08 08:16:15 +00:00
|
|
|
* @param Event $event
|
2021-02-09 21:51:09 +00:00
|
|
|
* @param string &$bundleString
|
|
|
|
*/
|
2023-08-15 22:39:43 +00:00
|
|
|
public function onEchoGetBundleRules( Event $event, string &$bundleString ) {
|
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;
|
2023-01-31 15:50:34 +00:00
|
|
|
case 'dt-added-topic':
|
2022-07-30 21:59:55 +00:00
|
|
|
case 'dt-removed-topic':
|
|
|
|
$bundleString = $event->getType() . '-' . $event->getTitle()->getNamespace()
|
|
|
|
. '-' . $event->getTitle()->getDBkey();
|
|
|
|
break;
|
2021-02-09 21:51:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array &$events
|
|
|
|
* @param RevisionRecord $revision
|
|
|
|
* @param bool $isRevert
|
|
|
|
*/
|
2023-08-15 22:39:43 +00:00
|
|
|
public function onEchoGetEventsForRevision( array &$events, RevisionRecord $revision, bool $isRevert ) {
|
2021-02-09 21:51:09 +00:00
|
|
|
if ( $isRevert ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EventDispatcher::generateEventsForRevision( $events, $revision );
|
|
|
|
}
|
|
|
|
}
|