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 MediaWiki\Extension\DiscussionTools\Notifications\AddedTopicPresentationModel;
|
2022-01-09 00:50:22 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\Notifications\CommentThanksPresentationModel;
|
2023-06-08 16:52:12 +00:00
|
|
|
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;
|
2024-05-28 14:46:27 +00:00
|
|
|
use MediaWiki\Extension\Notifications\UserLocator;
|
2024-10-19 21:39:18 +00:00
|
|
|
use MediaWiki\Registration\ExtensionRegistry;
|
2021-02-09 21:51:09 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2024-01-11 21:35:01 +00:00
|
|
|
use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
|
2021-02-09 21:51:09 +00:00
|
|
|
|
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
|
|
|
|
*/
|
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' => [
|
|
|
|
[
|
2024-05-28 14:46:27 +00:00
|
|
|
[ UserLocator::class, 'locateFromEventExtra' ],
|
2023-06-08 16:52:12 +00:00
|
|
|
[ 'mentioned-users' ]
|
2021-06-02 23:24:30 +00:00
|
|
|
],
|
2024-05-28 14:46:27 +00:00
|
|
|
[ [ UserLocator::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
|
|
|
|
2022-01-09 00:50:22 +00:00
|
|
|
if ( ExtensionRegistry::getInstance()->isLoaded( 'Thanks' ) ) {
|
|
|
|
$notifications['dt-thank'] = [
|
|
|
|
'category' => 'edit-thank',
|
|
|
|
'group' => 'positive',
|
|
|
|
'section' => 'message',
|
|
|
|
'user-locators' => [
|
|
|
|
[
|
|
|
|
[ UserLocator::class, 'locateFromEventExtra' ],
|
|
|
|
[ 'thanked-user-id' ]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'presentation-model' => CommentThanksPresentationModel::class,
|
|
|
|
'bundle' => [
|
|
|
|
'web' => true,
|
|
|
|
'expandable' => true,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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-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;
|
2022-01-09 00:50:22 +00:00
|
|
|
case 'dt-thank':
|
|
|
|
$bundleString = $event->getType() . '-' . $event->getExtraParam( 'comment-name' );
|
|
|
|
break;
|
2021-02-09 21:51:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-01-11 21:35:01 +00:00
|
|
|
* @throws ResourceLimitExceededException
|
2021-02-09 21:51:09 +00:00
|
|
|
*/
|
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 );
|
|
|
|
}
|
|
|
|
}
|