| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Thanks; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Notifications\AttributeManager; |
| 6 |
use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook; |
| 7 |
use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook; |
| 8 |
use MediaWiki\Extension\Notifications\Model\Event; |
| 9 |
use MediaWiki\Extension\Notifications\UserLocator; |
| 10 |
use MediaWiki\Registration\ExtensionRegistry; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class EchoHooks implements BeforeCreateEchoEventHook, EchoGetBundleRulesHook { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public function onBeforeCreateEchoEvent( |
| 28 |
array &$notifications, array &$notificationCategories, array &$icons |
| 29 |
) { |
| 30 |
$notificationCategories['edit-thank'] = [ |
| 31 |
'priority' => 3, |
| 32 |
'tooltip' => 'echo-pref-tooltip-edit-thank', |
| 33 |
]; |
| 34 |
|
| 35 |
$notifications['edit-thank'] = [ |
| 36 |
|
| 37 |
|
| 38 |
'category' => 'edit-thank', |
| 39 |
'group' => 'positive', |
| 40 |
'section' => 'message', |
| 41 |
'presentation-model' => EchoCoreThanksPresentationModel::class, |
| 42 |
'bundle' => [ |
| 43 |
'web' => true, |
| 44 |
'expandable' => true, |
| 45 |
], |
| 46 |
AttributeManager::ATTR_LOCATORS => [ |
| 47 |
[ |
| 48 |
[ UserLocator::class, 'locateFromEventExtra' ], |
| 49 |
[ 'thanked-user-id' ] |
| 50 |
], |
| 51 |
], |
| 52 |
]; |
| 53 |
|
| 54 |
if ( ExtensionRegistry::getInstance()->isLoaded( 'Flow' ) ) { |
| 55 |
$notifications['flow-thank'] = [ |
| 56 |
'category' => 'edit-thank', |
| 57 |
'group' => 'positive', |
| 58 |
'section' => 'message', |
| 59 |
'presentation-model' => EchoFlowThanksPresentationModel::class, |
| 60 |
'bundle' => [ |
| 61 |
'web' => true, |
| 62 |
'expandable' => true, |
| 63 |
], |
| 64 |
AttributeManager::ATTR_LOCATORS => [ |
| 65 |
[ |
| 66 |
[ UserLocator::class, 'locateFromEventExtra' ], |
| 67 |
[ 'thanked-user-id' ] |
| 68 |
], |
| 69 |
], |
| 70 |
]; |
| 71 |
} |
| 72 |
|
| 73 |
$icons['thanks'] = [ |
| 74 |
'path' => [ |
| 75 |
'ltr' => 'Thanks/modules/userTalk-constructive-ltr.svg', |
| 76 |
'rtl' => 'Thanks/modules/userTalk-constructive-rtl.svg' |
| 77 |
] |
| 78 |
]; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function onEchoGetBundleRules( Event $event, string &$bundleString ) { |
| 88 |
switch ( $event->getType() ) { |
| 89 |
case 'edit-thank': |
| 90 |
$bundleString = 'edit-thank'; |
| 91 |
|
| 92 |
$revOrLogId = $event->getExtraParam( 'logid' ); |
| 93 |
if ( $revOrLogId ) { |
| 94 |
|
| 95 |
$revOrLogId = 'log' . $revOrLogId; |
| 96 |
} else { |
| 97 |
$revOrLogId = $event->getExtraParam( 'revid' ); |
| 98 |
} |
| 99 |
if ( $revOrLogId ) { |
| 100 |
$bundleString .= $revOrLogId; |
| 101 |
} |
| 102 |
break; |
| 103 |
case 'flow-thank': |
| 104 |
$bundleString = 'flow-thank'; |
| 105 |
$postId = $event->getExtraParam( 'post-id' ); |
| 106 |
if ( $postId ) { |
| 107 |
$bundleString .= $postId; |
| 108 |
} |
| 109 |
break; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
} |