| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
namespace MediaWiki\Extension\DiscussionTools\Hooks; |
| 11 |
|
| 12 |
use MediaWiki\Extension\DiscussionTools\Notifications\AddedTopicPresentationModel; |
| 13 |
use MediaWiki\Extension\DiscussionTools\Notifications\CommentThanksPresentationModel; |
| 14 |
use MediaWiki\Extension\DiscussionTools\Notifications\EnhancedEchoEditUserTalkPresentationModel; |
| 15 |
use MediaWiki\Extension\DiscussionTools\Notifications\EnhancedEchoMentionPresentationModel; |
| 16 |
use MediaWiki\Extension\DiscussionTools\Notifications\EventDispatcher; |
| 17 |
use MediaWiki\Extension\DiscussionTools\Notifications\RemovedTopicPresentationModel; |
| 18 |
use MediaWiki\Extension\DiscussionTools\Notifications\SubscribedNewCommentPresentationModel; |
| 19 |
use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook; |
| 20 |
use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook; |
| 21 |
use MediaWiki\Extension\Notifications\Hooks\EchoGetEventsForRevisionHook; |
| 22 |
use MediaWiki\Extension\Notifications\Model\Event; |
| 23 |
use MediaWiki\Extension\Notifications\UserLocator; |
| 24 |
use MediaWiki\Registration\ExtensionRegistry; |
| 25 |
use MediaWiki\Revision\RevisionRecord; |
| 26 |
use Wikimedia\Parsoid\Core\ResourceLimitExceededException; |
| 27 |
|
| 28 |
class EchoHooks implements |
| 29 |
BeforeCreateEchoEventHook, |
| 30 |
EchoGetBundleRulesHook, |
| 31 |
EchoGetEventsForRevisionHook |
| 32 |
{ |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public function onBeforeCreateEchoEvent( |
| 37 |
array &$notifications, |
| 38 |
array &$notificationCategories, |
| 39 |
array &$icons |
| 40 |
) { |
| 41 |
|
| 42 |
|
| 43 |
$notificationCategories['dt-subscription'] = [ |
| 44 |
'priority' => 3, |
| 45 |
'tooltip' => 'echo-pref-tooltip-dt-subscription', |
| 46 |
]; |
| 47 |
$notifications['dt-subscribed-new-comment'] = [ |
| 48 |
'category' => 'dt-subscription', |
| 49 |
'group' => 'interactive', |
| 50 |
'section' => 'message', |
| 51 |
'user-locators' => [ |
| 52 |
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ] |
| 53 |
], |
| 54 |
|
| 55 |
|
| 56 |
'user-filters' => [ |
| 57 |
[ |
| 58 |
[ UserLocator::class, 'locateFromEventExtra' ], |
| 59 |
[ 'mentioned-users' ] |
| 60 |
], |
| 61 |
[ [ UserLocator::class, 'locateTalkPageOwner' ] ], |
| 62 |
], |
| 63 |
'presentation-model' => SubscribedNewCommentPresentationModel::class, |
| 64 |
'bundle' => [ |
| 65 |
'web' => true, |
| 66 |
'email' => true, |
| 67 |
'expandable' => true, |
| 68 |
], |
| 69 |
]; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
$notificationCategories['dt-subscription-archiving'] = [ |
| 74 |
'priority' => 3, |
| 75 |
'tooltip' => 'echo-pref-tooltip-dt-subscription-archiving', |
| 76 |
]; |
| 77 |
$notifications['dt-removed-topic'] = [ |
| 78 |
'category' => 'dt-subscription-archiving', |
| 79 |
'group' => 'interactive', |
| 80 |
'section' => 'message', |
| 81 |
'user-locators' => [ |
| 82 |
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ] |
| 83 |
], |
| 84 |
'presentation-model' => RemovedTopicPresentationModel::class, |
| 85 |
'bundle' => [ |
| 86 |
'web' => true, |
| 87 |
'email' => true, |
| 88 |
'expandable' => true, |
| 89 |
], |
| 90 |
]; |
| 91 |
$notifications['dt-added-topic'] = [ |
| 92 |
'category' => 'dt-subscription', |
| 93 |
'group' => 'interactive', |
| 94 |
'section' => 'message', |
| 95 |
'user-locators' => [ |
| 96 |
[ [ EventDispatcher::class, 'locateSubscribedUsers' ] ] |
| 97 |
], |
| 98 |
'presentation-model' => AddedTopicPresentationModel::class, |
| 99 |
'bundle' => [ |
| 100 |
'web' => true, |
| 101 |
'email' => true, |
| 102 |
'expandable' => true, |
| 103 |
], |
| 104 |
]; |
| 105 |
|
| 106 |
if ( ExtensionRegistry::getInstance()->isLoaded( 'Thanks' ) ) { |
| 107 |
$notifications['dt-thank'] = [ |
| 108 |
'category' => 'edit-thank', |
| 109 |
'group' => 'positive', |
| 110 |
'section' => 'message', |
| 111 |
'user-locators' => [ |
| 112 |
[ |
| 113 |
[ UserLocator::class, 'locateFromEventExtra' ], |
| 114 |
[ 'thanked-user-id' ] |
| 115 |
] |
| 116 |
], |
| 117 |
'presentation-model' => CommentThanksPresentationModel::class, |
| 118 |
'bundle' => [ |
| 119 |
'web' => true, |
| 120 |
'expandable' => true, |
| 121 |
], |
| 122 |
]; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
$notifications['edit-user-talk']['presentation-model'] = EnhancedEchoEditUserTalkPresentationModel::class; |
| 127 |
$notifications['mention']['presentation-model'] = EnhancedEchoMentionPresentationModel::class; |
| 128 |
} |
| 129 |
|
| 130 |
public function onEchoGetBundleRules( Event $event, string &$bundleString ) { |
| 131 |
switch ( $event->getType() ) { |
| 132 |
case 'dt-subscribed-new-comment': |
| 133 |
$bundleString = $event->getType() . '-' . $event->getExtraParam( 'subscribed-comment-name' ); |
| 134 |
break; |
| 135 |
case 'dt-added-topic': |
| 136 |
case 'dt-removed-topic': |
| 137 |
$bundleString = $event->getType() . '-' . $event->getTitle()->getNamespace() |
| 138 |
. '-' . $event->getTitle()->getDBkey(); |
| 139 |
break; |
| 140 |
case 'dt-thank': |
| 141 |
$bundleString = $event->getType() . '-' . $event->getExtraParam( 'comment-name' ); |
| 142 |
break; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public function onEchoGetEventsForRevision( array &$events, RevisionRecord $revision, bool $isRevert ) { |
| 150 |
if ( $isRevert ) { |
| 151 |
return; |
| 152 |
} |
| 153 |
EventDispatcher::generateEventsForRevision( $events, $revision ); |
| 154 |
} |
| 155 |
} |