Merge "Inject 'Popups.Logger' into PopupsHooks"

This commit is contained in:
jenkins-bot 2024-03-21 22:30:10 +00:00 committed by Gerrit Code Review
commit fc9c41ee05
4 changed files with 19 additions and 15 deletions

View file

@ -32,6 +32,7 @@
"services": [
"Popups.Config",
"Popups.Context",
"Popups.Logger",
"UserOptionsManager"
]
}

View file

@ -22,7 +22,6 @@ namespace Popups;
use ExtensionRegistry;
use MediaWiki\Config\Config;
use MediaWiki\MediaWikiServices;
use MediaWiki\SpecialPage\SpecialPageFactory;
use MediaWiki\Title\Title;
use MediaWiki\User\Options\UserOptionsLookup;
@ -242,13 +241,4 @@ class PopupsContext {
}
return false;
}
/**
* Get module logger
*
* @return \Psr\Log\LoggerInterface
*/
public function getLogger() {
return MediaWikiServices::getInstance()->getService( 'Popups.Logger' );
}
}

View file

@ -32,6 +32,7 @@ use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
use MediaWiki\User\Hook\UserGetDefaultOptionsHook;
use MediaWiki\User\Options\UserOptionsManager;
use MediaWiki\User\User;
use Psr\Log\LoggerInterface;
use Skin;
/**
@ -56,21 +57,27 @@ class PopupsHooks implements
/** @var PopupsContext */
private $popupsContext;
/** @var LoggerInterface */
private $logger;
/** @var UserOptionsManager */
private $userOptionsManager;
/**
* @param Config $config
* @param PopupsContext $popupsContext
* @param LoggerInterface $logger
* @param UserOptionsManager $userOptionsManager
*/
public function __construct(
Config $config,
PopupsContext $popupsContext,
LoggerInterface $logger,
UserOptionsManager $userOptionsManager
) {
$this->config = $config;
$this->popupsContext = $popupsContext;
$this->logger = $logger;
$this->userOptionsManager = $userOptionsManager;
}
@ -196,8 +203,7 @@ class PopupsHooks implements
}
if ( !$this->popupsContext->areDependenciesMet() ) {
$logger = $this->popupsContext->getLogger();
$logger->error( 'Popups requires the PageImages extensions.
$this->logger->error( 'Popups requires the PageImages extensions.
TextExtracts extension is required when using mwApiPlain gateway.' );
return;
}

View file

@ -50,6 +50,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
( new PopupsHooks(
new HashConfig(),
$contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager()
) )
->onGetPreferences( $this->createMock( User::class ), $prefs );
@ -82,6 +83,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
'PopupsReferencePreviews' => $enabled,
] ),
$contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager()
) )
->onGetPreferences( $userMock, $prefs );
@ -122,6 +124,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
'PopupsReferencePreviews' => $enabled,
] ),
$contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager()
) )
->onGetPreferences( $this->createMock( User::class ), $prefs );
@ -161,6 +164,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
'PopupsReferencePreviews' => $enabled,
] ),
$contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager()
) )
->onGetPreferences( $this->createMock( User::class ), $prefs );
@ -189,6 +193,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
( new PopupsHooks(
new HashConfig( $config ),
$this->getServiceContainer()->getService( 'Popups.Context' ),
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager()
) )
->onResourceLoaderGetConfigVars( $vars, '', new MultiConfig( $config ) );
@ -222,13 +227,11 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
$contextMock->expects( $this->once() )
->method( 'isTitleExcluded' )
->willReturn( false );
$contextMock->expects( $this->once() )
->method( 'getLogger' )
->willReturn( $loggerMock );
( new PopupsHooks(
new HashConfig(),
$contextMock,
$loggerMock,
$this->getServiceContainer()->getUserOptionsManager()
) )
->onBeforePageDisplay( $outPageMock, $skinMock );
@ -278,6 +281,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
( new PopupsHooks(
new HashConfig(),
$contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager()
) )
->onBeforePageDisplay( $outPageMock, $skinMock );
@ -302,6 +306,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
( new PopupsHooks(
new HashConfig(),
$contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager()
) )
->onMakeGlobalVariablesScript( $vars, $outputPage );
@ -326,6 +331,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
'PopupsReferencePreviews' => $enabled,
] ),
$this->getServiceContainer()->getService( 'Popups.Context' ),
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager()
) )
->onUserGetDefaultOptions( $userOptions );
@ -365,6 +371,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
'PopupsReferencePreviews' => $enabled,
] ),
$this->getServiceContainer()->getService( 'Popups.Context' ),
$this->getServiceContainer()->getService( 'Popups.Logger' ),
$userOptionsManagerMock
) )
->onLocalUserCreated( $userMock, false );