r49145 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49144‎ | r49145 | r49146 >
Date:20:30, 2 April 2009
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: cleanup to UserSystemGiftsClass.php & fix notice about undefined property
Modified paths:
  • /trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - *
 4+ * Class for managing awards (a.k.a system gifts)
55 */
66 class UserSystemGifts {
77
@@ -20,41 +20,42 @@
2121 * @private
2222 */
2323 /* private */ function __construct( $username ) {
24 - $title1 = Title::newFromDBkey($username);
 24+ $title1 = Title::newFromDBkey( $username );
2525 $this->user_name = $title1->getText();
26 - $this->user_id = User::idFromName($this->user_name);
 26+ $this->user_id = User::idFromName( $this->user_name );
2727 }
2828
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
3434 $dbw = wfGetDB( DB_MASTER );
3535 $dbw->insert( 'user_system_gift',
36 - array(
37 - 'sg_gift_id' => $gift_id,
38 - 'sg_user_id' => $this->user_id,
39 - 'sg_user_name' => $this->user_name,
40 - 'sg_status' => 1,
41 - 'sg_date' => date("Y-m-d H:i:s"),
42 - ), __METHOD__
 36+ array(
 37+ 'sg_gift_id' => $gift_id,
 38+ 'sg_user_id' => $this->user_id,
 39+ 'sg_user_name' => $this->user_name,
 40+ 'sg_status' => 1,
 41+ 'sg_date' => date("Y-m-d H:i:s"),
 42+ ),
 43+ __METHOD__
4344 );
4445 $sg_gift_id = $dbw->insertId();
45 - $this->incGiftGivenCount($gift_id);
 46+ $this->incGiftGivenCount( $gift_id );
4647
47 - //add to new gift count cache for receiving user
48 - $this->incNewSystemGiftCount($this->user_id);
 48+ // Add to new gift count cache for receiving user
 49+ $this->incNewSystemGiftCount( $this->user_id );
4950
50 - if( $email && !empty( $sg_gift_id ) ) $this->sendGiftNotificationEmail( $this->user_id, $gift_id );
 51+ if( $email && !empty( $sg_gift_id ) ) $this->sendGiftNotificationEmail( $this->user_id, $gift_id );
5152 $wgMemc->delete( wfMemcKey( 'user', 'profile', 'system_gifts', $this->user_id ) );
5253 return $sg_gift_id;
5354 }
5455
5556 public function sendGiftNotificationEmail( $user_id_to, $gift_id ){
56 - wfLoadExtensionMessages('SystemGifts');
57 - $gift = SystemGifts::getGift($gift_id);
58 - $user = User::newFromId($user_id_to);
 57+ wfLoadExtensionMessages( 'SystemGifts' );
 58+ $gift = SystemGifts::getGift( $gift_id );
 59+ $user = User::newFromId( $user_id_to );
5960 $user->loadFromDatabase();
6061 if( $user->isEmailConfirmed() && $user->getIntOption( 'notifygift', 1 ) ){
6162 $gifts_link = SpecialPage::getTitleFor( 'ViewSystemGifts' );
@@ -90,9 +91,9 @@
9192 'sg_status' => 0
9293 ), array( /* WHERE */
9394 'sg_user_id' => $this->user_id
94 - ), ""
 95+ ), __METHOD__
9596 );
96 - $this->clearNewSystemGiftCountCache($this->user_id);
 97+ $this->clearNewSystemGiftCountCache( $this->user_id );
9798 }
9899
99100 static function clearUserGiftStatus( $id ){
@@ -102,7 +103,7 @@
103104 'sg_status' => 0
104105 ), array( /* WHERE */
105106 'sg_id' => $id
106 - ), ""
 107+ ), __METHOD__
107108 );
108109 }
109110
@@ -110,7 +111,7 @@
111112 $dbr = wfGetDB( DB_SLAVE );
112113 $s = $dbr->selectRow( 'user_system_gift', array( 'sg_user_id' ), array( 'sg_id' => $sg_id ), __METHOD__ );
113114 if ( $s !== false ) {
114 - if($user_id == $s->ug_user_id_to){
 115+ if( $user_id == $s->ug_user_id_to ){
115116 return true;
116117 }
117118 }
@@ -131,15 +132,15 @@
132133 $res = $dbr->query($sql);
133134 $row = $dbr->fetchObject( $res );
134135 if( $row ){
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;
 136+ $gift['id'] = $row->sg_id;
 137+ $gift['user_id'] = $row->sg_user_id;
 138+ $gift['user_name'] = $row->sg_user_name;
 139+ $gift['gift_count'] = $row->gift_given_count;
 140+ $gift['timestamp'] = $row->sg_date;
 141+ $gift['gift_id'] = $row->gift_id;
 142+ $gift['name'] = $row->gift_name;
 143+ $gift['description'] = $row->gift_description;
 144+ $gift['status'] = $row->sg_status;
144145 }
145146
146147 return $gift;
@@ -175,12 +176,12 @@
176177
177178 static function getNewSystemGiftCount( $user_id ){
178179 global $wgMemc;
179 - $data = self::getNewSystemGiftCountCache($user_id);
 180+ $data = self::getNewSystemGiftCountCache( $user_id );
180181
181182 if( $data != '' ){
182183 $count = $data;
183184 } else {
184 - $count = self::getNewSystemGiftCountDB($user_id);
 185+ $count = self::getNewSystemGiftCountDB( $user_id );
185186 }
186187 return $count;
187188 }
@@ -193,9 +194,9 @@
194195 $dbr = wfGetDB( DB_SLAVE );
195196 $new_gift_count = 0;
196197 $s = $dbr->selectRow( 'user_system_gift', array( 'count(*) AS count' ), array( 'sg_user_id' => $user_id, 'sg_status' => 1 ), __METHOD__ );
197 - if ( $s !== false )$new_gift_count = $s->count;
 198+ if ( $s !== false ) $new_gift_count = $s->count;
198199
199 - $wgMemc->set($key, $new_gift_count);
 200+ $wgMemc->set( $key, $new_gift_count );
200201
201202 return $new_gift_count;
202203 }
@@ -224,7 +225,7 @@
225226 'gift_id' => $row->sg_gift_id,
226227 'timestamp' => ($row->sg_date),
227228 'status' => $row->sg_status,
228 - 'user_id' => $row->sg_user,
 229+ 'user_id' => $row->sg_user_id,
229230 'user_name' => $row->sg_user_name,
230231 'gift_name' => $row->gift_name,
231232 'gift_description' => $row->gift_description,
@@ -240,12 +241,13 @@
241242 $dbw->update( 'system_gift',
242243 array( 'gift_given_count=gift_given_count+1' ),
243244 array( 'gift_id' => $gift_id ),
244 - __METHOD__ );
 245+ __METHOD__
 246+ );
245247 }
246248
247249 static function getGiftCountByUsername( $user_name ){
248250 $dbr = wfGetDB( DB_SLAVE );
249 - $user_id = User::idFromName($user_name);
 251+ $user_id = User::idFromName( $user_name );
250252 $sql = "SELECT count(*) AS count
251253 FROM {$dbr->tableName( 'user_system_gift' )}
252254 WHERE sg_user_id = {$user_id}
@@ -256,7 +258,7 @@
257259 if( $row ){
258260 $gift_count = $row->count;
259261 }
260 - return $gift_count;
 262+ return $gift_count;
261263 }
262264
263265 }
\ No newline at end of file

Status & tagging log