2023-09-28 11:00:36 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DiscussionTools hooks for listening to our own hooks
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
|
|
|
|
2024-07-03 15:00:54 +00:00
|
|
|
use MediaWiki\Config\Config;
|
|
|
|
use MediaWiki\Config\ConfigFactory;
|
2024-06-08 22:02:35 +00:00
|
|
|
use MediaWiki\Context\IContextSource;
|
2023-09-28 11:00:36 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\OverflowMenuItem;
|
2024-10-19 21:39:18 +00:00
|
|
|
use MediaWiki\Registration\ExtensionRegistry;
|
2022-01-09 00:50:22 +00:00
|
|
|
use MediaWiki\User\UserNameUtils;
|
2023-09-28 11:00:36 +00:00
|
|
|
|
|
|
|
class DiscussionToolsHooks implements
|
|
|
|
DiscussionToolsAddOverflowMenuItemsHook
|
|
|
|
{
|
2024-07-03 15:00:54 +00:00
|
|
|
private Config $config;
|
|
|
|
private UserNameUtils $userNameUtils;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
ConfigFactory $configFactory,
|
|
|
|
UserNameUtils $userNameUtils
|
|
|
|
) {
|
|
|
|
$this->config = $configFactory->makeConfig( 'discussiontools' );
|
|
|
|
$this->userNameUtils = $userNameUtils;
|
|
|
|
}
|
2023-09-28 11:00:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param OverflowMenuItem[] &$overflowMenuItems
|
|
|
|
* @param string[] &$resourceLoaderModules
|
|
|
|
* @param array $threadItemData
|
|
|
|
* @param IContextSource $contextSource
|
|
|
|
* @return bool|void
|
|
|
|
*/
|
|
|
|
public function onDiscussionToolsAddOverflowMenuItems(
|
|
|
|
array &$overflowMenuItems,
|
|
|
|
array &$resourceLoaderModules,
|
|
|
|
array $threadItemData,
|
|
|
|
IContextSource $contextSource
|
|
|
|
) {
|
2023-10-11 15:53:55 +00:00
|
|
|
if (
|
|
|
|
( $threadItemData['type'] ?? null ) === 'heading' &&
|
|
|
|
!( $threadItemData['uneditableSection'] ?? false ) &&
|
|
|
|
$contextSource->getSkin()->getSkinName() === 'minerva'
|
|
|
|
) {
|
2023-09-28 11:00:36 +00:00
|
|
|
$overflowMenuItems[] = new OverflowMenuItem(
|
|
|
|
'edit',
|
|
|
|
'edit',
|
|
|
|
$contextSource->msg( 'skin-view-edit' ),
|
|
|
|
2
|
|
|
|
);
|
|
|
|
}
|
2022-01-09 00:50:22 +00:00
|
|
|
|
2024-07-03 15:00:54 +00:00
|
|
|
if ( $this->config->get( 'DiscussionToolsEnableThanks' ) ) {
|
2022-01-09 00:50:22 +00:00
|
|
|
$user = $contextSource->getUser();
|
|
|
|
$showThanks = ExtensionRegistry::getInstance()->isLoaded( 'Thanks' );
|
|
|
|
if ( $showThanks && ( $threadItemData['type'] ?? null ) === 'comment' && $user->isNamed() ) {
|
2024-07-03 15:00:54 +00:00
|
|
|
$recipient = $this->userNameUtils->getCanonical( $threadItemData['author'], UserNameUtils::RIGOR_NONE );
|
2022-01-09 00:50:22 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
$recipient !== $user->getName() &&
|
2024-07-03 15:00:54 +00:00
|
|
|
!$this->userNameUtils->isIP( $recipient )
|
2022-01-09 00:50:22 +00:00
|
|
|
) {
|
|
|
|
$overflowMenuItems[] = new OverflowMenuItem(
|
|
|
|
'thank',
|
|
|
|
'heart',
|
|
|
|
$contextSource->msg( 'thanks-button-thank' ),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-28 11:00:36 +00:00
|
|
|
}
|
|
|
|
}
|