Index: trunk/extensions/SocialProfile/UserStats/UserStatsClass.php |
— | — | @@ -63,8 +63,9 @@ |
64 | 64 | } |
65 | 65 | |
66 | 66 | function initStatsTrack(){ |
| 67 | + global $wgDbPrefix; |
67 | 68 | $dbr =& wfGetDB( DB_SLAVE ); |
68 | | - $s = $dbr->selectRow( '`user_stats`', array( 'stats_user_id' ), array('stats_user_id'=>$this->user_id ), __METHOD__ ); |
| 69 | + $s = $dbr->selectRow( $wgDbPrefix.'`user_stats`', array( 'stats_user_id' ), array('stats_user_id'=>$this->user_id ), __METHOD__ ); |
69 | 70 | |
70 | 71 | if ( $s === false ) { |
71 | 72 | $this->addStatRecord(); |
— | — | @@ -72,8 +73,9 @@ |
73 | 74 | } |
74 | 75 | |
75 | 76 | function addStatRecord(){ |
| 77 | + global $wgDbPrefix; |
76 | 78 | $dbr =& wfGetDB( DB_MASTER ); |
77 | | - $fname = 'user_stats::addToDatabase'; |
| 79 | + $fname = $wgDbPrefix.'user_stats::addToDatabase'; |
78 | 80 | $dbr->insert( '`user_stats`', |
79 | 81 | |
80 | 82 | array( |
— | — | @@ -95,11 +97,10 @@ |
96 | 98 | } |
97 | 99 | |
98 | 100 | function incStatField( $field, $val=1 ){ |
99 | | - global $wgUser, $IP, $wgMemc, $wgSitename,$wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserStatsPointValues; |
100 | | - |
| 101 | + global $wgUser, $IP, $wgDbPrefix, $wgMemc, $wgSitename,$wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserStatsPointValues; |
101 | 102 | if( !$wgUser->isBot() && !$wgUser->isAnon() && $this->stats_fields[$field]) { |
102 | 103 | $dbw = wfGetDB( DB_MASTER ); |
103 | | - $dbw->update( 'user_stats', |
| 104 | + $dbw->update( $wgDbPrefix.'user_stats', |
104 | 105 | array( $this->stats_fields[$field]."=".$this->stats_fields[$field]."+{$val}" ), |
105 | 106 | array( 'stats_user_id' => $this->user_id ), |
106 | 107 | __METHOD__ ); |
— | — | @@ -116,10 +117,10 @@ |
117 | 118 | } |
118 | 119 | |
119 | 120 | function decStatField($field,$val=1){ |
120 | | - global $wgUser, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly; |
| 121 | + global $wgUser, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgDbPrefix; |
121 | 122 | if( !$wgUser->isBot() && !$wgUser->isAnon() && $this->stats_fields[$field]) { |
122 | 123 | $dbw = wfGetDB( DB_MASTER ); |
123 | | - $dbw->update( 'user_stats', |
| 124 | + $dbw->update( $wgDbPrefix.'user_stats', |
124 | 125 | array( $this->stats_fields[$field]."=".$this->stats_fields[$field]."-{$val}" ), |
125 | 126 | array( 'stats_user_id' => $this->user_id ), |
126 | 127 | __METHOD__ ); |
— | — | @@ -135,10 +136,10 @@ |
136 | 137 | } |
137 | 138 | |
138 | 139 | function updateCommentCount(){ |
139 | | - global $wgUser; |
| 140 | + global $wgUser, $wgDbPrefix; |
140 | 141 | if( !$wgUser->isAnon() ) { |
141 | 142 | $dbr = wfGetDB( DB_MASTER ); |
142 | | - $sql = "update user_stats set "; |
| 143 | + $sql = "update ".$wgDbPrefix."user_stats set "; |
143 | 144 | $sql .= 'stats_comment_count='; |
144 | 145 | $sql .= "(SELECT COUNT(*) as CommentCount FROM Comments WHERE Comment_user_id = " . $this->user_id; |
145 | 146 | $sql .= ")"; |
— | — | @@ -150,10 +151,10 @@ |
151 | 152 | } |
152 | 153 | |
153 | 154 | function updateCommentIgnored(){ |
154 | | - global $wgUser; |
| 155 | + global $wgUser, $wgDbPrefix; |
155 | 156 | if( !$wgUser->isAnon() ) { |
156 | 157 | $dbr = wfGetDB( DB_MASTER ); |
157 | | - $sql = "update user_stats set "; |
| 158 | + $sql = "update ".$wgDbPrefix."user_stats set "; |
158 | 159 | $sql .= 'stats_comment_blocked='; |
159 | 160 | $sql .= "(SELECT COUNT(*) as CommentCount FROM Comments_block WHERE cb_user_id_blocked = " . $this->user_id; |
160 | 161 | $sql .= ")"; |
— | — | @@ -165,10 +166,10 @@ |
166 | 167 | } |
167 | 168 | |
168 | 169 | function updateEditCount(){ |
169 | | - global $wgUser; |
| 170 | + global $wgUser, $wgDbPrefix; |
170 | 171 | if( !$wgUser->isAnon() ) { |
171 | 172 | $dbr = wfGetDB( DB_MASTER ); |
172 | | - $sql = "update user_stats set "; |
| 173 | + $sql = "update ".$wgDbPrefix."user_stats set "; |
173 | 174 | $sql .= 'stats_edit_count='; |
174 | 175 | $sql .= "(SELECT count(*) as EditsCount FROM {$dbr->tableName( 'revision' )} WHERE rev_user = {$this->user_id} "; |
175 | 176 | $sql .= ")"; |
— | — | @@ -180,10 +181,10 @@ |
181 | 182 | } |
182 | 183 | |
183 | 184 | function updateVoteCount(){ |
184 | | - global $wgUser; |
| 185 | + global $wgUser, $wgDbPrefix; |
185 | 186 | if( !$wgUser->isAnon() ) { |
186 | 187 | $dbr = wfGetDB( DB_MASTER ); |
187 | | - $sql = "update user_stats set "; |
| 188 | + $sql = "update ".$wgDbPrefix."user_stats set "; |
188 | 189 | $sql .= 'stats_vote_count='; |
189 | 190 | $sql .= "(SELECT count(*) as VoteCount FROM Vote WHERE vote_user_id = {$this->user_id} "; |
190 | 191 | $sql .= ")"; |
— | — | @@ -195,10 +196,10 @@ |
196 | 197 | } |
197 | 198 | |
198 | 199 | function updateCommentScoreRec($vote_type){ |
199 | | - global $wgUser; |
| 200 | + global $wgUser, $wgDbPrefix; |
200 | 201 | if( $this->user_id != 0 ) { |
201 | 202 | $dbr = wfGetDB( DB_MASTER ); |
202 | | - $sql = "update user_stats set "; |
| 203 | + $sql = "update ".$wgDbPrefix."user_stats set "; |
203 | 204 | if($vote_type==1){ |
204 | 205 | $sql .= 'stats_comment_score_positive_rec='; |
205 | 206 | }else{ |
— | — | @@ -214,14 +215,14 @@ |
215 | 216 | } |
216 | 217 | |
217 | 218 | function updateCreatedOpinionsCount(){ |
218 | | - global $wgUser, $wgOut; |
| 219 | + global $wgUser, $wgOut, $wgDbPrefix; |
219 | 220 | if( !$wgUser->isAnon() && $this->user_id) { |
220 | 221 | $ctg = "Opinions by User " . ($this->user_name) ; |
221 | 222 | $parser = new Parser(); |
222 | 223 | $CtgTitle = Title::newFromText( $parser->transformMsg(trim($ctg), $wgOut->parserOptions() ) ); |
223 | 224 | $CtgTitle = $CtgTitle->getDbKey(); |
224 | 225 | $dbr = wfGetDB( DB_MASTER ); |
225 | | - $sql = "update user_stats set stats_opinions_created="; |
| 226 | + $sql = "update ".$wgDbPrefix."user_stats set stats_opinions_created="; |
226 | 227 | $sql .= "(SELECT count(*) as CreatedOpinions FROM {$dbr->tableName( 'page' )} INNER JOIN {$dbr->tableName( 'categorylinks' )} ON page_id = cl_from WHERE (cl_to) = " . $dbr->addQuotes($CtgTitle) . " "; |
227 | 228 | $sql .= ")"; |
228 | 229 | $sql .= " WHERE stats_user_id = " . $this->user_id ; |
— | — | @@ -233,13 +234,13 @@ |
234 | 235 | } |
235 | 236 | |
236 | 237 | function updatePublishedOpinionsCount(){ |
237 | | - global $wgUser, $wgOut; |
| 238 | + global $wgUser, $wgOut, $wgDbPrefix; |
238 | 239 | $parser = new Parser(); |
239 | 240 | $dbr =& wfGetDB( DB_MASTER ); |
240 | 241 | $ctg = "Opinions by User " . ($this->user_name) ; |
241 | 242 | $CtgTitle = Title::newFromText( $parser->transformMsg(trim($ctg), $wgOut->parserOptions()) ); |
242 | 243 | $CtgTitle = $CtgTitle->getDbKey(); |
243 | | - $sql = "update user_stats set stats_opinions_published = "; |
| 244 | + $sql = "update ".$wgDbPrefix."user_stats set stats_opinions_published = "; |
244 | 245 | $sql .= "(SELECT count(*) as PromotedOpinions FROM {$dbr->tableName( 'page' )} INNER JOIN {$dbr->tableName( 'categorylinks' )} ON page_id = cl_from INNER JOIN published_page ON page_id=published_page_id WHERE (cl_to) = " . $dbr->addQuotes($CtgTitle) . " AND published_type=1 " . " " . $timeSQL; |
245 | 246 | $sql .= ")"; |
246 | 247 | $sql .= " WHERE stats_user_id = " . $this->user_id ; |
— | — | @@ -249,15 +250,15 @@ |
250 | 251 | } |
251 | 252 | |
252 | 253 | function updateRelationshipCount($rel_type){ |
253 | | - global $wgUser; |
| 254 | + global $wgUser, $wgDbPrefix; |
254 | 255 | if( !$wgUser->isAnon() ) { |
255 | 256 | $dbr = wfGetDB( DB_MASTER ); |
256 | 257 | if($rel_type==1){ |
257 | 258 | $col="stats_friends_count"; |
258 | 259 | }else{ |
259 | 260 | $col="stats_foe_count"; |
260 | | - } |
261 | | - $sql = "update low_priority user_stats set {$col}= |
| 261 | + } //Where is low_priority? where was this table created? |
| 262 | + $sql = "update low_priority ".$wgDbPrefix."user_stats set {$col}= |
262 | 263 | (SELECT COUNT(*) as rel_count FROM user_relationship WHERE |
263 | 264 | r_user_id = {$this->user_id} AND r_type={$rel_type} |
264 | 265 | ) |
— | — | @@ -267,10 +268,10 @@ |
268 | 269 | } |
269 | 270 | |
270 | 271 | function updateGiftCountRec(){ |
271 | | - global $wgUser,$wgStatsStartTimestamp; |
| 272 | + global $wgUser,$wgStatsStartTimestamp, $wgDbPrefix; |
272 | 273 | if( !$wgUser->isAnon() ) { |
273 | 274 | $dbr = wfGetDB( DB_MASTER ); |
274 | | - $sql = "update low_priority user_stats set stats_gifts_rec_count= |
| 275 | + $sql = "update low_priority ".$wgDbPrefix."user_stats set stats_gifts_rec_count= |
275 | 276 | (SELECT COUNT(*) as gift_count FROM user_gift WHERE |
276 | 277 | ug_user_id_to = {$this->user_id} |
277 | 278 | ) |
— | — | @@ -281,10 +282,10 @@ |
282 | 283 | } |
283 | 284 | |
284 | 285 | function updateGiftCountSent(){ |
285 | | - global $wgUser; |
| 286 | + global $wgUser, $wgDbPrefix; |
286 | 287 | if( !$wgUser->isAnon() ) { |
287 | 288 | $dbr = wfGetDB( DB_MASTER ); |
288 | | - $sql = "update low_priority user_stats set stats_gifts_sent_count= |
| 289 | + $sql = "update low_priority ".$wgDbPrefix."user_stats set stats_gifts_sent_count= |
289 | 290 | (SELECT COUNT(*) as gift_count FROM user_gift WHERE |
290 | 291 | ug_user_id_from = {$this->user_id} |
291 | 292 | ) |
— | — | @@ -295,10 +296,10 @@ |
296 | 297 | } |
297 | 298 | |
298 | 299 | public function updateReferralComplete(){ |
299 | | - global $wgUser,$wgStatsStartTimestamp; |
| 300 | + global $wgUser,$wgStatsStartTimestamp, $wgDbPrefix; |
300 | 301 | if( !$wgUser->isAnon() ) { |
301 | 302 | $dbr = wfGetDB( DB_MASTER ); |
302 | | - $sql = "update low_priority user_stats set stats_referrals_completed= |
| 303 | + $sql = "update low_priority ".$wgDbPrefix."user_stats set stats_referrals_completed= |
303 | 304 | (SELECT COUNT(*) as thecount FROM user_register_track WHERE |
304 | 305 | ur_user_id_referral = {$this->user_id} and ur_user_name_referral<>'DNL' |
305 | 306 | ) |
— | — | @@ -310,7 +311,7 @@ |
311 | 312 | |
312 | 313 | public function updateWeeklyPoints($points){ |
313 | 314 | $dbr =& wfGetDB( DB_MASTER ); |
314 | | - $sql = "SELECT up_user_id from user_points_weekly where up_user_id = {$this->user_id}"; |
| 315 | + $sql = "SELECT up_user_id from user_points_weekly where up_user_id = {$this->user_id}"; //where is the table set for this one? |
315 | 316 | $res = $dbr->query($sql); |
316 | 317 | $row = $dbr->fetchObject( $res ); |
317 | 318 | |
— | — | @@ -361,13 +362,13 @@ |
362 | 363 | } |
363 | 364 | |
364 | 365 | public function updateTotalPoints(){ |
365 | | - global $wgEnableFacebook, $wgUserLevels; |
| 366 | + global $wgEnableFacebook, $wgUserLevels, $wgDbPrefix; |
366 | 367 | |
367 | 368 | if( $this->user_id == 0 )return ""; |
368 | 369 | |
369 | 370 | $dbr =& wfGetDB( DB_MASTER ); |
370 | 371 | $sql = "SELECT * |
371 | | - FROM user_stats where stats_user_id = " . $this->user_id ; |
| 372 | + FROM ".$wgDbPrefix."user_stats where stats_user_id = " . $this->user_id ; |
372 | 373 | $res = $dbr->query($sql); |
373 | 374 | $row = $dbr->fetchObject( $res ); |
374 | 375 | if($row){ |
— | — | @@ -445,12 +446,12 @@ |
446 | 447 | } |
447 | 448 | |
448 | 449 | public function getUserStatsDB(){ |
449 | | - global $wgMemc; |
| 450 | + global $wgMemc, $wgDbPrefix; |
450 | 451 | |
451 | 452 | wfDebug( "Got user stats for {$this->user_name} from db\n" ); |
452 | 453 | $dbr =& wfGetDB( DB_MASTER ); |
453 | 454 | $sql = "SELECT * |
454 | | - FROM user_stats |
| 455 | + FROM ".$wgDbPrefix."user_stats |
455 | 456 | WHERE stats_user_id = {$this->user_id} LIMIT 0,1"; |
456 | 457 | $res = $dbr->query($sql); |
457 | 458 | $row = $dbr->fetchObject( $res ); |