r104431 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104430‎ | r104431 | r104432 >
Date:14:45, 28 November 2011
Author:petrb
Status:deferred
Tags:
Comment:
style and some minor fixes
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
@@ -32,11 +32,11 @@
3333 * @return true
3434 */
3535 public static function setCache( $user, $values, $type, $time = null ) {
36 - global $wgOnlineStatusBarWriteTime, $wgMemc;
 36+ global $wgOnlineStatusBar_WriteTime, $wgMemc;
3737 // get a key
3838 $cache_key = self::getCacheKey( $user, $type );
3939 if ( $time === null ) {
40 - $time = $wgOnlineStatusBarWriteTime;
 40+ $time = $wgOnlineStatusBar_WriteTime;
4141 }
4242 $wgMemc->set( $cache_key, $values, $time );
4343 return true;
@@ -44,6 +44,8 @@
4545
4646 /**
4747 * Return cache value
 48+ * @param $user string
 49+ * @param $type string
4850 */
4951 public static function getCache( $user, $type ) {
5052 global $wgMemc;
@@ -55,6 +57,7 @@
5658
5759
5860 /**
 61+ * Status check
5962 * @param $user User
6063 * @return String
6164 */
@@ -186,7 +189,8 @@
187190 }
188191
189192 /**
190 - * Delete old records from the table, this function is called frequently too keep it as small as possible
 193+ * Delete old records from the table, this function is called frequently to keep the table it as small as possible
 194+ * it's also possible to disable this function to set automatic job in cron to do that
191195 * @return int
192196 */
193197 public static function deleteOld() {
@@ -197,9 +201,10 @@
198202 if ( self::getCache( 'null', 'delete' ) == 'true' ) {
199203 return 0;
200204 }
201 - $dbw = wfGetDB( DB_MASTER );
202 - $t_time = OnlineStatusBar::getTimeoutDate();
203 - $result = $dbw->selectField( 'online_status', 'timestamp', array( "timestamp < " . $dbw->addQuotes( $dbw->timestamp( $t_time ) ) ),
 205+ // Check if we actually need to delete something before we write to master
 206+ $dbr = wfGetDB( DB_SLAVE );
 207+ $time = OnlineStatusBar::getTimeoutDate();
 208+ $result = $dbr->selectField( 'online_status', 'timestamp', array( "timestamp < " . $dbr->addQuotes( $dbr->timestamp( $time ) ) ),
204209 __METHOD__, array( 'LIMIT 1' ) );
205210 if ( $result === false ) {
206211 // no need for delete
@@ -207,7 +212,7 @@
208213 }
209214
210215 // calculate time and convert it back to mediawiki format
211 - $time = OnlineStatusBar::getTimeoutDate();
 216+ $dbw = wfGetDB( DB_MASTER );
212217 $dbw->delete( 'online_status', array( "timestamp < " . $dbw->addQuotes( $dbw->timestamp( $time ) ) ), __METHOD__ );
213218 self::setCache( 'null', 'true', 'delete', 3600 ); // remember we deleted it for 1 hour so that we avoid calling this too many times
214219 return 0;
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -16,7 +16,10 @@
1717 */
1818
1919 class OnlineStatusBar {
20 -
 20+ /**
 21+ * Create a html bar
 22+ * @param $text
 23+ **/
2124 public static function getStatusBarHtml( $text ) {
2225 return <<<HTML
2326 <div class="onlinestatusbarbody metadata onlinestatusbartop" id="status-top">
@@ -129,6 +132,9 @@
130133
131134
132135 /**
 136+ * @param $delayed
 137+ * @param $away
 138+ * @param $user
133139 * @return timestamp
134140 */
135141 public static function getTimeoutDate( $delayed = false, $away = false, $user = false ) {
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -88,11 +88,11 @@
8989 // Configuration
9090 // Those values can be overriden in LocalSettings, do not change it here
9191 $wgOnlineStatusBarIcon = array(
92 - 'online' => "statusgreen.png",
93 - 'busy' => "statusorange.png",
94 - 'away' => "statusorange.png",
95 - 'hidden' => "statusred.png",
96 - 'offline' => "statusred.png",
 92+ 'online' => 'statusgreen.png',
 93+ 'busy' => 'statusorange.png',
 94+ 'away' => 'statusorange.png',
 95+ 'hidden' => 'statusred.png',
 96+ 'offline' => 'statusred.png',
9797 );
9898
9999 // default for anonymous and uknown users
@@ -102,9 +102,9 @@
103103 // delay between db updates
104104 $wgOnlineStatusBar_WriteTime = 300;
105105 // default for online
106 -$wgOnlineStatusBarDefaultOnline = "online";
 106+$wgOnlineStatusBarDefaultOnline = 'online';
107107 // default for offline
108 -$wgOnlineStatusBarDefaultOffline = "offline";
 108+$wgOnlineStatusBarDefaultOffline = 'offline';
109109 // if users have this feature enabled by default
110110 $wgOnlineStatusBarDefaultEnabled = false;
111111 // how long to wait until user is considered as offline

Status & tagging log