r44902 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44901‎ | r44902 | r44903 >
Date:17:40, 22 December 2008
Author:ashley
Status:deferred
Tags:
Comment:
bug and coding style fixes
Modified paths:
  • /trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php
@@ -28,10 +28,10 @@
2929 public function sendSystemGift( $gift_id, $email = true ){
3030 global $wgMemc;
3131
32 - if( $this->doesUserHaveGift($this->user_id, $gift_id) ) return "";
 32+ if( $this->doesUserHaveGift($this->user_id, $gift_id) ) return '';
3333
34 - $dbr = wfGetDB( DB_MASTER );
35 - $dbr->insert( 'user_system_gift',
 34+ $dbw = wfGetDB( DB_MASTER );
 35+ $dbw->insert( 'user_system_gift',
3636 array(
3737 'sg_gift_id' => $gift_id,
3838 'sg_user_id' => $this->user_id,
@@ -40,14 +40,14 @@
4141 'sg_date' => date("Y-m-d H:i:s"),
4242 ), __METHOD__
4343 );
44 - $sg_gift_id = $dbr->insertId();
 44+ $sg_gift_id = $dbw->insertId();
4545 $this->incGiftGivenCount($gift_id);
4646
4747 //add to new gift count cache for receiving user
4848 $this->incNewSystemGiftCount($this->user_id);
4949
5050 if( $email ) $this->sendGiftNotificationEmail( $this->user_id, $gift_id );
51 - $wgMemc->delete( wfMemcKey( 'user', 'profile', 'system_gifts', $this->user_id) );
 51+ $wgMemc->delete( wfMemcKey( 'user', 'profile', 'system_gifts', $this->user_id ) );
5252 return $sg_gift_id;
5353 }
5454
@@ -56,16 +56,16 @@
5757 $gift = SystemGifts::getGift($gift_id);
5858 $user = User::newFromId($user_id_to);
5959 $user->loadFromDatabase();
60 - if( $user->isEmailConfirmed() && $user->getIntOption("notifygift", 1) ){
61 - $gifts_link = Title::makeTitle( NS_SPECIAL, 'ViewSystemGifts' );
62 - $update_profile_link = Title::makeTitle( NS_SPECIAL, 'UpdateProfile' );
 60+ if( $user->isEmailConfirmed() && $user->getIntOption( 'notifygift', 1 ) ){
 61+ $gifts_link = SpecialPage::getTitleFor( 'ViewSystemGifts' );
 62+ $update_profile_link = SpecialPage::getTitleFor( 'UpdateProfile' );
6363 $subject = wfMsgExt( 'system_gift_received_subject', 'parsemag',
64 - $gift["gift_name"]
 64+ $gift['gift_name']
6565 );
6666 $body = wfMsgExt( 'system_gift_received_body', 'parsemag',
6767 ( ( trim( $user->getRealName() ) ) ? $user->getRealName() : $user->getName() ),
68 - $gift["gift_name"],
69 - $gift["gift_description"],
 68+ $gift['gift_name'],
 69+ $gift['gift_description'],
7070 $gifts_link->getFullURL(),
7171 $update_profile_link->getFullURL()
7272 );
@@ -76,7 +76,7 @@
7777
7878 public function doesUserHaveGift( $user_id, $gift_id ){
7979 $dbr = wfGetDB( DB_SLAVE );
80 - $s = $dbr->selectRow( 'user_system_gift', array( 'sg_status' ), array( 'sg_user_id' => $user_id, 'sg_gift_id' => $gift_id ), $fname );
 80+ $s = $dbr->selectRow( 'user_system_gift', array( 'sg_status' ), array( 'sg_user_id' => $user_id, 'sg_gift_id' => $gift_id ), __METHOD__ );
8181 if ( $s !== false ) {
8282 return true;
8383 }
@@ -108,7 +108,7 @@
109109
110110 public function doesUserOwnGift( $user_id, $sg_id ){
111111 $dbr = wfGetDB( DB_SLAVE );
112 - $s = $dbr->selectRow( 'user_system_gift', array( 'wg_user_id' ), array( 'sg_id' => $sg_id ), $fname );
 112+ $s = $dbr->selectRow( 'user_system_gift', array( 'sg_user_id' ), array( 'sg_id' => $sg_id ), __METHOD__ );
113113 if ( $s !== false ) {
114114 if($user_id == $s->ug_user_id_to){
115115 return true;
@@ -118,31 +118,28 @@
119119 }
120120
121121 static function deleteGift( $ug_id ){
122 - global $wgDBprefix;
123 - $dbr = wfGetDB( DB_MASTER );
124 - $sql = "DELETE FROM ".$wgDBprefix."user_system_gift WHERE sg_id={$ug_id}";
125 - $res = $dbr->query($sql);
 122+ $dbw = wfGetDB( DB_MASTER );
 123+ $dbw->delete( 'user_system_gift', array( 'sg_id' => $ug_id ), __METHOD__ );
126124 }
127125
128126 static function getUserGift( $id ){
129 - global $wgDBprefix;
130127 $dbr = wfGetDB( DB_SLAVE );
131128 $sql = "SELECT sg_id, sg_user_id, sg_user_name,gift_id, sg_date,
132129 gift_name, gift_description, gift_given_count, sg_status
133 - FROM ".$wgDBprefix."user_system_gift INNER JOIN ".$wgDBprefix."system_gift ON sg_gift_id=gift_id
 130+ FROM {$dbr->tableName( 'user_system_gift' )} INNER JOIN {$dbr->tableName( 'system_gift' )} ON sg_gift_id=gift_id
134131 WHERE sg_id = {$id} LIMIT 0,1";
135132 $res = $dbr->query($sql);
136133 $row = $dbr->fetchObject( $res );
137134 if( $row ){
138 - $gift["id"]= $row->sg_id;
139 - $gift["user_id"]= $row->sg_user_id;
140 - $gift["user_name"]= $row->sg_user_name;
141 - $gift["gift_count"]= $row->gift_given_count;
142 - $gift["timestamp"]= $row->sg_date;
143 - $gift["gift_id"]= $row->gift_id;
144 - $gift["name"]= $row->gift_name;
145 - $gift["description"]= $row->gift_description;
146 - $gift["status"]= $row->sg_status;
 135+ $gift['id']= $row->sg_id;
 136+ $gift['user_id']= $row->sg_user_id;
 137+ $gift['user_name']= $row->sg_user_name;
 138+ $gift['gift_count']= $row->gift_given_count;
 139+ $gift['timestamp']= $row->sg_date;
 140+ $gift['gift_id']= $row->gift_id;
 141+ $gift['name']= $row->gift_name;
 142+ $gift['description']= $row->gift_description;
 143+ $gift['status']= $row->sg_status;
147144 }
148145
149146 return $gift;
@@ -170,7 +167,7 @@
171168 global $wgMemc;
172169 $key = wfMemcKey( 'system_gifts', 'new_count', $user_id );
173170 $data = $wgMemc->get( $key );
174 - if( $data != "" ){
 171+ if( $data != '' ){
175172 wfDebug( "Got new award count of $data for id $user_id from cache\n" );
176173 return $data;
177174 }
@@ -180,7 +177,7 @@
181178 global $wgMemc;
182179 $data = self::getNewSystemGiftCountCache($user_id);
183180
184 - if( $data != "" ){
 181+ if( $data != '' ){
185182 $count = $data;
186183 } else {
187184 $count = self::getNewSystemGiftCountDB($user_id);
@@ -195,7 +192,7 @@
196193 $key = wfMemcKey( 'system_gifts', 'new_count', $user_id );
197194 $dbr = wfGetDB( DB_SLAVE );
198195 $new_gift_count = 0;
199 - $s = $dbr->selectRow( 'user_system_gift', array( 'count(*) as count' ), array( 'sg_user_id' => $user_id, 'sg_status' => 1 ), __METHOD__ );
 196+ $s = $dbr->selectRow( 'user_system_gift', array( 'count(*) AS count' ), array( 'sg_user_id' => $user_id, 'sg_status' => 1 ), __METHOD__ );
200197 if ( $s !== false )$new_gift_count = $s->count;
201198
202199 $wgMemc->set($key, $new_gift_count);
@@ -204,7 +201,6 @@
205202 }
206203
207204 public function getUserGiftList( $type, $limit = 0, $page = 0 ){
208 - global $wgDBprefix;
209205 $dbr = wfGetDB( DB_SLAVE );
210206
211207 if( $limit > 0 ){
@@ -215,7 +211,7 @@
216212
217213 $sql = "SELECT sg_id, sg_user_id, sg_user_name, sg_gift_id, sg_date, sg_status,
218214 gift_name, gift_description, gift_given_count, UNIX_TIMESTAMP(sg_date) AS unix_time
219 - FROM ".$wgDBprefix."user_system_gift INNER JOIN ".$wgDBprefix."system_gift ON sg_gift_id=gift_id
 215+ FROM {$dbr->tableName( 'user_system_gift' )} INNER JOIN {$dbr->tableName( 'system_gift' )} ON sg_gift_id=gift_id
220216 WHERE sg_user_id = {$this->user_id}
221217 ORDER BY sg_id DESC
222218 {$limit_sql}";
@@ -224,16 +220,16 @@
225221 $requests = array();
226222 while( $row = $dbr->fetchObject( $res ) ) {
227223 $requests[] = array(
228 - "id" => $row->sg_id,
229 - "gift_id" => $row->sg_gift_id,
230 - "timestamp" => ($row->sg_date),
231 - "status" => $row->sg_status,
232 - "user_id" => $row->sg_user,
233 - "user_name" => $row->sg_user_name,
234 - "gift_name" => $row->gift_name,
235 - "gift_description" => $row->gift_description,
236 - "gift_given_count" => $row->gift_given_count,
237 - "unix_timestamp" => $row->unix_time
 224+ 'id' => $row->sg_id,
 225+ 'gift_id' => $row->sg_gift_id,
 226+ 'timestamp' => ($row->sg_date),
 227+ 'status' => $row->sg_status,
 228+ 'user_id' => $row->sg_user,
 229+ 'user_name' => $row->sg_user_name,
 230+ 'gift_name' => $row->gift_name,
 231+ 'gift_description' => $row->gift_description,
 232+ 'gift_given_count' => $row->gift_given_count,
 233+ 'unix_timestamp' => $row->unix_time
238234 );
239235 }
240236 return $requests;
@@ -248,11 +244,10 @@
249245 }
250246
251247 static function getGiftCountByUsername( $user_name ){
252 - global $wgDBprefix;
253248 $dbr = wfGetDB( DB_SLAVE );
254249 $user_id = User::idFromName($user_name);
255250 $sql = "SELECT count(*) AS count
256 - FROM ".$wgDBprefix."user_system_gift
 251+ FROM {$dbr->tableName( 'user_system_gift' )}
257252 WHERE sg_user_id = {$user_id}
258253 LIMIT 0,1";
259254 $res = $dbr->query($sql);

Status & tagging log