r29194 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29193‎ | r29194 | r29195 >
Date:21:17, 2 January 2008
Author:tlaqua
Status:old
Tags:
Comment:
* Removed backwards compatibility
* Switched variable names - see new installation instructions on mw.org
* Added $wgGoogleAnalyticsIgnoreSysops
* Added $wgGoogleAnalyticsIgnoreBots
* Initialized all variables properly
Modified paths:
  • /trunk/extensions/googleAnalytics/googleAnalytics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/googleAnalytics/googleAnalytics.php
@@ -8,53 +8,38 @@
99 'url'=>'http://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration',
1010 'author'=>'Tim Laqua',
1111 'description'=>'Inserts Google Analytics script (ga.js) in to MediaWiki pages for tracking.',
12 - 'version'=>'1.3'
 12+ 'version'=>'2.0'
1313 );
1414
15 -if( version_compare( $wgVersion, '1.11alpha', '>=' ) ) {
16 - $wgHooks['SkinAfterBottomScripts'][] = 'efGoogleAnalyticsHookText';
17 -} else {
18 - $wgHooks['MonoBookTemplateToolboxEnd'][] = 'efGoogleAnalyticsHookEcho';
19 - $wgHooks['BeforePageDisplay'][] = 'efGoogleAnalyticsHookOut';
20 -}
 15+$wgHooks['SkinAfterBottomScripts'][] = 'efGoogleAnalyticsHookText';
2116
 17+$wgGoogleAnalyticsAccount = "";
 18+$wgGoogleAnalyticsIgnoreSysops = true;
 19+$wgGoogleAnalyticsIgnoreBots = true;
 20+
2221 function efGoogleAnalyticsHookText(&$skin, &$text='') {
2322 $text .= efAddGoogleAnalytics();
2423 return true;
2524 }
2625
27 -function efGoogleAnalyticsHookEcho(&$out) {
28 - global $googleAnalyticsMonobook;
29 - if ($googleAnalyticsMonobook)
30 - echo(efAddGoogleAnalytics());
31 - return true;
32 -}
33 -
34 -function efGoogleAnalyticsHookOut(&$out) {
35 - global $googleAnalyticsMonobook;
36 - if (!$googleAnalyticsMonobook)
37 - $out->addHTML(efAddGoogleAnalytics());
38 - return true;
39 -}
40 -
4126 function efAddGoogleAnalytics() {
42 - global $googleAnalytics, $wgUser;
43 - if (!$wgUser->isAllowed('bot')) {
44 - if (!$wgUser->isAllowed('protect')) {
45 - if ($googleAnalytics) {
 27+ global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser;
 28+ if (!$wgUser->isAllowed('bot') || !$wgGoogleAnalyticsIgnoreBots) {
 29+ if (!$wgUser->isAllowed('protect') || !$wgGoogleAnalyticsIgnoreSysops) {
 30+ if ( !empty($wgGoogleAnalyticsAccount) ) {
4631 $funcOutput = <<<GASCRIPT
4732 <script type="text/javascript">
4833 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
4934 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
5035 </script>
5136 <script type="text/javascript">
52 -var pageTracker = _gat._getTracker("{$googleAnalytics}");
 37+var pageTracker = _gat._getTracker("{$wgGoogleAnalyticsAccount}");
5338 pageTracker._initData();
5439 pageTracker._trackPageview();
5540 </script>
5641 GASCRIPT;
5742 } else {
58 - $funcOutput = "\n<!-- Set \$googleAnalytics to your uacct # provided by Google Analytics. -->";
 43+ $funcOutput = "\n<!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. -->";
5944 }
6045 } else {
6146 $funcOutput = "\n<!-- Google Analytics tracking is disabled for users with 'protect' rights (I.E. sysops) -->";

Status & tagging log