Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DiscussionToolsHooks | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onDiscussionToolsAddOverflowMenuItems | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
90 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * DiscussionTools hooks for listening to our own hooks |
| 4 | * |
| 5 | * @file |
| 6 | * @ingroup Extensions |
| 7 | * @license MIT |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\Extension\DiscussionTools\Hooks; |
| 11 | |
| 12 | use MediaWiki\Config\Config; |
| 13 | use MediaWiki\Config\ConfigFactory; |
| 14 | use MediaWiki\Context\IContextSource; |
| 15 | use MediaWiki\Extension\DiscussionTools\OverflowMenuItem; |
| 16 | use MediaWiki\Registration\ExtensionRegistry; |
| 17 | use MediaWiki\User\Options\UserOptionsLookup; |
| 18 | use MediaWiki\User\UserNameUtils; |
| 19 | |
| 20 | class DiscussionToolsHooks implements |
| 21 | DiscussionToolsAddOverflowMenuItemsHook |
| 22 | { |
| 23 | private readonly Config $config; |
| 24 | |
| 25 | public function __construct( |
| 26 | ConfigFactory $configFactory, |
| 27 | private readonly UserNameUtils $userNameUtils, |
| 28 | private readonly UserOptionsLookup $userOptionsLookup, |
| 29 | ) { |
| 30 | $this->config = $configFactory->makeConfig( 'discussiontools' ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param OverflowMenuItem[] &$overflowMenuItems |
| 35 | * @param string[] &$resourceLoaderModules |
| 36 | * @param array $threadItemData |
| 37 | * @param IContextSource $contextSource |
| 38 | * @return bool|void |
| 39 | */ |
| 40 | public function onDiscussionToolsAddOverflowMenuItems( |
| 41 | array &$overflowMenuItems, |
| 42 | array &$resourceLoaderModules, |
| 43 | array $threadItemData, |
| 44 | IContextSource $contextSource |
| 45 | ) { |
| 46 | if ( |
| 47 | ( $threadItemData['type'] ?? null ) === 'heading' && |
| 48 | !( $threadItemData['uneditableSection'] ?? false ) && |
| 49 | $contextSource->getSkin()->getSkinName() === 'minerva' |
| 50 | ) { |
| 51 | $overflowMenuItems[] = new OverflowMenuItem( |
| 52 | 'edit', |
| 53 | 'edit', |
| 54 | 'skin-view-edit', |
| 55 | 2 |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | $user = $contextSource->getUser(); |
| 60 | $showThanks = ExtensionRegistry::getInstance()->isLoaded( 'Thanks' ); |
| 61 | if ( $showThanks && ( $threadItemData['type'] ?? null ) === 'comment' && $user->isNamed() ) { |
| 62 | $recipient = $this->userNameUtils->getCanonical( $threadItemData['author'], UserNameUtils::RIGOR_NONE ); |
| 63 | |
| 64 | if ( |
| 65 | $recipient !== $user->getName() && |
| 66 | !$this->userNameUtils->isIP( $recipient ) |
| 67 | ) { |
| 68 | $overflowMenuItems[] = new OverflowMenuItem( |
| 69 | 'thank', |
| 70 | 'heart', |
| 71 | 'thanks-button-thank' |
| 72 | ); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |