diff --git a/.phan/config.php b/.phan/config.php index 70a6827c..766f4cfe 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -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', ] diff --git a/extension.json b/extension.json index 4d91b75e..9ccb6835 100644 --- a/extension.json +++ b/extension.json @@ -38,6 +38,9 @@ "MainConfig", "UserEditTracker", "UserOptionsLookup" + ], + "optional_services": [ + "MobileFrontend.Context" ] } }, diff --git a/includes/Hooks.php b/includes/Hooks.php index 31d001ce..ef40ab6e 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -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; }