r104560 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104559‎ | r104560 | r104561 >
Date:12:59, 29 November 2011
Author:petrb
Status:deferred (Comments)
Tags:
Comment:
rewriten function with constants it looks better although it does the same
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.status.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.status.php
@@ -90,7 +90,7 @@
9191 // cache it
9292 self::setCache( $user->getName(), $result, ONLINESTATUSBAR_DELAYED_CACHE );
9393 }
94 - $w_time = OnlineStatusBar::getTimeoutDate( true );
 94+ $w_time = OnlineStatusBar::getTimeoutDate( ONLINESTATUSBAR_CK_DELAYED );
9595 }
9696
9797 if ( $result === false ) {
@@ -105,7 +105,7 @@
106106 $status = 'write';
107107 }
108108 } else if ( $user->getOption( 'OnlineStatusBar_away', true ) == true ) {
109 - if ( $result < wfTimestamp( TS_MW, OnlineStatusBar::getTimeoutDate( false, true, $user ) ) ) {
 109+ if ( $result < wfTimestamp( TS_MW, OnlineStatusBar::getTimeoutDate( ONLINESTATUSBAR_CK_AWAY, $user ) ) ) {
110110 $status = 'away';
111111 }
112112 }
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -133,22 +133,22 @@
134134 * @param $user
135135 * @return timestamp
136136 */
137 - public static function getTimeoutDate( $delayed = false, $away = false, $user = false ) {
 137+ public static function getTimeoutDate( $checkType = false, $user = false ) {
138138 global $wgOnlineStatusBar_AwayTime, $wgOnlineStatusBar_WriteTime, $wgOnlineStatusBar_LogoutTime;
139139
140 - if ($away) {
141 - if ( $user === false ) {
142 - $time = $wgOnlineStatusBar_AwayTime;
143 - }else{
144 - $time = $user->getOption( 'OnlineStatusBar_awaytime', $wgOnlineStatusBar_AwayTime );
145 - }
146 - return wfTimestamp( TS_UNIX ) - ( $time * 60 );
 140+ if ($checkType != false) {
 141+ switch($checkType) {
 142+ case ONLINESTATUSBAR_CK_DELAYED:
 143+ return wfTimestamp( TS_UNIX ) - $wgOnlineStatusBar_WriteTime;
 144+ case ONLINESTATUSBAR_CK_AWAY:
 145+ if ( $user === false ) {
 146+ $time = $wgOnlineStatusBar_AwayTime;
 147+ } else {
 148+ $time = $user->getOption( 'OnlineStatusBar_awaytime', $wgOnlineStatusBar_AwayTime );
 149+ }
 150+ return wfTimestamp( TS_UNIX ) - ( $time * 60 );
 151+ }
147152 }
148 -
149 - if ($delayed) {
150 - return wfTimestamp( TS_UNIX ) - $wgOnlineStatusBar_WriteTime;
151 - }
152 -
153153 return wfTimestamp( TS_UNIX ) - $wgOnlineStatusBar_LogoutTime;
154154 }
155155
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -98,6 +98,9 @@
9999 // For memcached
100100 define( 'ONLINESTATUSBAR_DELAYED_CACHE', 'd' );
101101 define( 'ONLINESTATUSBAR_NORMAL_CACHE', 'n' );
 102+// Timeout
 103+define( 'ONLINESTATUSBAR_CK_DELAYED', 1 );
 104+define( 'ONLINESTATUSBAR_CK_AWAY', 2 );
102105
103106 // default for anonymous and uknown users
104107 $wgOnlineStatusBarTrackIpUsers = false;

Comments

#Comment by Bawolff (talk | contribs)   19:46, 30 November 2011

Another possibility might be to make them class constants instead of global constants (Both ways are probably fine though, more a matter of preference)

Status & tagging log