r100545 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100544‎ | r100545 | r100546 >
Date:14:21, 23 October 2011
Author:nikerabbit
Status:deferred (Comments)
Tags:
Comment:
Somewhat working, hopefully I didn't break it too much :)
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -15,31 +15,35 @@
1616 */
1717
1818 class OnlineStatusBar {
19 - private static function GetNow()
20 - {
21 - return gmdate( 'Ymdhis', time() );
22 - }
2319
2420 public static function Get_Html( $text, $mode )
2521 {
26 - global $wgOnlineStatusBarModes, $wgOnlineStatusBarIcon, $wgOnlineStatusBarColor, $wgOnlineStatusBarY;
27 - $icon = "$wgExtensionAssetsPath/OnlineStatusBar/{$wgOnlineStatusBarModes[$mode]}";
 22+ global $wgOnlineStatusBarColor, $wgOnlineStatusBarY;
2823 $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;
3029 }
 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+ }
3136
3237 static function UpdateDb()
3338 {
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 )
3741 {
3842 $dbw = wfGetDB( DB_MASTER );
3943 $now = OnlineStatusBar::GetNow();
4044 $row = array(
4145 'userid' => $wgUser->getID(),
4246 'username' => $wgUser->getName(),
43 - 'timestamp' => $now,
 47+ 'timestamp' => $dbw->timestamp( wfTimestamp() ),
4448 );
4549 $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' );
4650 }
@@ -51,14 +55,18 @@
5256 {
5357 global $wgUser, $wgOnlineStatusBarDefaultOffline;
5458 $now = OnlineStatusBar::GetNow();
55 - // FIXME: GetStatus needs a user id
56 - if ( OnlineStatusBar::GetStatus() == $wgOnlineStatusBarDefaultOffline )
 59+ if ( OnlineStatusBar::GetStatus( $wgUser->getId() ) == $wgOnlineStatusBarDefaultOffline )
5760 {
5861 OnlineStatusBar::UpdateDb();
5962 return true;
6063 }
6164 $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+ );
6371
6472 return false;
6573
@@ -68,8 +76,9 @@
6977 {
7078 global $wgOnlineStatusBar_LogoutTime, $wgDBname;
7179 $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__ );
7483 return 0;
7584 }
7685
@@ -77,8 +86,8 @@
7887 global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname;
7988 $dbw = wfGetDB( DB_MASTER );
8089 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 )
8392 {
8493 return $wgOnlineStatusBarDefaultOnline;
8594 }
@@ -86,10 +95,10 @@
8796 return $wgOnlineStatusBarDefaultOffline;
8897 }
8998
90 - static function DeleteStatus( $user )
 99+ static function DeleteStatus( $userId )
91100 {
92101 $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
94103 return true;
95104 }
96105 }
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php
@@ -14,5 +14,5 @@
1515 */
1616 $messages['en'] = array(
1717 '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",
1919 );
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -82,8 +82,7 @@
8383 $wgHooks['UserLogoutComplete'][] = 'wfOnlineStatusBar_Logout';
8484 function wfOnlineStatusBar_Logout( &$user, &$inject_html, $old_name )
8585 {
86 - global $wgUser;
87 - OnlineStatusBar::DeleteStatus( $old_name );
 86+ OnlineStatusBar::DeleteStatus( $user->getId() );
8887 return true;
8988 }
9089
@@ -97,9 +96,12 @@
9897 {
9998 // better way to get a username would be great :)
10099 $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 ) );
104106 }
105107 return true;
106108 }

Comments

#Comment by Petrb (talk | contribs)   16:18, 23 October 2011

actually it doesn't work now :) probably something wrong with timestamp

#Comment by Siebrand (talk | contribs)   19:45, 28 October 2011
+	'onlinestatusbar-line' => "$1 is now $2 $3",

$1 needs GENDER support.

Status & tagging log