Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
Use globals in MediaWikiServicesHook (#5)
Browse files Browse the repository at this point in the history
To avoid "Deprecated: Premature access to service 'MainConfig'"
  • Loading branch information
lens0021 authored Oct 23, 2021
1 parent f514680 commit 3b116ee
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Hooks/MediaWikiServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace MediaWiki\Extension\PageViewInfoGA\Hooks;

use MediaWiki\Extension\PageViewInfoGA\Constants;
use MediaWiki\Extension\PageViewInfoGA\GoogleAnalyticsPageViewService;
use MediaWiki\Extensions\PageViewInfo\CachedPageViewService;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices as MediaWikiMediaWikiServices;
use ObjectCache;

class MediaWikiServices implements \MediaWiki\Hook\MediaWikiServicesHook {
Expand All @@ -15,17 +13,22 @@ class MediaWikiServices implements \MediaWiki\Hook\MediaWikiServicesHook {
* @inheritDoc
*/
public function onMediaWikiServices( $services ) {
$config = MediaWikiMediaWikiServices::getInstance()->getMainConfig();
$profileId = $config->get( Constants::CONFIG_KEY_PROFILE_ID );
global $wgPageViewInfoGAProfileId,
$wgPageViewInfoGACredentialsFile,
$wgPageViewInfoGAWriteCustomMap,
$wgPageViewInfoGAReadCustomDimensions,
$wgPageViewApiMaxDays;

$profileId = $wgPageViewInfoGAProfileId;
if ( !$profileId ) {
return;
}
$credentialsFile = $config->get( Constants::CONFIG_KEY_CREDENTIALS_FILE );
$customMap = $config->get( Constants::CONFIG_KEY_CUSTOM_MAP );
$readCustomDimensions = $config->get( Constants::CONFIG_KEY_READ_CUSTOM_DIMENSIONS );
$credentialsFile = $wgPageViewInfoGACredentialsFile;
$customMap = $wgPageViewInfoGAWriteCustomMap;
$readCustomDimensions = $wgPageViewInfoGAReadCustomDimensions;
$cache = ObjectCache::getLocalClusterInstance();
$logger = LoggerFactory::getInstance( 'PageViewInfoGA' );
$cachedDays = max( 30, $config->get( 'PageViewApiMaxDays' ) );
$cachedDays = max( 30, $wgPageViewApiMaxDays );

$services->redefineService(
'PageViewService',
Expand Down

0 comments on commit 3b116ee

Please sign in to comment.