diff --git a/CHANGELOG.md b/CHANGELOG.md index 04998cb..ed7525e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## ChangeLog for MatomoAnalytics +### 1.1.0 (29-01-2023) +* Ensure matomo script isn't added more than once +* Require MediaWiki 1.39.0 + ### 1.0.9 (12-01-2023) * Replace deprecated wfGetDB() diff --git a/extension.json b/extension.json index 47cd30c..246555f 100644 --- a/extension.json +++ b/extension.json @@ -6,12 +6,12 @@ "Universal Omega" ], "url": "https://github.com/miraheze/MatomoAnalytics", - "version": "1.0.9", + "version": "1.1.0", "descriptionmsg": "matomoanalytics-desc", "license-name": "GPL-3.0-or-later", "type": "specialpage", "requires": { - "MediaWiki": ">= 1.38.0" + "MediaWiki": ">= 1.39.0" }, "AvailableRights": [ "noanalytics" diff --git a/includes/MatomoAnalyticsHooks.php b/includes/MatomoAnalyticsHooks.php index a3f7b92..04ef98a 100644 --- a/includes/MatomoAnalyticsHooks.php +++ b/includes/MatomoAnalyticsHooks.php @@ -35,12 +35,14 @@ public static function wikiRename( $dbw, $old, $new ) { public static function matomoScript( $skin, &$text = '' ) { $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'matomoanalytics' ); - // Check if JS tracking is disabled and bow out early - if ( $config->get( 'MatomoAnalyticsDisableJS' ) === true ) { + static $alreadyDone = false; + + // Check if JS tracking is disabled or if the script has already been added and bow out early + if ( $alreadyDone || $config->get( 'MatomoAnalyticsDisableJS' ) ) { return true; } - $user = RequestContext::getMain()->getUser(); + $user = $skin->getUser(); $mAId = MatomoAnalytics::getSiteID( $config->get( 'DBname' ) ); $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); @@ -56,7 +58,7 @@ public static function matomoScript( $skin, &$text = '' ) { $jstitle = Xml::encodeJsVar( $title->getPrefixedText() ); $dbname = Xml::encodeJsVar( $config->get( 'DBname' ) ); $urltitle = $title->getPrefixedURL(); - $userType = $user->isRegistered() ? "User" : "Anonymous"; + $userType = $user->isRegistered() ? 'User' : 'Anonymous'; $cookieDisable = (int)$config->get( 'MatomoAnalyticsDisableCookie' ); $forceGetRequest = (int)$config->get( 'MatomoAnalyticsForceGetRequest' ); $text .= <<