r105602 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105601‎ | r105602 | r105603 >
Date:22:43, 8 December 2011
Author:reedy
Status:ok
Tags:
Comment:
Invert if statements with returns to reduce nesting
Modified paths:
  • /trunk/extensions/googleAnalytics/googleAnalytics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/googleAnalytics/googleAnalytics.php
@@ -32,17 +32,26 @@
3333 return true;
3434 }
3535
36 -function efGoogleAnalyticsHookText($skin, &$text='') {
 36+function efGoogleAnalyticsHookText( $skin, &$text='' ) {
3737 $text .= efAddGoogleAnalytics();
3838 return true;
3939 }
4040
4141 function efAddGoogleAnalytics() {
4242 global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser;
43 - if (!$wgUser->isAllowed('bot') || !$wgGoogleAnalyticsIgnoreBots) {
44 - if (!$wgUser->isAllowed('protect') || !$wgGoogleAnalyticsIgnoreSysops) {
45 - if ( !empty($wgGoogleAnalyticsAccount) ) {
46 - $funcOutput = <<<GASCRIPT
 43+ if ( $wgUser->isAllowed( 'bot' ) && $wgGoogleAnalyticsIgnoreBots ) {
 44+ return "\n<!-- Google Analytics tracking is disabled for bots -->";
 45+ }
 46+
 47+ if ( $wgUser->isAllowed( 'protect' ) && $wgGoogleAnalyticsIgnoreSysops ) {
 48+ return "\n<!-- Google Analytics tracking is disabled for users with 'protect' rights (I.E. sysops) -->";
 49+ }
 50+
 51+ if ( $wgGoogleAnalyticsAccount === '' ) {
 52+ return "\n<!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. -->";
 53+ }
 54+
 55+ return <<<HTML
4756 <script type="text/javascript">
4857 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
4958 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
@@ -51,18 +60,7 @@
5261 var pageTracker = _gat._getTracker("{$wgGoogleAnalyticsAccount}");
5362 pageTracker._trackPageview();
5463 </script>
55 -GASCRIPT;
56 - } else {
57 - $funcOutput = "\n<!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. -->";
58 - }
59 - } else {
60 - $funcOutput = "\n<!-- Google Analytics tracking is disabled for users with 'protect' rights (I.E. sysops) -->";
61 - }
62 - } else {
63 - $funcOutput = "\n<!-- Google Analytics tracking is disabled for bots -->";
64 - }
65 -
66 - return $funcOutput;
 64+HTML;
6765 }
6866
6967 ///Alias for efAddGoogleAnalytics - backwards compatibility.

Status & tagging log