diff --git a/src/Hooks.php b/src/Hooks.php index 1c30658..0385f43 100644 --- a/src/Hooks.php +++ b/src/Hooks.php @@ -2,6 +2,9 @@ namespace MediaWiki\Extension\Matomo; +use RequestContext; +use Xml; + class Hooks { /** @var string|null Searched term in Special:Search. */ @@ -80,20 +83,19 @@ public static function onSpecialSearchSetupEngine( $search, $profile, $engine ) * @return string */ public static function addMatomo( $title ) { - global $wgUser; - + $user = RequestContext::getMain()->getUser(); // Is Matomo disabled for bots? - if ( $wgUser->isAllowed( 'bot' ) && self::getParameter( 'IgnoreBots' ) ) { + if ( $user->isAllowed( 'bot' ) && self::getParameter( 'IgnoreBots' ) ) { return ''; } // Ignore Wiki System Operators - if ( $wgUser->isAllowed( 'protect' ) && self::getParameter( 'IgnoreSysops' ) ) { + if ( $user->isAllowed( 'protect' ) && self::getParameter( 'IgnoreSysops' ) ) { return ''; } // Ignore Wiki Editors - if ( $wgUser->isAllowed( 'edit' ) && self::getParameter( 'IgnoreEditors' ) ) { + if ( $user->isAllowed( 'edit' ) && self::getParameter( 'IgnoreEditors' ) ) { return ""; } @@ -168,8 +170,8 @@ public static function addMatomo( $title ) { // Track username based on https://matomo.org/docs/user-id/ The user // name for anonymous visitors is their IP address which Matomo already // records. - if ( self::getParameter( 'TrackUsernames' ) && $wgUser->isLoggedIn() ) { - $username = Xml::encodeJsVar( $wgUser->getName() ); + if ( self::getParameter( 'TrackUsernames' ) && $user->isLoggedIn() ) { + $username = Xml::encodeJsVar( $user->getName() ); $customJs .= PHP_EOL . " _paq.push([\"setUserId\",{$username}]);"; }