Use "optional_services" to inject service MobileContext

This change requires a soft dependency on extension MobileFrontend
in project integration/config in file zuul/parameter_functions.py.

Depends-On: Idd55fb06cb166c00817f53287ab17984cae6a7a4
Change-Id: Ia0f6dc59cfac3d201c19bc4a62a5df9590c1ed37
This commit is contained in:
Fomafix 2024-03-13 19:23:52 +00:00
parent 37e032fb8c
commit 9b7ec7ec48
3 changed files with 15 additions and 4 deletions

View file

@ -6,6 +6,7 @@ $cfg['directory_list'] = array_merge(
$cfg['directory_list'],
[
'../../extensions/EventLogging',
'../../extensions/MobileFrontend',
'../../extensions/WikimediaEvents',
'../../extensions/ConfirmEdit',
]
@ -15,6 +16,7 @@ $cfg['exclude_analysis_directory_list'] = array_merge(
$cfg['exclude_analysis_directory_list'],
[
'../../extensions/EventLogging',
'../../extensions/MobileFrontend',
'../../extensions/WikimediaEvents',
'../../extensions/ConfirmEdit',
]

View file

@ -38,6 +38,9 @@
"MainConfig",
"UserEditTracker",
"UserOptionsLookup"
],
"optional_services": [
"MobileFrontend.Context"
]
}
},

View file

@ -38,6 +38,7 @@ use MediaWiki\User\User;
use MediaWiki\User\UserEditTracker;
use MediaWiki\WikiMap\WikiMap;
use MessageLocalizer;
use MobileContext;
use MWCryptRand;
use RecentChange;
use RequestContext;
@ -73,19 +74,25 @@ class Hooks implements
/** @var UserOptionsLookup */
private $userOptionsLookup;
/** @var MobileContext|null */
private ?MobileContext $mobileContext;
/**
* @param Config $config
* @param UserEditTracker $userEditTracker
* @param UserOptionsLookup $userOptionsLookup
* @param MobileContext|null $mobileContext
*/
public function __construct(
Config $config,
UserEditTracker $userEditTracker,
UserOptionsLookup $userOptionsLookup
UserOptionsLookup $userOptionsLookup,
?MobileContext $mobileContext
) {
$this->config = $config;
$this->userEditTracker = $userEditTracker;
$this->userOptionsLookup = $userOptionsLookup;
$this->mobileContext = $mobileContext;
}
/**
@ -130,9 +137,8 @@ class Hooks implements
if ( !$extensionRegistry->isLoaded( 'EventLogging' ) || !$extensionRegistry->isLoaded( 'WikimediaEvents' ) ) {
return;
}
if ( $extensionRegistry->isLoaded( 'MobileFrontend' ) ) {
$mobFrontContext = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' );
if ( $mobFrontContext->shouldDisplayMobileView() ) {
if ( $extensionRegistry->isLoaded( 'MobileFrontend' ) && $this->mobileContext ) {
if ( $this->mobileContext->shouldDisplayMobileView() ) {
// on a MobileFrontend page the logging should be handled by it
return;
}