r37622 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37621‎ | r37622 | r37623 >
Date:17:09, 13 July 2008
Author:ashley
Status:old
Tags:
Comment:
SocialProfile:
*take DB table prefix into account too
*some random coding style tweaks
Modified paths:
  • /trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserBoard/UserBoard_AjaxFunctions.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php
@@ -16,9 +16,9 @@
1717 /* private */ function __construct() {
1818 }
1919
20 - public function sendBoardMessage($user_id_from,$user_name_from,$user_id_to,$user_name_to, $message, $message_type=0){
 20+ public function sendBoardMessage($user_id_from, $user_name_from, $user_id_to, $user_name_to, $message, $message_type = 0){
2121 global $IP, $wgDBprefix;
22 - $dbr =& wfGetDB( DB_MASTER );
 22+ $dbr = wfGetDB( DB_MASTER );
2323 $fname = $wgDBprefix.'user_board::addToDatabase';
2424
2525 $user_name_from = stripslashes($user_name_from);
@@ -39,8 +39,8 @@
4040 $ub_gift_id = $dbr->insertId();
4141
4242 //Send Email (if user is not writing on own board)
43 - if($user_id_from!=$user_id_to){
44 - $this->sendBoardNotificationEmail($user_id_to,$user_name_from);
 43+ if($user_id_from != $user_id_to){
 44+ $this->sendBoardNotificationEmail($user_id_to, $user_name_from);
4545 $this->incNewMessageCount($user_id_to);
4646 }
4747
@@ -59,18 +59,18 @@
6060 return $ub_gift_id;
6161 }
6262
63 - public function sendBoardNotificationEmail($user_id_to,$user_from){
 63+ public function sendBoardNotificationEmail($user_id_to, $user_from){
6464 wfLoadExtensionMessages( 'SocialProfileUserBoard' );
6565
6666 $user = User::newFromId($user_id_to);
6767 $user->loadFromId();
6868
69 - if($user->isEmailConfirmed() && $user->getIntOption("notifymessage",1) ){
70 - $board_link = Title::makeTitle( NS_SPECIAL , "UserBoard" );
71 - $update_profile_link = Title::makeTitle( NS_SPECIAL , "UpdateProfile" );
 69+ if($user->isEmailConfirmed() && $user->getIntOption("notifymessage", 1) ){
 70+ $board_link = Title::makeTitle( NS_SPECIAL, "UserBoard" );
 71+ $update_profile_link = Title::makeTitle( NS_SPECIAL, "UpdateProfile" );
7272 $subject = wfMsgExt( 'message_received_subject', "parsemag",
7373 $user_from
74 - );
 74+ );
7575 $body = wfMsgExt( 'message_received_body', "parsemag",
7676 $user->getName(),
7777 $user_from,
@@ -132,7 +132,7 @@
133133
134134 public function doesUserOwnMessage($user_id, $ub_id){
135135 $dbr = wfGetDB( DB_MASTER );
136 - $s = $dbr->selectRow( '`user_board`', array( 'ub_user_id' ), array( 'ub_id' => $ub_id ), $fname );
 136+ $s = $dbr->selectRow( 'user_board', array( 'ub_user_id' ), array( 'ub_id' => $ub_id ), $fname );
137137 if ( $s !== false ) {
138138 if($user_id == $s->ub_user_id){
139139 return true;
@@ -142,25 +142,26 @@
143143 }
144144
145145 public function deleteMessage($ub_id){
 146+ global $wgDBprefix;
146147 if($ub_id){
147 - $dbr =& wfGetDB( DB_MASTER );
148 - $s = $dbr->selectRow( '`user_board`', array( 'ub_user_id','ub_user_name','ub_type' ), array( 'ub_id' => $ub_id ), $fname );
 148+ $dbr = wfGetDB( DB_MASTER );
 149+ $s = $dbr->selectRow( 'user_board', array( 'ub_user_id','ub_user_name','ub_type' ), array( 'ub_id' => $ub_id ), $fname );
149150 if ( $s !== false ) {
150151
151 - $sql = "DELETE FROM user_board WHERE ub_id={$ub_id}";
 152+ $sql = "DELETE FROM ".$wgDBprefix."user_board WHERE ub_id={$ub_id}";
152153 $res = $dbr->query($sql);
153154
154155 $stats = new UserStatsTrack($s->ub_user_id, $s->ub_user_name);
155156 if($s->ub_type==0){
156157 $stats->decStatField("user_board_count");
157 - }else{
 158+ } else {
158159 $stats->decStatField("user_board_count_priv");
159160 }
160161 }
161162 }
162163 }
163164
164 - public function getUserBoardMessages($user_id,$user_id_2=0,$limit=0,$page=0){
 165+ public function getUserBoardMessages($user_id, $user_id_2 = 0, $limit = 0, $page = 0){
165166 global $wgUser, $wgOut, $wgTitle, $wgDBprefix;
166167 $dbr = wfGetDB( DB_SLAVE );
167168
@@ -202,16 +203,16 @@
203204 $message_text = $message_text->getText();
204205
205206 $messages[] = array(
206 - "id"=>$row->ub_id,"timestamp"=>($row->unix_time ) ,
207 - "user_id_from"=>$row->ub_user_id_from,"user_name_from"=>$row->ub_user_name_from,
208 - "user_id"=>$row->ub_user_id,"user_name"=>$row->ub_user_name,
209 - "message_text"=>$message_text,"type"=>$row->ub_type
210 - );
 207+ "id" => $row->ub_id, "timestamp" => ($row->unix_time),
 208+ "user_id_from" => $row->ub_user_id_from, "user_name_from" => $row->ub_user_name_from,
 209+ "user_id" => $row->ub_user_id, "user_name" => $row->ub_user_name,
 210+ "message_text" => $message_text, "type" => $row->ub_type
 211+ );
211212 }
212213 return $messages;
213214 }
214215
215 - public function getUserBoardToBoardCount($user_id,$user_id_2){
 216+ public function getUserBoardToBoardCount($user_id, $user_id_2){
216217 global $wgOut, $wgUser, $wgTitle, $wgDBprefix;
217218 $dbr = wfGetDB( DB_SLAVE );
218219
@@ -235,15 +236,15 @@
236237 return $count;
237238 }
238239
239 - public function displayMessages($user_id,$user_id_2=0,$count=10,$page=0){
 240+ public function displayMessages($user_id, $user_id_2 = 0, $count = 10, $page = 0){
240241 global $wgUser,$max_link_text_length, $wgTitle;
241 - $messages = $this->getUserBoardMessages($user_id,$user_id_2,$count,$page);
 242+ $messages = $this->getUserBoardMessages($user_id, $user_id_2, $count, $page);
242243 wfLoadExtensionMessages( 'SocialProfileUserBoard' );
243244 if ($messages) {
244245
245246 foreach ($messages as $message) {
246247 $user = Title::makeTitle( NS_USER, $message["user_name_from"] );
247 - $avatar = new wAvatar($message["user_id_from"],"m");
 248+ $avatar = new wAvatar($message["user_id_from"], "m");
248249
249250 $board_to_board = "";
250251 $board_link = "";
@@ -299,20 +300,20 @@
300301 }
301302
302303 static function getBoardBlastURL( ){
303 - $title = Title::makeTitle( NS_SPECIAL , "SendBoardBlast" );
 304+ $title = Title::makeTitle( NS_SPECIAL, "SendBoardBlast" );
304305 return $title->escapeFullURL();
305306 }
306307
307308 static function getUserBoardURL($user_name){
308 - $title = Title::makeTitle( NS_SPECIAL , "UserBoard" );
309 - $user_name = str_replace("&","%26",$user_name);
 309+ $title = Title::makeTitle( NS_SPECIAL, "UserBoard" );
 310+ $user_name = str_replace("&", "%26", $user_name);
310311 return $title->escapeFullURL('user='.$user_name);
311312 }
312313
313 - static function getUserBoardToBoardURL($user_name_1,$user_name_2){
314 - $title = Title::makeTitle( NS_SPECIAL , "UserBoard" );
315 - $user_name_1 = str_replace("&","%26",$user_name_1);
316 - $user_name_2 = str_replace("&","%26",$user_name_2);
 314+ static function getUserBoardToBoardURL($user_name_1, $user_name_2){
 315+ $title = Title::makeTitle( NS_SPECIAL, "UserBoard" );
 316+ $user_name_1 = str_replace("&", "%26", $user_name_1);
 317+ $user_name_2 = str_replace("&", "%26", $user_name_2);
317318 return $title->escapeFullURL('user='.$user_name_1.'&conv='.$user_name_2);
318319 }
319320
@@ -334,7 +335,7 @@
335336 return $dif;
336337 }
337338
338 - public function getTimeOffset($time,$timeabrv,$timename){
 339+ public function getTimeOffset($time, $timeabrv, $timename){
339340 if($time[$timeabrv]>0){
340341 $timeStr = $time[$timeabrv] . " " . $timename;
341342 if($time[$timeabrv]>1)$timeStr .= "s";
@@ -344,12 +345,12 @@
345346 }
346347
347348 public function getTimeAgo($time){
348 - $timeArray = $this-> dateDiff(time(),$time );
 349+ $timeArray = $this-> dateDiff( time(), $time );
349350 $timeStr = "";
350 - $timeStrD = $this->getTimeOffset($timeArray,"d","day");
351 - $timeStrH = $this->getTimeOffset($timeArray,"h","hour");
352 - $timeStrM = $this->getTimeOffset($timeArray,"m","minute");
353 - $timeStrS = $this->getTimeOffset($timeArray,"s","second");
 351+ $timeStrD = $this->getTimeOffset($timeArray, "d", "day");
 352+ $timeStrH = $this->getTimeOffset($timeArray, "h", "hour");
 353+ $timeStrM = $this->getTimeOffset($timeArray, "m", "minute");
 354+ $timeStrS = $this->getTimeOffset($timeArray, "s", "second");
354355 $timeStr = $timeStrD;
355356 if($timeStr<2){
356357 $timeStr.=$timeStrH;
@@ -358,4 +359,4 @@
359360 }
360361 return $timeStr;
361362 }
362 -}
 363+}
\ No newline at end of file
Index: trunk/extensions/SocialProfile/UserBoard/UserBoard_AjaxFunctions.php
@@ -1,16 +1,16 @@
22 <?php
33 $wgAjaxExportList [] = 'wfSendBoardMessage';
4 -function wfSendBoardMessage($user_name,$message,$message_type,$count){
 4+function wfSendBoardMessage($user_name, $message, $message_type, $count){
55 global $IP, $wgMemc, $wgUser;
6 - //require_once("$IP/extensions/wikia/UserBoard/UserBoardClass.php");
 6+ //require_once("$IP/extensions/SocialProfile/UserBoard/UserBoardClass.php");
77 $user_name = stripslashes($user_name);
88 $user_name = urldecode($user_name);
99 $user_id_to = User::idFromName($user_name);
1010 $b = new UserBoard();
1111
12 - $m = $b->sendBoardMessage($wgUser->getID(),$wgUser->getName(),$user_id_to, $user_name, urldecode($message),$message_type);
 12+ $m = $b->sendBoardMessage($wgUser->getID(), $wgUser->getName(), $user_id_to, $user_name, urldecode($message), $message_type);
1313
14 - return $b->displayMessages($user_id_to,0,$count);
 14+ return $b->displayMessages($user_id_to, 0, $count);
1515 }
1616
1717 $wgAjaxExportList [] = 'wfDeleteBoardMessage';
@@ -18,7 +18,7 @@
1919 global $IP, $wgMemc, $wgUser;
2020
2121 $b = new UserBoard();
22 - if( $b->doesUserOwnMessage($wgUser->getID(),$ub_id) ){
 22+ if( $b->doesUserOwnMessage($wgUser->getID(), $ub_id) ){
2323 $b->deleteMessage($ub_id);
2424 }
2525 return "ok";
Index: trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php
@@ -17,7 +17,7 @@
1818 }
1919
2020 $dbr = wfGetDB( DB_MASTER );
21 - $sql = "SELECT rev_user_text, rev_user, count(*) AS the_count FROM revision INNER JOIN page ON page_id = rev_page WHERE page_namespace = 0 AND rev_user <> 0 GROUP BY rev_user_text ";
 21+ $sql = "SELECT rev_user_text, rev_user, count(*) AS the_count FROM ".$wgDBprefix."revision INNER JOIN ".$wgDBprefix."page ON page_id = rev_page WHERE page_namespace = 0 AND rev_user <> 0 GROUP BY rev_user_text ";
2222 $res = $dbr->query($sql);
2323 while ($row = $dbr->fetchObject( $res ) ) {
2424
@@ -30,10 +30,10 @@
3131 $edit_count = 0;
3232 }
3333
34 - $s = $dbr->selectRow( '`'.$wgDBprefix.'user_stats`', array( 'stats_user_id' ), array('stats_user_id' => $row->rev_user), __METHOD__ );
 34+ $s = $dbr->selectRow( 'user_stats', array( 'stats_user_id' ), array('stats_user_id' => $row->rev_user), __METHOD__ );
3535 if ( ! $s->stats_user_id ) {
3636
37 - $dbr->insert( '`'.$wgDBprefix.'user_stats`',
 37+ $dbr->insert( 'user_stats',
3838 array(
3939 'stats_year_id' => 0,
4040 'stats_user_id' => $row->rev_user,
@@ -58,14 +58,14 @@
5959 }
6060
6161 function execute(){
62 - global $wgUser, $wgOut;
 62+ global $wgUser, $wgOut, $wgDBprefix;
6363 $dbr = wfGetDB( DB_MASTER );
6464 $this->updateMainEditsCount();
6565
6666 global $wgUserLevels;
6767 $wgUserLevels = "";
6868
69 - $sql = "SELECT stats_user_id,stats_user_name, stats_total_points FROM user_stats ORDER BY stats_user_name";
 69+ $sql = "SELECT stats_user_id,stats_user_name, stats_total_points FROM ".$wgDBprefix."user_stats ORDER BY stats_user_name";
7070 $res = $dbr->query($sql);
7171 $out = "";
7272 while ($row = $dbr->fetchObject( $res ) ) {

Status & tagging log