Index: trunk/extensions/googleAnalytics/googleAnalytics.php |
— | — | @@ -8,53 +8,38 @@ |
9 | 9 | 'url'=>'http://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration', |
10 | 10 | 'author'=>'Tim Laqua', |
11 | 11 | 'description'=>'Inserts Google Analytics script (ga.js) in to MediaWiki pages for tracking.', |
12 | | - 'version'=>'1.3' |
| 12 | + 'version'=>'2.0' |
13 | 13 | ); |
14 | 14 | |
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'; |
21 | 16 | |
| 17 | +$wgGoogleAnalyticsAccount = ""; |
| 18 | +$wgGoogleAnalyticsIgnoreSysops = true; |
| 19 | +$wgGoogleAnalyticsIgnoreBots = true; |
| 20 | + |
22 | 21 | function efGoogleAnalyticsHookText(&$skin, &$text='') { |
23 | 22 | $text .= efAddGoogleAnalytics(); |
24 | 23 | return true; |
25 | 24 | } |
26 | 25 | |
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 | | - |
41 | 26 | 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) ) { |
46 | 31 | $funcOutput = <<<GASCRIPT |
47 | 32 | <script type="text/javascript"> |
48 | 33 | var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
49 | 34 | document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
50 | 35 | </script> |
51 | 36 | <script type="text/javascript"> |
52 | | -var pageTracker = _gat._getTracker("{$googleAnalytics}"); |
| 37 | +var pageTracker = _gat._getTracker("{$wgGoogleAnalyticsAccount}"); |
53 | 38 | pageTracker._initData(); |
54 | 39 | pageTracker._trackPageview(); |
55 | 40 | </script> |
56 | 41 | GASCRIPT; |
57 | 42 | } 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. -->"; |
59 | 44 | } |
60 | 45 | } else { |
61 | 46 | $funcOutput = "\n<!-- Google Analytics tracking is disabled for users with 'protect' rights (I.E. sysops) -->"; |