Index: trunk/extensions/SocialProfile/UserStats/UserStatsClass.php |
— | — | @@ -67,12 +67,17 @@ |
68 | 68 | 'links_approved' => 'stats_links_approved' |
69 | 69 | ); |
70 | 70 | |
| 71 | + /** |
| 72 | + * Constructor |
| 73 | + * @param $user_id Integer: ID number of the user that we want to track stats for |
| 74 | + * @param $user_name Mixed: user's name; if not supplied, then the user ID will be used to get the user name from DB. |
| 75 | + */ |
71 | 76 | function UserStatsTrack( $user_id, $user_name = '' ){ |
72 | 77 | global $wgUserStatsPointValues; |
73 | 78 | |
74 | 79 | $this->user_id = $user_id; |
75 | 80 | if( !$user_name ){ |
76 | | - $user = User::newFromId($this->user_id); |
| 81 | + $user = User::newFromId( $this->user_id ); |
77 | 82 | $user->loadFromDatabase(); |
78 | 83 | $user_name = $user->getName(); |
79 | 84 | } |
— | — | @@ -82,6 +87,9 @@ |
83 | 88 | $this->initStatsTrack(); |
84 | 89 | } |
85 | 90 | |
| 91 | + /** |
| 92 | + * Checks if records for the given user are present in user_stats table and if not, adds them |
| 93 | + */ |
86 | 94 | function initStatsTrack(){ |
87 | 95 | $dbr = wfGetDB( DB_SLAVE ); |
88 | 96 | $s = $dbr->selectRow( 'user_stats', array( 'stats_user_id' ), array( 'stats_user_id' => $this->user_id ), __METHOD__ ); |
— | — | @@ -91,19 +99,24 @@ |
92 | 100 | } |
93 | 101 | } |
94 | 102 | |
| 103 | + /** |
| 104 | + * Adds a record for the given user into the user_stats table |
| 105 | + */ |
95 | 106 | function addStatRecord(){ |
96 | 107 | $dbw = wfGetDB( DB_MASTER ); |
97 | 108 | $dbw->insert( 'user_stats', |
98 | | - |
99 | | - array( |
100 | | - 'stats_year_id' => 0, |
101 | | - 'stats_user_id' => $this->user_id, |
102 | | - 'stats_user_name' => $this->user_name, |
103 | | - 'stats_total_points' => 1000 |
| 109 | + array( |
| 110 | + 'stats_year_id' => 0, |
| 111 | + 'stats_user_id' => $this->user_id, |
| 112 | + 'stats_user_name' => $this->user_name, |
| 113 | + 'stats_total_points' => 1000 |
104 | 114 | ), __METHOD__ |
105 | 115 | ); |
106 | 116 | } |
107 | 117 | |
| 118 | + /** |
| 119 | + * Deletes Memcached entries |
| 120 | + */ |
108 | 121 | function clearCache(){ |
109 | 122 | global $wgMemc; |
110 | 123 | |
— | — | @@ -113,21 +126,22 @@ |
114 | 127 | } |
115 | 128 | |
116 | 129 | function incStatField( $field, $val = 1 ){ |
117 | | - global $wgUser, $IP, $wgDBprefix, $wgMemc, $wgSitename, $wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserStatsPointValues; |
| 130 | + global $wgUser, $wgMemc, $wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserStatsPointValues; |
118 | 131 | if( !$wgUser->isAllowed( 'bot' ) && !$wgUser->isAnon() && $this->stats_fields[$field] ) { |
119 | 132 | $dbw = wfGetDB( DB_MASTER ); |
120 | 133 | $dbw->update( 'user_stats', |
121 | | - array( $this->stats_fields[$field]."=".$this->stats_fields[$field]."+{$val}" ), |
| 134 | + array( $this->stats_fields[$field] . '=' . $this->stats_fields[$field] . "+{$val}" ), |
122 | 135 | array( 'stats_user_id' => $this->user_id ), |
123 | | - __METHOD__ ); |
| 136 | + __METHOD__ |
| 137 | + ); |
124 | 138 | $this->updateTotalPoints(); |
125 | 139 | |
126 | 140 | $this->clearCache(); |
127 | 141 | |
128 | 142 | // update weekly/monthly points |
129 | | - if( $this->point_values[$field] ){ |
130 | | - if( $wgUserStatsTrackWeekly ) $this->updateWeeklyPoints($this->point_values[$field]); |
131 | | - if( $wgUserStatsTrackMonthly ) $this->updateMonthlyPoints($this->point_values[$field]); |
| 143 | + if( isset( $this->point_values[$field] ) && !empty( $this->point_values[$field] ) ){ |
| 144 | + if( $wgUserStatsTrackWeekly ) $this->updateWeeklyPoints( $this->point_values[$field] ); |
| 145 | + if( $wgUserStatsTrackMonthly ) $this->updateMonthlyPoints( $this->point_values[$field] ); |
132 | 146 | } |
133 | 147 | |
134 | 148 | if( $wgSystemGifts ){ |
— | — | @@ -135,7 +149,7 @@ |
136 | 150 | $stat_field = $this->stats_fields[$field]; |
137 | 151 | $field_count = $s->$stat_field; |
138 | 152 | |
139 | | - $key = wfMemcKey( 'system_gift', 'id', $field."-".$field_count ); |
| 153 | + $key = wfMemcKey( 'system_gift', 'id', $field . '-' . $field_count ); |
140 | 154 | $data = $wgMemc->get( $key ); |
141 | 155 | |
142 | 156 | if( $data ){ |
— | — | @@ -143,15 +157,15 @@ |
144 | 158 | $system_gift_id = $data; |
145 | 159 | } else { |
146 | 160 | $g = new SystemGifts(); |
147 | | - $system_gift_id = $g->doesGiftExistForThreshold($field, $field_count); |
| 161 | + $system_gift_id = $g->doesGiftExistForThreshold( $field, $field_count ); |
148 | 162 | if( $system_gift_id ){ |
149 | 163 | $wgMemc->set( $key, $system_gift_id, 60 * 30 ); |
150 | 164 | } |
151 | 165 | } |
152 | 166 | |
153 | 167 | if( $system_gift_id ){ |
154 | | - $sg = new UserSystemGifts($this->user_name); |
155 | | - $sg->sendSystemGift($system_gift_id); |
| 168 | + $sg = new UserSystemGifts( $this->user_name ); |
| 169 | + $sg->sendSystemGift( $system_gift_id ); |
156 | 170 | } |
157 | 171 | } |
158 | 172 | } |
— | — | @@ -162,14 +176,17 @@ |
163 | 177 | if( !$wgUser->isAllowed( 'bot' ) && !$wgUser->isAnon() && $this->stats_fields[$field] ) { |
164 | 178 | $dbw = wfGetDB( DB_MASTER ); |
165 | 179 | $dbw->update( 'user_stats', |
166 | | - array( $this->stats_fields[$field]."=".$this->stats_fields[$field]."-{$val}" ), |
| 180 | + array( $this->stats_fields[$field] . '=' . $this->stats_fields[$field] . "-{$val}" ), |
167 | 181 | array( 'stats_user_id' => $this->user_id ), |
168 | | - __METHOD__ ); |
| 182 | + __METHOD__ |
| 183 | + ); |
169 | 184 | |
170 | 185 | if( $this->point_values[$field] ){ |
171 | 186 | $this->updateTotalPoints(); |
172 | | - if( $wgUserStatsTrackWeekly ) $this->updateWeeklyPoints(0-($this->point_values[$field])); |
173 | | - if( $wgUserStatsTrackMonthly ) $this->updateMonthlyPoints(0-($this->point_values[$field])); |
| 187 | + if( $wgUserStatsTrackWeekly ) |
| 188 | + $this->updateWeeklyPoints( 0 - ( $this->point_values[$field] ) ); |
| 189 | + if( $wgUserStatsTrackMonthly ) |
| 190 | + $this->updateMonthlyPoints( 0 - ( $this->point_values[$field] ) ); |
174 | 191 | } |
175 | 192 | |
176 | 193 | $this->clearCache(); |
— | — | @@ -197,7 +214,7 @@ |
198 | 215 | $dbw = wfGetDB( DB_MASTER ); |
199 | 216 | $sql = "UPDATE ".$wgDBprefix."user_stats SET "; |
200 | 217 | $sql .= 'stats_comment_blocked='; |
201 | | - $sql .= "(SELECT COUNT(*) AS CommentCount FROM Comments_block WHERE cb_user_id_blocked = " . $this->user_id; |
| 218 | + $sql .= "(SELECT COUNT(*) AS CommentCount FROM Comments_block WHERE cb_user_id_blocked = " . $this->user_id; |
202 | 219 | $sql .= ")"; |
203 | 220 | $sql .= " WHERE stats_user_id = " . $this->user_id; |
204 | 221 | $res = $dbw->query($sql); |
— | — | @@ -206,6 +223,10 @@ |
207 | 224 | } |
208 | 225 | } |
209 | 226 | |
| 227 | + /** |
| 228 | + * Update the amount of edits for a given user |
| 229 | + * Edit count is fetched from revision table |
| 230 | + */ |
210 | 231 | function updateEditCount(){ |
211 | 232 | global $wgUser, $wgDBprefix; |
212 | 233 | if( !$wgUser->isAnon() ) { |
— | — | @@ -258,9 +279,9 @@ |
259 | 280 | function updateCreatedOpinionsCount(){ |
260 | 281 | global $wgUser, $wgOut, $wgDBprefix; |
261 | 282 | if( !$wgUser->isAnon() && $this->user_id ) { |
262 | | - $ctg = "Opinions by User " . ($this->user_name); |
| 283 | + $ctg = 'Opinions by User ' . ( $this->user_name ); |
263 | 284 | $parser = new Parser(); |
264 | | - $CtgTitle = Title::newFromText( $parser->transformMsg( trim($ctg), $wgOut->parserOptions() ) ); |
| 285 | + $CtgTitle = Title::newFromText( $parser->transformMsg( trim( $ctg ), $wgOut->parserOptions() ) ); |
265 | 286 | $CtgTitle = $CtgTitle->getDBKey(); |
266 | 287 | $dbw = wfGetDB( DB_MASTER ); |
267 | 288 | $sql = "UPDATE ".$wgDBprefix."user_stats SET stats_opinions_created="; |
— | — | @@ -278,8 +299,8 @@ |
279 | 300 | global $wgUser, $wgOut, $wgDBprefix; |
280 | 301 | $parser = new Parser(); |
281 | 302 | $dbw = wfGetDB( DB_MASTER ); |
282 | | - $ctg = "Opinions by User " . ($this->user_name); |
283 | | - $CtgTitle = Title::newFromText( $parser->transformMsg( trim($ctg), $wgOut->parserOptions() ) ); |
| 303 | + $ctg = 'Opinions by User ' . ( $this->user_name ); |
| 304 | + $CtgTitle = Title::newFromText( $parser->transformMsg( trim( $ctg ), $wgOut->parserOptions() ) ); |
284 | 305 | $CtgTitle = $CtgTitle->getDBKey(); |
285 | 306 | $sql = "UPDATE ".$wgDBprefix."user_stats SET stats_opinions_published = "; |
286 | 307 | $sql .= "(SELECT count(*) AS PromotedOpinions FROM {$dbw->tableName( 'page' )} INNER JOIN {$dbw->tableName( 'categorylinks' )} ON page_id = cl_from INNER JOIN published_page ON page_id=published_page_id WHERE (cl_to) = " . $dbw->addQuotes($CtgTitle) . " AND published_type=1 " . " " . $timeSQL; |
— | — | @@ -309,7 +330,7 @@ |
310 | 331 | } |
311 | 332 | |
312 | 333 | function updateGiftCountRec(){ |
313 | | - global $wgUser, $wgStatsStartTimestamp, $wgDBprefix; |
| 334 | + global $wgUser, $wgDBprefix; |
314 | 335 | if( !$wgUser->isAnon() ) { |
315 | 336 | $dbw = wfGetDB( DB_MASTER ); |
316 | 337 | $sql = "UPDATE LOW_PRIORITY ".$wgDBprefix."user_stats SET stats_gifts_rec_count= |
— | — | @@ -337,7 +358,7 @@ |
338 | 359 | } |
339 | 360 | |
340 | 361 | public function updateReferralComplete(){ |
341 | | - global $wgUser, $wgStatsStartTimestamp, $wgDBprefix; |
| 362 | + global $wgUser, $wgDBprefix; |
342 | 363 | if( !$wgUser->isAnon() ) { |
343 | 364 | $dbw = wfGetDB( DB_MASTER ); |
344 | 365 | $sql = "UPDATE LOW_PRIORITY ".$wgDBprefix."user_stats SET stats_referrals_completed= |
— | — | @@ -351,78 +372,75 @@ |
352 | 373 | } |
353 | 374 | |
354 | 375 | public function updateWeeklyPoints( $points ){ |
355 | | - global $wgDBprefix; |
356 | 376 | $dbw = wfGetDB( DB_MASTER ); |
357 | | - $sql = "SELECT up_user_id FROM ".$wgDBprefix."user_points_weekly WHERE up_user_id = {$this->user_id}"; |
358 | | - $res = $dbw->query($sql); |
| 377 | + $res = $dbw->select( 'user_points_weekly', 'up_user_id', array( "up_user_id = {$this->user_id}" ), __METHOD__ ); |
359 | 378 | $row = $dbw->fetchObject( $res ); |
360 | 379 | |
361 | 380 | if( !$row ){ |
362 | 381 | $this->addWeekly(); |
363 | 382 | } |
364 | 383 | $dbw->update( 'user_points_weekly', |
365 | | - array( 'up_points=up_points+'.$points ), |
366 | | - array( 'up_user_id' => $this->user_id ), |
367 | | - __METHOD__ ); |
| 384 | + array( 'up_points=up_points+' . $points ), |
| 385 | + array( 'up_user_id' => $this->user_id ), |
| 386 | + __METHOD__ |
| 387 | + ); |
368 | 388 | } |
369 | 389 | |
370 | 390 | public function addWeekly(){ |
371 | 391 | $dbw = wfGetDB( DB_MASTER ); |
372 | 392 | $dbw->insert( 'user_points_weekly', |
373 | | - array( |
374 | | - 'up_user_id' => $this->user_id, |
375 | | - 'up_user_name' => $this->user_name |
| 393 | + array( |
| 394 | + 'up_user_id' => $this->user_id, |
| 395 | + 'up_user_name' => $this->user_name |
376 | 396 | ), __METHOD__ |
377 | 397 | ); |
378 | 398 | } |
379 | 399 | |
380 | 400 | public function updateMonthlyPoints( $points ){ |
381 | | - global $wgDBprefix; |
382 | 401 | $dbw = wfGetDB( DB_MASTER ); |
383 | | - $sql = "SELECT up_user_id FROM ".$wgDBprefix."user_points_monthly WHERE up_user_id = {$this->user_id}"; |
384 | | - $res = $dbw->query($sql); |
| 402 | + $res = $dbw->select( 'user_points_monthly', 'up_user_id', array( "up_user_id = {$this->user_id}" ), __METHOD__ ); |
385 | 403 | $row = $dbw->fetchObject( $res ); |
386 | 404 | if( !$row ){ |
387 | 405 | $this->addMonthly(); |
388 | 406 | } |
389 | 407 | |
390 | 408 | $dbw->update( 'user_points_monthly', |
391 | | - array( 'up_points=up_points+'.$points), |
392 | | - array( 'up_user_id' => $this->user_id ), |
393 | | - __METHOD__ ); |
| 409 | + array( 'up_points=up_points+' . $points ), |
| 410 | + array( 'up_user_id' => $this->user_id ), |
| 411 | + __METHOD__ |
| 412 | + ); |
394 | 413 | } |
395 | 414 | |
396 | 415 | public function addMonthly(){ |
397 | 416 | $dbw = wfGetDB( DB_MASTER ); |
398 | 417 | $dbw->insert( 'user_points_monthly', |
399 | | - array( |
400 | | - 'up_user_id' => $this->user_id, |
401 | | - 'up_user_name' => $this->user_name |
| 418 | + array( |
| 419 | + 'up_user_id' => $this->user_id, |
| 420 | + 'up_user_name' => $this->user_name |
402 | 421 | ), __METHOD__ |
403 | 422 | ); |
404 | 423 | } |
405 | 424 | |
406 | 425 | public function updateTotalPoints(){ |
407 | | - global $wgEnableFacebook, $wgUserLevels, $wgDBprefix; |
| 426 | + global $wgEnableFacebook, $wgUserLevels; |
408 | 427 | |
409 | | - if( $this->user_id == 0 ) return ''; |
| 428 | + if( $this->user_id == 0 ) |
| 429 | + return ''; |
410 | 430 | |
411 | 431 | $stats_data = array(); |
412 | 432 | if( is_array( $wgUserLevels ) ){ |
413 | 433 | // Load points before update |
414 | | - $stats = new UserStats($this->user_id, $this->user_name); |
| 434 | + $stats = new UserStats( $this->user_id, $this->user_name ); |
415 | 435 | $stats_data = $stats->getUserStats(); |
416 | 436 | $points_before = $stats_data['points']; |
417 | 437 | |
418 | 438 | // Load Honorific Level before update |
419 | | - $user_level = new UserLevel($points_before); |
| 439 | + $user_level = new UserLevel( $points_before ); |
420 | 440 | $level_number_before = $user_level->getLevelNumber(); |
421 | 441 | } |
422 | 442 | |
423 | 443 | $dbw = wfGetDB( DB_MASTER ); |
424 | | - $sql = "SELECT * |
425 | | - FROM ".$wgDBprefix."user_stats WHERE stats_user_id = " . $this->user_id; |
426 | | - $res = $dbw->query($sql); |
| 444 | + $res = $dbw->select( 'user_stats', '*', array( "stats_user_id = {$this->user_id}" ), __METHOD__ ); |
427 | 445 | $row = $dbw->fetchObject( $res ); |
428 | 446 | if( $row ){ |
429 | 447 | // recaculate point total |
— | — | @@ -442,21 +460,22 @@ |
443 | 461 | } |
444 | 462 | |
445 | 463 | $dbw->update( 'user_stats', |
446 | | - array( 'stats_total_points' => $new_total_points), |
447 | | - array( 'stats_user_id' => $this->user_id ), |
448 | | - __METHOD__ ); |
| 464 | + array( 'stats_total_points' => $new_total_points ), |
| 465 | + array( 'stats_user_id' => $this->user_id ), |
| 466 | + __METHOD__ |
| 467 | + ); |
449 | 468 | |
450 | 469 | // If user levels is in settings, check to see if user advanced with update |
451 | 470 | if( is_array( $wgUserLevels ) ){ |
452 | 471 | // Get New Honorific Level |
453 | | - $user_level = new UserLevel($new_total_points); |
| 472 | + $user_level = new UserLevel( $new_total_points ); |
454 | 473 | $level_number_after = $user_level->getLevelNumber(); |
455 | 474 | |
456 | 475 | // Check if user advanced on this update |
457 | | - /*if($level_number_after > $level_number_before){ |
| 476 | + /*if( $level_number_after > $level_number_before ){ |
458 | 477 | $m = new UserSystemMessage(); |
459 | | - $m->addMessage($this->user_name, 2, "advanced to level <span style=\"font-weight:800;\">{$user_level->getLevelName()}</span>"); |
460 | | - $m->sendAdvancementNotificationEmail($this->user_id, $user_level->getLevelName()); |
| 478 | + $m->addMessage( $this->user_name, 2, "advanced to level <span style=\"font-weight:800;\">{$user_level->getLevelName()}</span>" ); |
| 479 | + $m->sendAdvancementNotificationEmail( $this->user_id, $user_level->getLevelName() ); |
461 | 480 | }*/ |
462 | 481 | } |
463 | 482 | $this->clearCache(); |
— | — | @@ -469,11 +488,13 @@ |
470 | 489 | /** |
471 | 490 | * Constructor |
472 | 491 | * @private |
| 492 | + * @param $user_id Integer: ID number of the user that we want to track stats for |
| 493 | + * @param $user_name Mixed: user's name; if not supplied, then the user ID will be used to get the user name from DB. |
473 | 494 | */ |
474 | 495 | /* private */ function __construct( $user_id, $user_name ) { |
475 | 496 | $this->user_id = $user_id; |
476 | 497 | if( !$user_name ){ |
477 | | - $user = User::newFromId($this->user_id); |
| 498 | + $user = User::newFromId( $this->user_id ); |
478 | 499 | $user->loadFromDatabase(); |
479 | 500 | $user_name = $user->getName(); |
480 | 501 | } |
— | — | @@ -499,6 +520,9 @@ |
500 | 521 | 'gifts_sent_count' => 'Gifts Sent' |
501 | 522 | ); |
502 | 523 | |
| 524 | + /** |
| 525 | + * Retrieves per-user statistics, either from Memcached or from the database |
| 526 | + */ |
503 | 527 | public function getUserStats(){ |
504 | 528 | $stats = $this->getUserStatsCache(); |
505 | 529 | if( !$stats ){ |
— | — | @@ -507,6 +531,9 @@ |
508 | 532 | return $stats; |
509 | 533 | } |
510 | 534 | |
| 535 | + /** |
| 536 | + * Retrieves cached per-user statistics from Memcached, if possible |
| 537 | + */ |
511 | 538 | public function getUserStatsCache(){ |
512 | 539 | global $wgMemc; |
513 | 540 | $key = wfMemcKey( 'user', 'stats', $this->user_id ); |
— | — | @@ -517,14 +544,15 @@ |
518 | 545 | } |
519 | 546 | } |
520 | 547 | |
| 548 | + /** |
| 549 | + * Retrieves per-user statistics from the database |
| 550 | + */ |
521 | 551 | public function getUserStatsDB(){ |
522 | 552 | global $wgMemc, $wgDBprefix; |
523 | 553 | |
524 | 554 | wfDebug( "Got user stats for {$this->user_name} from DB\n" ); |
525 | 555 | $dbr = wfGetDB( DB_MASTER ); |
526 | | - $sql = "SELECT * |
527 | | - FROM ".$wgDBprefix."user_stats |
528 | | - WHERE stats_user_id = {$this->user_id} LIMIT 0,1"; |
| 556 | + $sql = "SELECT * FROM ".$wgDBprefix."user_stats WHERE stats_user_id = {$this->user_id} LIMIT 0,1"; |
529 | 557 | $res = $dbr->query($sql); |
530 | 558 | $row = $dbr->fetchObject( $res ); |
531 | 559 | $stats['edits'] = number_format( isset( $row->stats_edit_count ) ? $row->stats_edit_count : 0 ); |
— | — | @@ -542,17 +570,17 @@ |
543 | 571 | $stats['foe_count'] = number_format( isset( $row->stats_foe_count ) ? $row->stats_foe_count : 0 ); |
544 | 572 | $stats['user_board'] = number_format( isset( $row->user_board_count ) ? $row->user_board_count : 0 ); |
545 | 573 | $stats['user_board_priv'] = number_format( isset( $row->user_board_count_priv ) ? $row->user_board_count_priv : 0 ); |
546 | | - $stats['user_board_sent'] = number_format( isset( $row->user_board_sent ) ? $row->user_board_sent : 0); |
547 | | - $stats['weekly_wins'] = number_format( isset( $row->stats_weekly_winner_count ) ? $row->stats_weekly_winner_count : 0); |
548 | | - $stats['monthly_wins'] = number_format( isset( $row->stats_monthly_winner_count ) ? $row->stats_monthly_winner_count : 0); |
| 574 | + $stats['user_board_sent'] = number_format( isset( $row->user_board_sent ) ? $row->user_board_sent : 0 ); |
| 575 | + $stats['weekly_wins'] = number_format( isset( $row->stats_weekly_winner_count ) ? $row->stats_weekly_winner_count : 0 ); |
| 576 | + $stats['monthly_wins'] = number_format( isset( $row->stats_monthly_winner_count ) ? $row->stats_monthly_winner_count : 0 ); |
549 | 577 | $stats['poll_votes'] = number_format( isset( $row->stats_poll_votes ) ? $row->stats_poll_votes : 0 ); |
550 | 578 | $stats['currency'] = number_format( isset( $row->stats_currency ) ? $row->stats_currency : 0 ); |
551 | 579 | $stats['picture_game_votes'] = number_format( isset( $row->stats_picturegame_votes ) ? $row->stats_picturegame_votes : 0 ); |
552 | 580 | $stats['quiz_created'] = number_format( isset( $row->stats_quiz_questions_created ) ? $row->stats_quiz_questions_created : 0 ); |
553 | 581 | $stats['quiz_answered'] = number_format( isset( $row->stats_quiz_questions_answered ) ? $row->stats_quiz_questions_answered : 0 ); |
554 | | - $stats['quiz_correct'] = number_format( isset( $row->stats_quiz_questions_correct ) ? $row->stats_quiz_questions_correct : 0); |
| 582 | + $stats['quiz_correct'] = number_format( isset( $row->stats_quiz_questions_correct ) ? $row->stats_quiz_questions_correct : 0 ); |
555 | 583 | $stats['quiz_points'] = number_format( isset( $row->stats_quiz_points ) ? $row->stats_quiz_points : 0 ); |
556 | | - $stats['quiz_correct_percent'] = number_format( ( isset( $row->stats_quiz_questions_correct_percent ) ? $row->stats_quiz_questions_correct_percent : 0 ) *100, 2); |
| 584 | + $stats['quiz_correct_percent'] = number_format( ( isset( $row->stats_quiz_questions_correct_percent ) ? $row->stats_quiz_questions_correct_percent : 0 ) * 100, 2 ); |
557 | 585 | $stats['user_status_count'] = number_format( isset( $row->user_status_count ) ? $row->user_status_count : 0 ); |
558 | 586 | if( !$row ){ |
559 | 587 | $stats['points'] = '1,000'; |
— | — | @@ -591,7 +619,7 @@ |
592 | 620 | return $list; |
593 | 621 | } |
594 | 622 | |
595 | | - static function getTopFansListPeriod( $limit = 10, $period = "weekly"){ |
| 623 | + static function getTopFansListPeriod( $limit = 10, $period = 'weekly' ){ |
596 | 624 | $dbr = wfGetDB( DB_SLAVE ); |
597 | 625 | |
598 | 626 | if( $limit > 0 ){ |
— | — | @@ -655,7 +683,7 @@ |
656 | 684 | ); |
657 | 685 | } |
658 | 686 | if( $condition == 1 ){ |
659 | | - $list = array_reverse($list); |
| 687 | + $list = array_reverse( $list ); |
660 | 688 | } |
661 | 689 | return $list; |
662 | 690 | } |
— | — | @@ -668,7 +696,7 @@ |
669 | 697 | /* private */ function __construct( $points ) { |
670 | 698 | global $wgUserLevels; |
671 | 699 | $this->levels = $wgUserLevels; |
672 | | - $this->points = (int)str_replace(",", "", $points); |
| 700 | + $this->points = (int)str_replace( ',', '', $points ); |
673 | 701 | if( $this->levels ) $this->setLevel(); |
674 | 702 | } |
675 | 703 | |
— | — | @@ -681,9 +709,9 @@ |
682 | 710 | } else { |
683 | 711 | // Set next level and what they need to reach |
684 | 712 | // Check if not already at highest level |
685 | | - if( ($this->level_number) != count($this->levels) ){ |
| 713 | + if( ( $this->level_number ) != count( $this->levels ) ){ |
686 | 714 | $this->next_level_name = $level_name; |
687 | | - $this->next_level_points_needed = ($level_points_needed - $this->points); |
| 715 | + $this->next_level_points_needed = ( $level_points_needed - $this->points ); |
688 | 716 | return ''; |
689 | 717 | } |
690 | 718 | } |
— | — | @@ -693,45 +721,54 @@ |
694 | 722 | public function getLevelName(){ return $this->level_name; } |
695 | 723 | public function getLevelNumber(){ return $this->level_number; } |
696 | 724 | public function getNextLevelName(){ return $this->next_level_name; } |
697 | | - public function getPointsNeededToAdvance(){ return number_format($this->next_level_points_needed); } |
| 725 | + public function getPointsNeededToAdvance(){ return number_format( $this->next_level_points_needed ); } |
698 | 726 | public function getLevelMinimum(){ return $this->levels[$this->level_name]; } |
699 | 727 | } |
700 | 728 | |
| 729 | +/** |
| 730 | + * Class for tracking email invitations |
| 731 | + * Used by InviteContacts extension |
| 732 | + */ |
701 | 733 | class UserEmailTrack { |
702 | 734 | |
703 | 735 | /** |
704 | 736 | * Constructor |
705 | 737 | * @private |
| 738 | + * @param $user_id Integer: ID number of the user that we want to track stats for |
| 739 | + * @param $user_name Mixed: user's name; if not supplied, then the user ID will be used to get the user name from DB. |
706 | 740 | */ |
707 | 741 | /* private */ function __construct( $user_id, $user_name ) { |
708 | 742 | $this->user_id = $user_id; |
709 | 743 | if( !$user_name ){ |
710 | | - $user = User::newFromId($this->user_id); |
| 744 | + $user = User::newFromId( $this->user_id ); |
711 | 745 | $user->loadFromDatabase(); |
712 | 746 | $user_name = $user->getName(); |
713 | 747 | } |
714 | 748 | $this->user_name = $user_name; |
715 | 749 | } |
716 | | - //type |
717 | | - /* |
| 750 | + |
| 751 | + /** |
| 752 | + * @param $type Integer: one of the following: |
718 | 753 | 1 = Invite - Email Contacts sucker |
719 | 754 | 2 = Invite -CVS Contacts importer |
720 | 755 | 3 = Invite -Manually Address enter |
721 | 756 | 4 = Invite to Read - Manually Address enter |
722 | 757 | 5 = Invite to Edit - Manually Address enter |
723 | 758 | 6 = Invite to Rate - Manually Address enter |
724 | | - */ |
| 759 | + * @param $count |
| 760 | + * @param $page_title |
| 761 | + */ |
725 | 762 | public function track_email( $type, $count, $page_title = '' ){ |
726 | 763 | if( $this->user_id > 0 ){ |
727 | 764 | $dbw = wfGetDB( DB_MASTER ); |
728 | 765 | $dbw->insert( 'user_email_track', |
729 | | - array( |
730 | | - 'ue_user_id' => $this->user_id, |
731 | | - 'ue_user_name' => $this->user_name, |
732 | | - 'ue_type' => $type, |
733 | | - 'ue_count' => $count, |
734 | | - 'ue_page_title' => $page_title, |
735 | | - 'ue_date' => date("Y-m-d H:i:s"), |
| 766 | + array( |
| 767 | + 'ue_user_id' => $this->user_id, |
| 768 | + 'ue_user_name' => $this->user_name, |
| 769 | + 'ue_type' => $type, |
| 770 | + 'ue_count' => $count, |
| 771 | + 'ue_page_title' => $page_title, |
| 772 | + 'ue_date' => date("Y-m-d H:i:s"), |
736 | 773 | ), __METHOD__ |
737 | 774 | ); |
738 | 775 | } |