Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.status.php |
— | — | @@ -32,11 +32,11 @@ |
33 | 33 | * @return true |
34 | 34 | */ |
35 | 35 | public static function setCache( $user, $values, $type, $time = null ) { |
36 | | - global $wgOnlineStatusBarWriteTime, $wgMemc; |
| 36 | + global $wgOnlineStatusBar_WriteTime, $wgMemc; |
37 | 37 | // get a key |
38 | 38 | $cache_key = self::getCacheKey( $user, $type ); |
39 | 39 | if ( $time === null ) { |
40 | | - $time = $wgOnlineStatusBarWriteTime; |
| 40 | + $time = $wgOnlineStatusBar_WriteTime; |
41 | 41 | } |
42 | 42 | $wgMemc->set( $cache_key, $values, $time ); |
43 | 43 | return true; |
— | — | @@ -44,6 +44,8 @@ |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Return cache value |
| 48 | + * @param $user string |
| 49 | + * @param $type string |
48 | 50 | */ |
49 | 51 | public static function getCache( $user, $type ) { |
50 | 52 | global $wgMemc; |
— | — | @@ -55,6 +57,7 @@ |
56 | 58 | |
57 | 59 | |
58 | 60 | /** |
| 61 | + * Status check |
59 | 62 | * @param $user User |
60 | 63 | * @return String |
61 | 64 | */ |
— | — | @@ -186,7 +189,8 @@ |
187 | 190 | } |
188 | 191 | |
189 | 192 | /** |
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 |
191 | 195 | * @return int |
192 | 196 | */ |
193 | 197 | public static function deleteOld() { |
— | — | @@ -197,9 +201,10 @@ |
198 | 202 | if ( self::getCache( 'null', 'delete' ) == 'true' ) { |
199 | 203 | return 0; |
200 | 204 | } |
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 ) ) ), |
204 | 209 | __METHOD__, array( 'LIMIT 1' ) ); |
205 | 210 | if ( $result === false ) { |
206 | 211 | // no need for delete |
— | — | @@ -207,7 +212,7 @@ |
208 | 213 | } |
209 | 214 | |
210 | 215 | // calculate time and convert it back to mediawiki format |
211 | | - $time = OnlineStatusBar::getTimeoutDate(); |
| 216 | + $dbw = wfGetDB( DB_MASTER ); |
212 | 217 | $dbw->delete( 'online_status', array( "timestamp < " . $dbw->addQuotes( $dbw->timestamp( $time ) ) ), __METHOD__ ); |
213 | 218 | self::setCache( 'null', 'true', 'delete', 3600 ); // remember we deleted it for 1 hour so that we avoid calling this too many times |
214 | 219 | return 0; |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -16,7 +16,10 @@ |
17 | 17 | */ |
18 | 18 | |
19 | 19 | class OnlineStatusBar { |
20 | | - |
| 20 | + /** |
| 21 | + * Create a html bar |
| 22 | + * @param $text |
| 23 | + **/ |
21 | 24 | public static function getStatusBarHtml( $text ) { |
22 | 25 | return <<<HTML |
23 | 26 | <div class="onlinestatusbarbody metadata onlinestatusbartop" id="status-top"> |
— | — | @@ -129,6 +132,9 @@ |
130 | 133 | |
131 | 134 | |
132 | 135 | /** |
| 136 | + * @param $delayed |
| 137 | + * @param $away |
| 138 | + * @param $user |
133 | 139 | * @return timestamp |
134 | 140 | */ |
135 | 141 | public static function getTimeoutDate( $delayed = false, $away = false, $user = false ) { |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php |
— | — | @@ -88,11 +88,11 @@ |
89 | 89 | // Configuration |
90 | 90 | // Those values can be overriden in LocalSettings, do not change it here |
91 | 91 | $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', |
97 | 97 | ); |
98 | 98 | |
99 | 99 | // default for anonymous and uknown users |
— | — | @@ -102,9 +102,9 @@ |
103 | 103 | // delay between db updates |
104 | 104 | $wgOnlineStatusBar_WriteTime = 300; |
105 | 105 | // default for online |
106 | | -$wgOnlineStatusBarDefaultOnline = "online"; |
| 106 | +$wgOnlineStatusBarDefaultOnline = 'online'; |
107 | 107 | // default for offline |
108 | | -$wgOnlineStatusBarDefaultOffline = "offline"; |
| 108 | +$wgOnlineStatusBarDefaultOffline = 'offline'; |
109 | 109 | // if users have this feature enabled by default |
110 | 110 | $wgOnlineStatusBarDefaultEnabled = false; |
111 | 111 | // how long to wait until user is considered as offline |