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;
|
|
|
|
|
2022-01-09 00:50:22 +00:00
|
|
|
use ExtensionRegistry;
|
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;
|
2022-01-09 00:50:22 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use MediaWiki\User\UserNameUtils;
|
2023-09-28 11:00:36 +00:00
|
|
|
|
|
|
|
class DiscussionToolsHooks implements
|
|
|
|
DiscussionToolsAddOverflowMenuItemsHook
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
|
|
|
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'discussiontools' );
|
|
|
|
if ( $dtConfig->get( 'DiscussionToolsEnableThanks' ) ) {
|
|
|
|
$user = $contextSource->getUser();
|
|
|
|
$showThanks = ExtensionRegistry::getInstance()->isLoaded( 'Thanks' );
|
|
|
|
if ( $showThanks && ( $threadItemData['type'] ?? null ) === 'comment' && $user->isNamed() ) {
|
|
|
|
$userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
|
|
|
|
$recipient = $userNameUtils->getCanonical( $threadItemData['author'], UserNameUtils::RIGOR_NONE );
|
|
|
|
|
|
|
|
if (
|
|
|
|
$recipient !== $user->getName() &&
|
|
|
|
!$userNameUtils->isIP( $recipient )
|
|
|
|
) {
|
|
|
|
$overflowMenuItems[] = new OverflowMenuItem(
|
|
|
|
'thank',
|
|
|
|
'heart',
|
|
|
|
$contextSource->msg( 'thanks-button-thank' ),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-28 11:00:36 +00:00
|
|
|
}
|
|
|
|
}
|