r100532 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100531‎ | r100532 | r100533 >
Date:08:43, 23 October 2011
Author:petrb
Status:deferred
Tags:
Comment:
Improved some stuff according to recommendations from review
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -32,15 +32,14 @@
3333 global $wgUser, $wgDBname, $wgOnlineStatusBarTable;
3434 if ( OnlineStatusBar::GetStatus($wgUser->getID()) != $OnlineStatusBar->DefaultOnline )
3535 {
36 - $db = wfGetDB( DB_MASTER );
37 - $db->SelectDB( $wgDBname );
 36+ $dbw = wfGetDB( DB_MASTER );
3837 $now = OnlineStatusBar::GetNow();
3938 $row = array(
4039 'userid' => $wgUser->getID(),
4140 'username' => $wgUser->getName(),
4241 'timestamp' => $now,
4342 );
44 - $db->insert( $wgOnlineStatusBarTable, $row, __METHOD__, 'DELAYED' );
 43+ $dbw->insert( $wgOnlineStatusBarTable, $row, __METHOD__, 'DELAYED' );
4544 }
4645
4746 return false;
@@ -55,9 +54,8 @@
5655 OnlineStatusBar::UpdateDb();
5756 return true;
5857 }
59 - $db = wfGetDB ( DB_MASTER );
60 - $db->SelectDB( $wgDBname );
61 - $db->update($wgOnlineStatusBarTable, array ('timestamp' => $now), array ('username' => $wgUser->getName()), __METHOD__ );
 58+ $dbw = wfGetDB ( DB_MASTER );
 59+ $dbw->update($wgOnlineStatusBarTable, array ('timestamp' => $now), array ('username' => $wgUser->getName()), __METHOD__ );
6260
6361 return false;
6462
@@ -66,10 +64,9 @@
6765 public static function DeleteOld()
6866 {
6967 global $wgOnlineStatusBarTable, $wgOnlineStatusBar_LogoutTime, $wgDBname;
70 - $db = wfGetDB ( DB_MASTER );
 68+ $dbw= wfGetDB ( DB_MASTER );
7169 $time = OnlineStatusBar::GetNow() - $wgOnlineStatusBar_LogoutTime;
72 - $db->SelectDB( $wgDBname );
73 - $db->delete( $wgOnlineStatusBarTable, array( 'timestamp < "' . $time . '"' ) ,__METHOD__ );
 70+ $dbw->delete( $wgOnlineStatusBarTable, array( 'timestamp < "' . $time . '"' ) ,__METHOD__ );
7471 return 0;
7572 }
7673
@@ -83,11 +80,10 @@
8481
8582 static function GetStatus( $userID ) {
8683 global $wgOnlineStatusBarTable, $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname;
87 - $db = wfGetDB ( DB_MASTER );
 84+ $dbw= wfGetDB ( DB_MASTER );
8885 OnlineStatusBar::DeleteOld();
89 - $db->SelectDB( $wgDBname );
90 - $result = $db->select( $wgOnlineStatusBarTable, array ('userid', 'username', 'timestamp'), array('username' => $userID), __METHOD__, array('limit 1', 'order by timestamp desc'));
91 - $values = new ResultWrapper ($db, $result);
 86+ $result = $dbw->select( $wgOnlineStatusBarTable, array ('userid', 'username', 'timestamp'), array('username' => $userID), __METHOD__, array('limit 1', 'order by timestamp desc'));
 87+ $values = new ResultWrapper ($dbw, $result);
9288
9389 if ($values->numRows() > 0)
9490 {
@@ -100,11 +96,8 @@
10197 static function DeleteStatus( $user )
10298 {
10399 global $wgOnlineStatusBarTable, $wgDBname;
104 - $db = wfGetDB ( DB_MASTER );
105 - $db->SelectDB( $wgDBname );
106 - $db->delete( $wgOnlineStatusBarTable, array ('username' => $user), __METHOD__ ); // delete user
 100+ $dbw= wfGetDB ( DB_MASTER );
 101+ $dbw->delete( $wgOnlineStatusBarTable, array ('username' => $user), __METHOD__ ); // delete user
107102 return true;
108103 }
109104 }
110 -
111 -?>
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -98,7 +98,7 @@
9999 global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarModes, $wgOut;
100100 OnlineStatusBar::UpdateStatus();
101101 $ns=$article->getTitle()->getNamespace();
102 - if(($ns == "3") || ($ns == "2"))
 102+ if(($ns == NS_USER_TALK) || ($ns == NS_USER))
103103 {
104104 // better way to get a username would be great :)
105105 $user = preg_replace('/\/.*/', '', preg_replace('/^.*\:/', "", $article->getTitle()));
@@ -114,13 +114,11 @@
115115 function wfOnlineStatusBar_UpdateStatus()
116116 {
117117 OnlineStatusBar::UpdateDb();
118 - return 0;
 118+ return true;
119119 }
120120
121121
122122 $commonModuleInfo = array(
123123 'localBasePath' => dirname( __FILE__ ) . '/modules',
124124 'remoteExtPath' => 'OnlineStatusBar/modules',
125 -);
126 -
127 -?>
 125+ );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100501Work in progress, extension which adds a status if user is online, there is s...petrb16:47, 22 October 2011

Status & tagging log