mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-18 02:51:26 +00:00
Inject services into DiscussionToolsHooks
Change-Id: If15fd7cca27832ed8ff6738c90556be701be269f
This commit is contained in:
parent
11ef3a577d
commit
b06b96b915
|
@ -484,7 +484,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"discussiontools": {
|
"discussiontools": {
|
||||||
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\DiscussionToolsHooks"
|
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\DiscussionToolsHooks",
|
||||||
|
"services": [
|
||||||
|
"ConfigFactory",
|
||||||
|
"UserNameUtils"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"tags": {
|
"tags": {
|
||||||
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\TagHooks"
|
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\TagHooks"
|
||||||
|
|
|
@ -10,14 +10,25 @@
|
||||||
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
||||||
|
|
||||||
use ExtensionRegistry;
|
use ExtensionRegistry;
|
||||||
|
use MediaWiki\Config\Config;
|
||||||
|
use MediaWiki\Config\ConfigFactory;
|
||||||
use MediaWiki\Context\IContextSource;
|
use MediaWiki\Context\IContextSource;
|
||||||
use MediaWiki\Extension\DiscussionTools\OverflowMenuItem;
|
use MediaWiki\Extension\DiscussionTools\OverflowMenuItem;
|
||||||
use MediaWiki\MediaWikiServices;
|
|
||||||
use MediaWiki\User\UserNameUtils;
|
use MediaWiki\User\UserNameUtils;
|
||||||
|
|
||||||
class DiscussionToolsHooks implements
|
class DiscussionToolsHooks implements
|
||||||
DiscussionToolsAddOverflowMenuItemsHook
|
DiscussionToolsAddOverflowMenuItemsHook
|
||||||
{
|
{
|
||||||
|
private Config $config;
|
||||||
|
private UserNameUtils $userNameUtils;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
ConfigFactory $configFactory,
|
||||||
|
UserNameUtils $userNameUtils
|
||||||
|
) {
|
||||||
|
$this->config = $configFactory->makeConfig( 'discussiontools' );
|
||||||
|
$this->userNameUtils = $userNameUtils;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param OverflowMenuItem[] &$overflowMenuItems
|
* @param OverflowMenuItem[] &$overflowMenuItems
|
||||||
|
@ -45,17 +56,15 @@ class DiscussionToolsHooks implements
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'discussiontools' );
|
if ( $this->config->get( 'DiscussionToolsEnableThanks' ) ) {
|
||||||
if ( $dtConfig->get( 'DiscussionToolsEnableThanks' ) ) {
|
|
||||||
$user = $contextSource->getUser();
|
$user = $contextSource->getUser();
|
||||||
$showThanks = ExtensionRegistry::getInstance()->isLoaded( 'Thanks' );
|
$showThanks = ExtensionRegistry::getInstance()->isLoaded( 'Thanks' );
|
||||||
if ( $showThanks && ( $threadItemData['type'] ?? null ) === 'comment' && $user->isNamed() ) {
|
if ( $showThanks && ( $threadItemData['type'] ?? null ) === 'comment' && $user->isNamed() ) {
|
||||||
$userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
|
$recipient = $this->userNameUtils->getCanonical( $threadItemData['author'], UserNameUtils::RIGOR_NONE );
|
||||||
$recipient = $userNameUtils->getCanonical( $threadItemData['author'], UserNameUtils::RIGOR_NONE );
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$recipient !== $user->getName() &&
|
$recipient !== $user->getName() &&
|
||||||
!$userNameUtils->isIP( $recipient )
|
!$this->userNameUtils->isIP( $recipient )
|
||||||
) {
|
) {
|
||||||
$overflowMenuItems[] = new OverflowMenuItem(
|
$overflowMenuItems[] = new OverflowMenuItem(
|
||||||
'thank',
|
'thank',
|
||||||
|
|
Loading…
Reference in a new issue