jenkins-bot has submitted this change and it was merged.
Change subject: Move hooks into separate file and class
......................................................................
Move hooks into separate file and class
Change-Id: Ib5dea16456f243662b95d757b1938d237fa9b087
---
A googleAnalytics.hooks.php
M googleAnalytics.php
2 files changed, 63 insertions(+), 54 deletions(-)
Approvals:
DavisNT: Looks good to me, but someone else must approve
Addshore: Looks good to me, approved
jenkins-bot: Verified
diff --git a/googleAnalytics.hooks.php b/googleAnalytics.hooks.php
new file mode 100644
index 0000000..dfd90a5
--- /dev/null
+++ b/googleAnalytics.hooks.php
@@ -0,0 +1,61 @@
+<?php
+
+class GoogleAnalyticsHooks {
+ /**
+ * @param Skin $skin
+ * @param string $text
+ * @return bool
+ */
+ public static function onSkinAfterBottomScripts( Skin $skin, &$text =
'' ) {
+ global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsOtherCode,
$wgGoogleAnalyticsIgnoreNsIDs,
+ $wgGoogleAnalyticsIgnorePages,
$wgGoogleAnalyticsIgnoreSpecials;
+
+ if ( $skin->getUser()->isAllowed( 'noanalytics' ) ) {
+ $text .= "<!-- Web analytics code inclusion is disabled
for this user. -->\r\n";
+ return true;
+ }
+
+ if ( count( array_filter( $wgGoogleAnalyticsIgnoreSpecials,
function ( $v ) use ( $skin ) {
+ return $skin->getTitle()->isSpecial( $v );
+ } ) ) > 0
+ || in_array( $skin->getTitle()->getNamespace(),
$wgGoogleAnalyticsIgnoreNsIDs, true )
+ || in_array( $skin->getTitle()->getPrefixedText(),
$wgGoogleAnalyticsIgnorePages, true ) ) {
+ $text .= "<!-- Web analytics code inclusion is disabled
for this page. -->\r\n";
+ return true;
+ }
+
+ $appended = false;
+
+ if ( $wgGoogleAnalyticsAccount !== '' ) {
+ $text .= <<<EOD
+<script>
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+
+ ga('create', '
+EOD
+. $wgGoogleAnalyticsAccount . <<<EOD
+', 'auto');
+ ga('send', 'pageview');
+
+</script>
+
+EOD;
+ $appended = true;
+ }
+
+ if ( $wgGoogleAnalyticsOtherCode !== '' ) {
+ $text .= $wgGoogleAnalyticsOtherCode . "\r\n";
+ $appended = true;
+ }
+
+ if ( !$appended ) {
+ $text .= "<!-- No web analytics configured. -->\r\n";
+ }
+
+ return true;
+ }
+
+}
diff --git a/googleAnalytics.php b/googleAnalytics.php
index b365057..2085ae5 100644
--- a/googleAnalytics.php
+++ b/googleAnalytics.php
@@ -40,57 +40,5 @@
/*****************************/
-
-$wgHooks['SkinAfterBottomScripts'][] = 'wfUniversalAnalyticsIntegrationSABS';
-
-function wfUniversalAnalyticsIntegrationSABS( $skin, &$text = '' ) {
- global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsOtherCode,
$wgGoogleAnalyticsIgnoreNsIDs,
- $wgGoogleAnalyticsIgnorePages,
$wgGoogleAnalyticsIgnoreSpecials;
-
- if ( $skin->getUser()->isAllowed( 'noanalytics' ) ) {
- $text .= "<!-- Web analytics code inclusion is disabled for
this user. -->\r\n";
- return true;
- }
-
- if ( count( array_filter( $wgGoogleAnalyticsIgnoreSpecials, function (
$v ) use ( $skin ) {
- return $skin->getTitle()->isSpecial( $v );
- } ) ) > 0
- || in_array( $skin->getTitle()->getNamespace(),
$wgGoogleAnalyticsIgnoreNsIDs, true )
- || in_array( $skin->getTitle()->getPrefixedText(),
$wgGoogleAnalyticsIgnorePages, true ) ) {
- $text .= "<!-- Web analytics code inclusion is disabled for
this page. -->\r\n";
- return true;
- }
-
- $appended = false;
-
- if ( $wgGoogleAnalyticsAccount !== '' ) {
- $text .= <<<EOD
-<script>
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
-
- ga('create', '
-EOD
-. $wgGoogleAnalyticsAccount . <<<EOD
-', 'auto');
- ga('send', 'pageview');
-
-</script>
-
-EOD;
- $appended = true;
- }
-
- if ( $wgGoogleAnalyticsOtherCode !== '' ) {
- $text .= $wgGoogleAnalyticsOtherCode . "\r\n";
- $appended = true;
- }
-
- if ( !$appended ) {
- $text .= "<!-- No web analytics configured. -->\r\n";
- }
-
- return true;
-}
+$wgAutoloadClasses['GoogleAnalyticsHooks'] = __DIR__ .
'/googleAnalytics.hooks.php';
+$wgHooks['SkinAfterBottomScripts'][] =
'GoogleAnalyticsHooks::onSkinAfterBottomScripts';
--
To view, visit https://gerrit.wikimedia.org/r/185791
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib5dea16456f243662b95d757b1938d237fa9b087
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/googleAnalytics
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: DavisNT <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
Gerrit-Reviewer: tosfos <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits