Skip to content

Commit

Permalink
Merge pull request #37 from mnival/master
Browse files Browse the repository at this point in the history
  • Loading branch information
DaSchTour authored Jan 2, 2022
2 parents fddd9b8 + ef4f898 commit 3e9bd0c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace MediaWiki\Extension\Matomo;

use RequestContext;
use Xml;

class Hooks {

/** @var string|null Searched term in Special:Search. */
Expand Down Expand Up @@ -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 '<!-- Matomo extension is disabled for bots -->';
}

// Ignore Wiki System Operators
if ( $wgUser->isAllowed( 'protect' ) && self::getParameter( 'IgnoreSysops' ) ) {
if ( $user->isAllowed( 'protect' ) && self::getParameter( 'IgnoreSysops' ) ) {
return '<!-- Matomo tracking is disabled for users with \'protect\' rights (i.e., sysops) -->';
}

// Ignore Wiki Editors
if ( $wgUser->isAllowed( 'edit' ) && self::getParameter( 'IgnoreEditors' ) ) {
if ( $user->isAllowed( 'edit' ) && self::getParameter( 'IgnoreEditors' ) ) {
return "<!-- Matomo tracking is disabled for users with 'edit' rights -->";
}

Expand Down Expand Up @@ -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}]);";
}

Expand Down

0 comments on commit 3e9bd0c

Please sign in to comment.