Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -15,31 +15,35 @@ |
16 | 16 | */ |
17 | 17 | |
18 | 18 | class OnlineStatusBar { |
19 | | - private static function GetNow() |
20 | | - { |
21 | | - return gmdate( 'Ymdhis', time() ); |
22 | | - } |
23 | 19 | |
24 | 20 | public static function Get_Html( $text, $mode ) |
25 | 21 | { |
26 | | - global $wgOnlineStatusBarModes, $wgOnlineStatusBarIcon, $wgOnlineStatusBarColor, $wgOnlineStatusBarY; |
27 | | - $icon = "$wgExtensionAssetsPath/OnlineStatusBar/{$wgOnlineStatusBarModes[$mode]}"; |
| 22 | + global $wgOnlineStatusBarColor, $wgOnlineStatusBarY; |
28 | 23 | $color = $wgOnlineStatusBarColor[$mode]; |
29 | | - return '<div style="right:0px; margin-top:-10px;" class="metadata topicon" id="status-top"><div style="border: 0px solid black; background: transparent; float: right; position: relative; top:' . $wgOnlineStatusBarY . 'px; padding: 5px"><p><b>' . $text . ': <span style="color: ' . $color . '; font:bold;"><img alt=' . $text . " - " . $mode . ' src="' . $wgOnlineStatusBarIcon[$mode] . '" width="20" height="20" />' . $icon . '</span></b></p></div></div>'; |
| 24 | + return <<<HTML |
| 25 | +<div style="right:0px; margin-top:-10px;" class="metadata topicon" id="status-top"> |
| 26 | +<div style="border: 0px solid black; background: transparent; float: right; position: relative; top: {$wgOnlineStatusBarY}px; padding: 5px"> |
| 27 | +$text</div></div> |
| 28 | +HTML; |
30 | 29 | } |
| 30 | + public static function GetImageHtml( $mode ) { |
| 31 | + global $wgExtensionAssetsPath, $wgOnlineStatusBarIcon, $wgOnlineStatusBarModes; |
| 32 | + $icon = "$wgExtensionAssetsPath/OnlineStatusBar/{$wgOnlineStatusBarIcon[$mode]}"; |
| 33 | + $modeText = $wgOnlineStatusBarModes[$mode]; |
| 34 | + return Html::element( 'img', array( 'src' => $icon ) ); |
| 35 | + } |
31 | 36 | |
32 | 37 | static function UpdateDb() |
33 | 38 | { |
34 | | - global $wgUser; |
35 | | - // FIXME: GetStatus needs a user id |
36 | | - if ( OnlineStatusBar::GetStatus( $wgUser->getID() ) != $OnlineStatusBar->DefaultOnline ) |
| 39 | + global $wgUser, $wgOnlineStatusBarDefaultOnline; |
| 40 | + if ( OnlineStatusBar::GetStatus( $wgUser->getID() ) != $wgOnlineStatusBarDefaultOnline ) |
37 | 41 | { |
38 | 42 | $dbw = wfGetDB( DB_MASTER ); |
39 | 43 | $now = OnlineStatusBar::GetNow(); |
40 | 44 | $row = array( |
41 | 45 | 'userid' => $wgUser->getID(), |
42 | 46 | 'username' => $wgUser->getName(), |
43 | | - 'timestamp' => $now, |
| 47 | + 'timestamp' => $dbw->timestamp( wfTimestamp() ), |
44 | 48 | ); |
45 | 49 | $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' ); |
46 | 50 | } |
— | — | @@ -51,14 +55,18 @@ |
52 | 56 | { |
53 | 57 | global $wgUser, $wgOnlineStatusBarDefaultOffline; |
54 | 58 | $now = OnlineStatusBar::GetNow(); |
55 | | - // FIXME: GetStatus needs a user id |
56 | | - if ( OnlineStatusBar::GetStatus() == $wgOnlineStatusBarDefaultOffline ) |
| 59 | + if ( OnlineStatusBar::GetStatus( $wgUser->getId() ) == $wgOnlineStatusBarDefaultOffline ) |
57 | 60 | { |
58 | 61 | OnlineStatusBar::UpdateDb(); |
59 | 62 | return true; |
60 | 63 | } |
61 | 64 | $dbw = wfGetDB( DB_MASTER ); |
62 | | - $dbw->update( 'online_status', array ( 'timestamp' => $now ), array ( 'username' => $wgUser->getName() ), __METHOD__ ); |
| 65 | + $dbw->update( |
| 66 | + 'online_status', |
| 67 | + array( 'timestamp' => $dbw->timestamp( wfTimestamp() ) ), |
| 68 | + array( 'username' => $wgUser->getID() ), |
| 69 | + __METHOD__ |
| 70 | + ); |
63 | 71 | |
64 | 72 | return false; |
65 | 73 | |
— | — | @@ -68,8 +76,9 @@ |
69 | 77 | { |
70 | 78 | global $wgOnlineStatusBar_LogoutTime, $wgDBname; |
71 | 79 | $dbw = wfGetDB( DB_MASTER ); |
72 | | - $time = OnlineStatusBar::GetNow() - $wgOnlineStatusBar_LogoutTime; |
73 | | - $dbw->delete( 'online_status', array( 'timestamp < "' . $time . '"' ) , __METHOD__ ); |
| 80 | + $time = wfTimestamp( TS_UNIX ) - $wgOnlineStatusBar_LogoutTime; |
| 81 | + $time = $dbw->addQuotes( $dbw->timestamp( $time ) ); |
| 82 | + $dbw->delete( 'online_status', array( "timestamp < $time" ) , __METHOD__ ); |
74 | 83 | return 0; |
75 | 84 | } |
76 | 85 | |
— | — | @@ -77,8 +86,8 @@ |
78 | 87 | global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname; |
79 | 88 | $dbw = wfGetDB( DB_MASTER ); |
80 | 89 | OnlineStatusBar::DeleteOld(); |
81 | | - $result = $dbw->select( 'online_status', array( 'userid', 'username', 'timestamp' ), array( 'username' => $userID ), __METHOD__, array( 'limit 1', 'order by timestamp desc' ) ); |
82 | | - if ( $result->numRows() > 0 ) |
| 90 | + $result = $dbw->selectField( 'online_status', 'userid', array( 'userid' => $userID ), __METHOD__, array( 'limit 1', 'order by timestamp desc' ) ); |
| 91 | + if ( $result ) |
83 | 92 | { |
84 | 93 | return $wgOnlineStatusBarDefaultOnline; |
85 | 94 | } |
— | — | @@ -86,10 +95,10 @@ |
87 | 96 | return $wgOnlineStatusBarDefaultOffline; |
88 | 97 | } |
89 | 98 | |
90 | | - static function DeleteStatus( $user ) |
| 99 | + static function DeleteStatus( $userId ) |
91 | 100 | { |
92 | 101 | $dbw = wfGetDB ( DB_MASTER ); |
93 | | - $dbw->delete( 'online_status', array( 'username' => $user ), __METHOD__ ); // delete user |
| 102 | + $dbw->delete( 'online_status', array( 'userid' => $userId ), __METHOD__ ); // delete user |
94 | 103 | return true; |
95 | 104 | } |
96 | 105 | } |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php |
— | — | @@ -14,5 +14,5 @@ |
15 | 15 | */ |
16 | 16 | $messages['en'] = array( |
17 | 17 | 'onlinestatusbar-desc' => "Status bar which shows whether a user is online, based on preferences, on their user page", |
18 | | - 'onlinestatusbar-line' => " is now", |
| 18 | + 'onlinestatusbar-line' => "$1 is now $2 $3", |
19 | 19 | ); |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php |
— | — | @@ -82,8 +82,7 @@ |
83 | 83 | $wgHooks['UserLogoutComplete'][] = 'wfOnlineStatusBar_Logout'; |
84 | 84 | function wfOnlineStatusBar_Logout( &$user, &$inject_html, $old_name ) |
85 | 85 | { |
86 | | - global $wgUser; |
87 | | - OnlineStatusBar::DeleteStatus( $old_name ); |
| 86 | + OnlineStatusBar::DeleteStatus( $user->getId() ); |
88 | 87 | return true; |
89 | 88 | } |
90 | 89 | |
— | — | @@ -97,9 +96,12 @@ |
98 | 97 | { |
99 | 98 | // better way to get a username would be great :) |
100 | 99 | $user = preg_replace( '/\/.*/', '', preg_replace( '/^.*\:/', "", $article->getTitle() ) ); |
101 | | - $OnlineStatus_Text = $user . language::getMessageFromDB( "onlinestatusbar-line" ); |
102 | | - $OnlineStatus_Mode = OnlineStatusBar::GetStatus( $user ); |
103 | | - $wgOut->addHtml( OnlineStatusBar::Get_Html( $OnlineStatus_Text, $OnlineStatus_Mode ) ); |
| 100 | + |
| 101 | + $mode = OnlineStatusBar::GetStatus( $user ); |
| 102 | + $modetext = $wgOnlineStatusBarModes[$mode]; |
| 103 | + $image = OnlineStatusBar::getImageHtml( $mode ); |
| 104 | + $text = wfMessage( 'onlinestatusbar-line', $user )->rawParams( $image )->params( $modetext )->escaped(); |
| 105 | + $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) ); |
104 | 106 | } |
105 | 107 | return true; |
106 | 108 | } |