mediawiki-extensions-Discus.../includes/Hooks/EchoHooks.php
Bartosz Dziewoński 69e8e948b2 Remove now redundant PHPDoc blocks
MediaWiki's PHPCS plugin requires documentation comments on all
methods, unless those methods are fully typed (all parameters and
return value).

It turns out that almost all of our methods are fully typed already.

Procedure:

1. Find: \*(\s*\*\s*(@param \??[\w\\]+(\|null)? &?\$\w+|@return \??[\w\\]+(\|null)?)\n)+\s*\*/
   Replace with: */
   This deletes type annotations, except those not representable
   as PHP type hints such as union types `a|b` or typed arrays `a[]`,
   or those with documentation beyond type hints, or those on
   functions with any other annotations.

2. Find: /\*\*/\n\s*
   Replace with nothing
   This deletes the remaining comments on methods that had no prose
   documentation.

3. Undo all changes that PHPCS complains about (those comments
   were not redundant)

4. Review the diff carefully, these regexps are imprecise :)

Change-Id: Ic82e8b23f2996f44951208dbd9cfb4c8e0738dac
2024-03-10 23:53:04 +00:00

132 lines
4.2 KiB
PHP

<?php
/**
* DiscussionTools echo hooks
*
* @file
* @ingroup Extensions
* @license MIT
*/
namespace MediaWiki\Extension\DiscussionTools\Hooks;
use EchoUserLocator;
use MediaWiki\Extension\DiscussionTools\Notifications\AddedTopicPresentationModel;
use MediaWiki\Extension\DiscussionTools\Notifications\EnhancedEchoEditUserTalkPresentationModel;
use MediaWiki\Extension\DiscussionTools\Notifications\EnhancedEchoMentionPresentationModel;
use MediaWiki\Extension\DiscussionTools\Notifications\EventDispatcher;
use MediaWiki\Extension\DiscussionTools\Notifications\RemovedTopicPresentationModel;
use MediaWiki\Extension\DiscussionTools\Notifications\SubscribedNewCommentPresentationModel;
use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook;
use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook;
use MediaWiki\Extension\Notifications\Hooks\EchoGetEventsForRevisionHook;
use MediaWiki\Extension\Notifications\Model\Event;
use MediaWiki\Revision\RevisionRecord;
use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
class EchoHooks implements
BeforeCreateEchoEventHook,
EchoGetBundleRulesHook,
EchoGetEventsForRevisionHook
{
/**
* Add notification events to Echo
*/
public function onBeforeCreateEchoEvent(
array &$notifications,
array &$notificationCategories,
array &$icons
) {
// The following messages are generated upstream
// * echo-category-title-dt-subscription
$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' => [
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ]
],
// Exclude mentioned users and talk page owner from our notification, to avoid
// duplicate notifications for a single comment
'user-filters' => [
[
[ EchoUserLocator::class, 'locateFromEventExtra' ],
[ 'mentioned-users' ]
],
[ [ EchoUserLocator::class, 'locateTalkPageOwner' ] ],
],
'presentation-model' => SubscribedNewCommentPresentationModel::class,
'bundle' => [
'web' => true,
'email' => true,
'expandable' => true,
],
];
// The following messages are generated upstream
// * echo-category-title-dt-subscription-archiving
$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' => [
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ]
],
'presentation-model' => RemovedTopicPresentationModel::class,
'bundle' => [
'web' => true,
'email' => true,
'expandable' => true,
],
];
$notifications['dt-added-topic'] = [
'category' => 'dt-subscription',
'group' => 'interactive',
'section' => 'message',
'user-locators' => [
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ]
],
'presentation-model' => AddedTopicPresentationModel::class,
'bundle' => [
'web' => true,
'email' => true,
'expandable' => true,
],
];
// Override default handlers
$notifications['edit-user-talk']['presentation-model'] = EnhancedEchoEditUserTalkPresentationModel::class;
$notifications['mention']['presentation-model'] = EnhancedEchoMentionPresentationModel::class;
}
public function onEchoGetBundleRules( Event $event, string &$bundleString ) {
switch ( $event->getType() ) {
case 'dt-subscribed-new-comment':
$bundleString = $event->getType() . '-' . $event->getExtraParam( 'subscribed-comment-name' );
break;
case 'dt-added-topic':
case 'dt-removed-topic':
$bundleString = $event->getType() . '-' . $event->getTitle()->getNamespace()
. '-' . $event->getTitle()->getDBkey();
break;
}
}
/**
* @throws ResourceLimitExceededException
*/
public function onEchoGetEventsForRevision( array &$events, RevisionRecord $revision, bool $isRevert ) {
if ( $isRevert ) {
return;
}
EventDispatcher::generateEventsForRevision( $events, $revision );
}
}