Merge "Replace global variables by inject MainConfig"

This commit is contained in:
jenkins-bot 2023-10-23 21:17:39 +00:00 committed by Gerrit Code Review
commit 6ce10b6597
3 changed files with 15 additions and 14 deletions

View file

@ -425,6 +425,7 @@
"main": { "main": {
"class": "MediaWiki\\Extension\\MultimediaViewer\\Hooks", "class": "MediaWiki\\Extension\\MultimediaViewer\\Hooks",
"services": [ "services": [
"MainConfig",
"SpecialPageFactory", "SpecialPageFactory",
"UserOptionsLookup" "UserOptionsLookup"
] ]

View file

@ -63,17 +63,21 @@ class Hooks implements
protected static $helpLink = protected static $helpLink =
'https://mediawiki.org/wiki/Special:MyLanguage/Help:Extension:Media_Viewer'; 'https://mediawiki.org/wiki/Special:MyLanguage/Help:Extension:Media_Viewer';
private Config $config;
private SpecialPageFactory $specialPageFactory; private SpecialPageFactory $specialPageFactory;
private UserOptionsLookup $userOptionsLookup; private UserOptionsLookup $userOptionsLookup;
/** /**
* @param Config $config
* @param SpecialPageFactory $specialPageFactory * @param SpecialPageFactory $specialPageFactory
* @param UserOptionsLookup $userOptionsLookup * @param UserOptionsLookup $userOptionsLookup
*/ */
public function __construct( public function __construct(
Config $config,
SpecialPageFactory $specialPageFactory, SpecialPageFactory $specialPageFactory,
UserOptionsLookup $userOptionsLookup UserOptionsLookup $userOptionsLookup
) { ) {
$this->config = $config;
$this->specialPageFactory = $specialPageFactory; $this->specialPageFactory = $specialPageFactory;
$this->userOptionsLookup = $userOptionsLookup; $this->userOptionsLookup = $userOptionsLookup;
} }
@ -83,9 +87,7 @@ class Hooks implements
* @param array &$defaultOptions * @param array &$defaultOptions
*/ */
public function onUserGetDefaultOptions( &$defaultOptions ) { public function onUserGetDefaultOptions( &$defaultOptions ) {
global $wgMediaViewerEnableByDefault; if ( $this->config->get( 'MediaViewerEnableByDefault' ) ) {
if ( $wgMediaViewerEnableByDefault ) {
$defaultOptions['multimediaviewer-enable'] = 1; $defaultOptions['multimediaviewer-enable'] = 1;
} }
} }
@ -96,14 +98,14 @@ class Hooks implements
* @return bool * @return bool
*/ */
protected function shouldHandleClicks( User $performer ): bool { protected function shouldHandleClicks( User $performer ): bool {
global $wgMediaViewerEnableByDefaultForAnonymous,
$wgMediaViewerEnableByDefault;
if ( $performer->isNamed() ) { if ( $performer->isNamed() ) {
return (bool)$this->userOptionsLookup->getOption( $performer, 'multimediaviewer-enable' ); return (bool)$this->userOptionsLookup->getOption( $performer, 'multimediaviewer-enable' );
} }
return (bool)( $wgMediaViewerEnableByDefaultForAnonymous ?? $wgMediaViewerEnableByDefault ); return (bool)(
$this->config->get( 'MediaViewerEnableByDefaultForAnonymous' ) ??
$this->config->get( 'MediaViewerEnableByDefault' )
);
} }
/** /**
@ -184,17 +186,14 @@ class Hooks implements
* @param Config $config * @param Config $config
*/ */
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void { public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
global $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerExtensions,
$wgMediaViewerImageQueryParameter, $wgMediaViewerRecordVirtualViewBeaconURI;
$vars['wgMultimediaViewer'] = [ $vars['wgMultimediaViewer'] = [
'infoLink' => self::$infoLink, 'infoLink' => self::$infoLink,
'discussionLink' => self::$discussionLink, 'discussionLink' => self::$discussionLink,
'helpLink' => self::$helpLink, 'helpLink' => self::$helpLink,
'useThumbnailGuessing' => (bool)$wgMediaViewerUseThumbnailGuessing, 'useThumbnailGuessing' => (bool)$this->config->get( 'MediaViewerUseThumbnailGuessing' ),
'imageQueryParameter' => $wgMediaViewerImageQueryParameter, 'imageQueryParameter' => $this->config->get( 'MediaViewerImageQueryParameter' ),
'recordVirtualViewBeaconURI' => $wgMediaViewerRecordVirtualViewBeaconURI, 'recordVirtualViewBeaconURI' => $this->config->get( 'MediaViewerRecordVirtualViewBeaconURI' ),
'extensions' => $wgMediaViewerExtensions, 'extensions' => $this->config->get( 'MediaViewerExtensions' ),
]; ];
$vars['wgMediaViewer'] = true; $vars['wgMediaViewer'] = true;
} }

View file

@ -15,6 +15,7 @@ class HooksTest extends MediaWikiIntegrationTestCase {
public function newHooksInstance() { public function newHooksInstance() {
return new Hooks( return new Hooks(
$this->getServiceContainer()->getMainConfig(),
$this->getServiceContainer()->getSpecialPageFactory(), $this->getServiceContainer()->getSpecialPageFactory(),
$this->getServiceContainer()->getUserOptionsLookup() $this->getServiceContainer()->getUserOptionsLookup()
); );