Index: trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php |
— | — | @@ -28,10 +28,10 @@ |
29 | 29 | public function sendSystemGift( $gift_id, $email = true ){ |
30 | 30 | global $wgMemc; |
31 | 31 | |
32 | | - if( $this->doesUserHaveGift($this->user_id, $gift_id) ) return ""; |
| 32 | + if( $this->doesUserHaveGift($this->user_id, $gift_id) ) return ''; |
33 | 33 | |
34 | | - $dbr = wfGetDB( DB_MASTER ); |
35 | | - $dbr->insert( 'user_system_gift', |
| 34 | + $dbw = wfGetDB( DB_MASTER ); |
| 35 | + $dbw->insert( 'user_system_gift', |
36 | 36 | array( |
37 | 37 | 'sg_gift_id' => $gift_id, |
38 | 38 | 'sg_user_id' => $this->user_id, |
— | — | @@ -40,14 +40,14 @@ |
41 | 41 | 'sg_date' => date("Y-m-d H:i:s"), |
42 | 42 | ), __METHOD__ |
43 | 43 | ); |
44 | | - $sg_gift_id = $dbr->insertId(); |
| 44 | + $sg_gift_id = $dbw->insertId(); |
45 | 45 | $this->incGiftGivenCount($gift_id); |
46 | 46 | |
47 | 47 | //add to new gift count cache for receiving user |
48 | 48 | $this->incNewSystemGiftCount($this->user_id); |
49 | 49 | |
50 | 50 | 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 ) ); |
52 | 52 | return $sg_gift_id; |
53 | 53 | } |
54 | 54 | |
— | — | @@ -56,16 +56,16 @@ |
57 | 57 | $gift = SystemGifts::getGift($gift_id); |
58 | 58 | $user = User::newFromId($user_id_to); |
59 | 59 | $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' ); |
63 | 63 | $subject = wfMsgExt( 'system_gift_received_subject', 'parsemag', |
64 | | - $gift["gift_name"] |
| 64 | + $gift['gift_name'] |
65 | 65 | ); |
66 | 66 | $body = wfMsgExt( 'system_gift_received_body', 'parsemag', |
67 | 67 | ( ( trim( $user->getRealName() ) ) ? $user->getRealName() : $user->getName() ), |
68 | | - $gift["gift_name"], |
69 | | - $gift["gift_description"], |
| 68 | + $gift['gift_name'], |
| 69 | + $gift['gift_description'], |
70 | 70 | $gifts_link->getFullURL(), |
71 | 71 | $update_profile_link->getFullURL() |
72 | 72 | ); |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | |
78 | 78 | public function doesUserHaveGift( $user_id, $gift_id ){ |
79 | 79 | $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__ ); |
81 | 81 | if ( $s !== false ) { |
82 | 82 | return true; |
83 | 83 | } |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | |
110 | 110 | public function doesUserOwnGift( $user_id, $sg_id ){ |
111 | 111 | $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__ ); |
113 | 113 | if ( $s !== false ) { |
114 | 114 | if($user_id == $s->ug_user_id_to){ |
115 | 115 | return true; |
— | — | @@ -118,31 +118,28 @@ |
119 | 119 | } |
120 | 120 | |
121 | 121 | 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__ ); |
126 | 124 | } |
127 | 125 | |
128 | 126 | static function getUserGift( $id ){ |
129 | | - global $wgDBprefix; |
130 | 127 | $dbr = wfGetDB( DB_SLAVE ); |
131 | 128 | $sql = "SELECT sg_id, sg_user_id, sg_user_name,gift_id, sg_date, |
132 | 129 | 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 |
134 | 131 | WHERE sg_id = {$id} LIMIT 0,1"; |
135 | 132 | $res = $dbr->query($sql); |
136 | 133 | $row = $dbr->fetchObject( $res ); |
137 | 134 | 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; |
147 | 144 | } |
148 | 145 | |
149 | 146 | return $gift; |
— | — | @@ -170,7 +167,7 @@ |
171 | 168 | global $wgMemc; |
172 | 169 | $key = wfMemcKey( 'system_gifts', 'new_count', $user_id ); |
173 | 170 | $data = $wgMemc->get( $key ); |
174 | | - if( $data != "" ){ |
| 171 | + if( $data != '' ){ |
175 | 172 | wfDebug( "Got new award count of $data for id $user_id from cache\n" ); |
176 | 173 | return $data; |
177 | 174 | } |
— | — | @@ -180,7 +177,7 @@ |
181 | 178 | global $wgMemc; |
182 | 179 | $data = self::getNewSystemGiftCountCache($user_id); |
183 | 180 | |
184 | | - if( $data != "" ){ |
| 181 | + if( $data != '' ){ |
185 | 182 | $count = $data; |
186 | 183 | } else { |
187 | 184 | $count = self::getNewSystemGiftCountDB($user_id); |
— | — | @@ -195,7 +192,7 @@ |
196 | 193 | $key = wfMemcKey( 'system_gifts', 'new_count', $user_id ); |
197 | 194 | $dbr = wfGetDB( DB_SLAVE ); |
198 | 195 | $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__ ); |
200 | 197 | if ( $s !== false )$new_gift_count = $s->count; |
201 | 198 | |
202 | 199 | $wgMemc->set($key, $new_gift_count); |
— | — | @@ -204,7 +201,6 @@ |
205 | 202 | } |
206 | 203 | |
207 | 204 | public function getUserGiftList( $type, $limit = 0, $page = 0 ){ |
208 | | - global $wgDBprefix; |
209 | 205 | $dbr = wfGetDB( DB_SLAVE ); |
210 | 206 | |
211 | 207 | if( $limit > 0 ){ |
— | — | @@ -215,7 +211,7 @@ |
216 | 212 | |
217 | 213 | $sql = "SELECT sg_id, sg_user_id, sg_user_name, sg_gift_id, sg_date, sg_status, |
218 | 214 | 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 |
220 | 216 | WHERE sg_user_id = {$this->user_id} |
221 | 217 | ORDER BY sg_id DESC |
222 | 218 | {$limit_sql}"; |
— | — | @@ -224,16 +220,16 @@ |
225 | 221 | $requests = array(); |
226 | 222 | while( $row = $dbr->fetchObject( $res ) ) { |
227 | 223 | $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 |
238 | 234 | ); |
239 | 235 | } |
240 | 236 | return $requests; |
— | — | @@ -248,11 +244,10 @@ |
249 | 245 | } |
250 | 246 | |
251 | 247 | static function getGiftCountByUsername( $user_name ){ |
252 | | - global $wgDBprefix; |
253 | 248 | $dbr = wfGetDB( DB_SLAVE ); |
254 | 249 | $user_id = User::idFromName($user_name); |
255 | 250 | $sql = "SELECT count(*) AS count |
256 | | - FROM ".$wgDBprefix."user_system_gift |
| 251 | + FROM {$dbr->tableName( 'user_system_gift' )} |
257 | 252 | WHERE sg_user_id = {$user_id} |
258 | 253 | LIMIT 0,1"; |
259 | 254 | $res = $dbr->query($sql); |