mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-17 18:41:01 +00:00
Inject services into DiscussionToolsHooks
Change-Id: If15fd7cca27832ed8ff6738c90556be701be269f
This commit is contained in:
parent
11ef3a577d
commit
b06b96b915
|
@ -484,7 +484,11 @@
|
|||
]
|
||||
},
|
||||
"discussiontools": {
|
||||
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\DiscussionToolsHooks"
|
||||
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\DiscussionToolsHooks",
|
||||
"services": [
|
||||
"ConfigFactory",
|
||||
"UserNameUtils"
|
||||
]
|
||||
},
|
||||
"tags": {
|
||||
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\TagHooks"
|
||||
|
|
|
@ -10,14 +10,25 @@
|
|||
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
||||
|
||||
use ExtensionRegistry;
|
||||
use MediaWiki\Config\Config;
|
||||
use MediaWiki\Config\ConfigFactory;
|
||||
use MediaWiki\Context\IContextSource;
|
||||
use MediaWiki\Extension\DiscussionTools\OverflowMenuItem;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserNameUtils;
|
||||
|
||||
class DiscussionToolsHooks implements
|
||||
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
|
||||
|
@ -45,17 +56,15 @@ class DiscussionToolsHooks implements
|
|||
);
|
||||
}
|
||||
|
||||
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'discussiontools' );
|
||||
if ( $dtConfig->get( 'DiscussionToolsEnableThanks' ) ) {
|
||||
if ( $this->config->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 );
|
||||
$recipient = $this->userNameUtils->getCanonical( $threadItemData['author'], UserNameUtils::RIGOR_NONE );
|
||||
|
||||
if (
|
||||
$recipient !== $user->getName() &&
|
||||
!$userNameUtils->isIP( $recipient )
|
||||
!$this->userNameUtils->isIP( $recipient )
|
||||
) {
|
||||
$overflowMenuItems[] = new OverflowMenuItem(
|
||||
'thank',
|
||||
|
|
Loading…
Reference in a new issue