r31457 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r31456‎ | r31457 | r31458 >
Date:17:31, 2 March 2008
Author:siebrand
Status:old
Tags:
Comment:
Now takes $wgDbPrefix into account.

Patch by: Bfhappy/Wiredtape
Modified paths:
  • /trunk/extensions/SocialProfile/UserStats/UserStatsClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserStats/UserStatsClass.php
@@ -63,8 +63,9 @@
6464 }
6565
6666 function initStatsTrack(){
 67+ global $wgDbPrefix;
6768 $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__ );
6970
7071 if ( $s === false ) {
7172 $this->addStatRecord();
@@ -72,8 +73,9 @@
7374 }
7475
7576 function addStatRecord(){
 77+ global $wgDbPrefix;
7678 $dbr =& wfGetDB( DB_MASTER );
77 - $fname = 'user_stats::addToDatabase';
 79+ $fname = $wgDbPrefix.'user_stats::addToDatabase';
7880 $dbr->insert( '`user_stats`',
7981
8082 array(
@@ -95,11 +97,10 @@
9698 }
9799
98100 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;
101102 if( !$wgUser->isBot() && !$wgUser->isAnon() && $this->stats_fields[$field]) {
102103 $dbw = wfGetDB( DB_MASTER );
103 - $dbw->update( 'user_stats',
 104+ $dbw->update( $wgDbPrefix.'user_stats',
104105 array( $this->stats_fields[$field]."=".$this->stats_fields[$field]."+{$val}" ),
105106 array( 'stats_user_id' => $this->user_id ),
106107 __METHOD__ );
@@ -116,10 +117,10 @@
117118 }
118119
119120 function decStatField($field,$val=1){
120 - global $wgUser, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly;
 121+ global $wgUser, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgDbPrefix;
121122 if( !$wgUser->isBot() && !$wgUser->isAnon() && $this->stats_fields[$field]) {
122123 $dbw = wfGetDB( DB_MASTER );
123 - $dbw->update( 'user_stats',
 124+ $dbw->update( $wgDbPrefix.'user_stats',
124125 array( $this->stats_fields[$field]."=".$this->stats_fields[$field]."-{$val}" ),
125126 array( 'stats_user_id' => $this->user_id ),
126127 __METHOD__ );
@@ -135,10 +136,10 @@
136137 }
137138
138139 function updateCommentCount(){
139 - global $wgUser;
 140+ global $wgUser, $wgDbPrefix;
140141 if( !$wgUser->isAnon() ) {
141142 $dbr = wfGetDB( DB_MASTER );
142 - $sql = "update user_stats set ";
 143+ $sql = "update ".$wgDbPrefix."user_stats set ";
143144 $sql .= 'stats_comment_count=';
144145 $sql .= "(SELECT COUNT(*) as CommentCount FROM Comments WHERE Comment_user_id = " . $this->user_id;
145146 $sql .= ")";
@@ -150,10 +151,10 @@
151152 }
152153
153154 function updateCommentIgnored(){
154 - global $wgUser;
 155+ global $wgUser, $wgDbPrefix;
155156 if( !$wgUser->isAnon() ) {
156157 $dbr = wfGetDB( DB_MASTER );
157 - $sql = "update user_stats set ";
 158+ $sql = "update ".$wgDbPrefix."user_stats set ";
158159 $sql .= 'stats_comment_blocked=';
159160 $sql .= "(SELECT COUNT(*) as CommentCount FROM Comments_block WHERE cb_user_id_blocked = " . $this->user_id;
160161 $sql .= ")";
@@ -165,10 +166,10 @@
166167 }
167168
168169 function updateEditCount(){
169 - global $wgUser;
 170+ global $wgUser, $wgDbPrefix;
170171 if( !$wgUser->isAnon() ) {
171172 $dbr = wfGetDB( DB_MASTER );
172 - $sql = "update user_stats set ";
 173+ $sql = "update ".$wgDbPrefix."user_stats set ";
173174 $sql .= 'stats_edit_count=';
174175 $sql .= "(SELECT count(*) as EditsCount FROM {$dbr->tableName( 'revision' )} WHERE rev_user = {$this->user_id} ";
175176 $sql .= ")";
@@ -180,10 +181,10 @@
181182 }
182183
183184 function updateVoteCount(){
184 - global $wgUser;
 185+ global $wgUser, $wgDbPrefix;
185186 if( !$wgUser->isAnon() ) {
186187 $dbr = wfGetDB( DB_MASTER );
187 - $sql = "update user_stats set ";
 188+ $sql = "update ".$wgDbPrefix."user_stats set ";
188189 $sql .= 'stats_vote_count=';
189190 $sql .= "(SELECT count(*) as VoteCount FROM Vote WHERE vote_user_id = {$this->user_id} ";
190191 $sql .= ")";
@@ -195,10 +196,10 @@
196197 }
197198
198199 function updateCommentScoreRec($vote_type){
199 - global $wgUser;
 200+ global $wgUser, $wgDbPrefix;
200201 if( $this->user_id != 0 ) {
201202 $dbr = wfGetDB( DB_MASTER );
202 - $sql = "update user_stats set ";
 203+ $sql = "update ".$wgDbPrefix."user_stats set ";
203204 if($vote_type==1){
204205 $sql .= 'stats_comment_score_positive_rec=';
205206 }else{
@@ -214,14 +215,14 @@
215216 }
216217
217218 function updateCreatedOpinionsCount(){
218 - global $wgUser, $wgOut;
 219+ global $wgUser, $wgOut, $wgDbPrefix;
219220 if( !$wgUser->isAnon() && $this->user_id) {
220221 $ctg = "Opinions by User " . ($this->user_name) ;
221222 $parser = new Parser();
222223 $CtgTitle = Title::newFromText( $parser->transformMsg(trim($ctg), $wgOut->parserOptions() ) );
223224 $CtgTitle = $CtgTitle->getDbKey();
224225 $dbr = wfGetDB( DB_MASTER );
225 - $sql = "update user_stats set stats_opinions_created=";
 226+ $sql = "update ".$wgDbPrefix."user_stats set stats_opinions_created=";
226227 $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) . " ";
227228 $sql .= ")";
228229 $sql .= " WHERE stats_user_id = " . $this->user_id ;
@@ -233,13 +234,13 @@
234235 }
235236
236237 function updatePublishedOpinionsCount(){
237 - global $wgUser, $wgOut;
 238+ global $wgUser, $wgOut, $wgDbPrefix;
238239 $parser = new Parser();
239240 $dbr =& wfGetDB( DB_MASTER );
240241 $ctg = "Opinions by User " . ($this->user_name) ;
241242 $CtgTitle = Title::newFromText( $parser->transformMsg(trim($ctg), $wgOut->parserOptions()) );
242243 $CtgTitle = $CtgTitle->getDbKey();
243 - $sql = "update user_stats set stats_opinions_published = ";
 244+ $sql = "update ".$wgDbPrefix."user_stats set stats_opinions_published = ";
244245 $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;
245246 $sql .= ")";
246247 $sql .= " WHERE stats_user_id = " . $this->user_id ;
@@ -249,15 +250,15 @@
250251 }
251252
252253 function updateRelationshipCount($rel_type){
253 - global $wgUser;
 254+ global $wgUser, $wgDbPrefix;
254255 if( !$wgUser->isAnon() ) {
255256 $dbr = wfGetDB( DB_MASTER );
256257 if($rel_type==1){
257258 $col="stats_friends_count";
258259 }else{
259260 $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}=
262263 (SELECT COUNT(*) as rel_count FROM user_relationship WHERE
263264 r_user_id = {$this->user_id} AND r_type={$rel_type}
264265 )
@@ -267,10 +268,10 @@
268269 }
269270
270271 function updateGiftCountRec(){
271 - global $wgUser,$wgStatsStartTimestamp;
 272+ global $wgUser,$wgStatsStartTimestamp, $wgDbPrefix;
272273 if( !$wgUser->isAnon() ) {
273274 $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=
275276 (SELECT COUNT(*) as gift_count FROM user_gift WHERE
276277 ug_user_id_to = {$this->user_id}
277278 )
@@ -281,10 +282,10 @@
282283 }
283284
284285 function updateGiftCountSent(){
285 - global $wgUser;
 286+ global $wgUser, $wgDbPrefix;
286287 if( !$wgUser->isAnon() ) {
287288 $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=
289290 (SELECT COUNT(*) as gift_count FROM user_gift WHERE
290291 ug_user_id_from = {$this->user_id}
291292 )
@@ -295,10 +296,10 @@
296297 }
297298
298299 public function updateReferralComplete(){
299 - global $wgUser,$wgStatsStartTimestamp;
 300+ global $wgUser,$wgStatsStartTimestamp, $wgDbPrefix;
300301 if( !$wgUser->isAnon() ) {
301302 $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=
303304 (SELECT COUNT(*) as thecount FROM user_register_track WHERE
304305 ur_user_id_referral = {$this->user_id} and ur_user_name_referral<>'DNL'
305306 )
@@ -310,7 +311,7 @@
311312
312313 public function updateWeeklyPoints($points){
313314 $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?
315316 $res = $dbr->query($sql);
316317 $row = $dbr->fetchObject( $res );
317318
@@ -361,13 +362,13 @@
362363 }
363364
364365 public function updateTotalPoints(){
365 - global $wgEnableFacebook, $wgUserLevels;
 366+ global $wgEnableFacebook, $wgUserLevels, $wgDbPrefix;
366367
367368 if( $this->user_id == 0 )return "";
368369
369370 $dbr =& wfGetDB( DB_MASTER );
370371 $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 ;
372373 $res = $dbr->query($sql);
373374 $row = $dbr->fetchObject( $res );
374375 if($row){
@@ -445,12 +446,12 @@
446447 }
447448
448449 public function getUserStatsDB(){
449 - global $wgMemc;
 450+ global $wgMemc, $wgDbPrefix;
450451
451452 wfDebug( "Got user stats for {$this->user_name} from db\n" );
452453 $dbr =& wfGetDB( DB_MASTER );
453454 $sql = "SELECT *
454 - FROM user_stats
 455+ FROM ".$wgDbPrefix."user_stats
455456 WHERE stats_user_id = {$this->user_id} LIMIT 0,1";
456457 $res = $dbr->query($sql);
457458 $row = $dbr->fetchObject( $res );

Status & tagging log