mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
3dc5e88842
Changes to the use statements done automatically via script Addition of missing use statement done manually Change-Id: I492ddae3c3e9f81d551ea8b348b7148893f4f590
70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* DiscussionTools hooks for listening to our own hooks
|
|
*
|
|
* @file
|
|
* @ingroup Extensions
|
|
* @license MIT
|
|
*/
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
|
|
|
use ExtensionRegistry;
|
|
use MediaWiki\Context\IContextSource;
|
|
use MediaWiki\Extension\DiscussionTools\OverflowMenuItem;
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\User\UserNameUtils;
|
|
|
|
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
|
|
) {
|
|
if (
|
|
( $threadItemData['type'] ?? null ) === 'heading' &&
|
|
!( $threadItemData['uneditableSection'] ?? false ) &&
|
|
$contextSource->getSkin()->getSkinName() === 'minerva'
|
|
) {
|
|
$overflowMenuItems[] = new OverflowMenuItem(
|
|
'edit',
|
|
'edit',
|
|
$contextSource->msg( 'skin-view-edit' ),
|
|
2
|
|
);
|
|
}
|
|
|
|
$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' ),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|