Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php |
— | — | @@ -90,6 +90,7 @@ |
91 | 91 | } |
92 | 92 | |
93 | 93 | $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket ); |
| 94 | + $this->saveUserProperties( $revisionId ); |
94 | 95 | $this->updateRollupTables( $pageId, $revisionId, $user_answers ); |
95 | 96 | |
96 | 97 | if ( $params['email'] ) { |
— | — | @@ -512,6 +513,82 @@ |
513 | 514 | return $ctaId; |
514 | 515 | } |
515 | 516 | |
| 517 | + /** |
| 518 | + * Inserts or updates properties for a specific rating |
| 519 | + * @param $revisionId int Revision ID |
| 520 | + */ |
| 521 | + private function saveUserProperties( $revisionId ) { |
| 522 | + global $wgUser; |
| 523 | + $dbw = wfGetDB( DB_MASTER ); |
| 524 | + $dbr = wfGetDB( DB_SLAVE ); |
| 525 | + $rows = array(); |
| 526 | + |
| 527 | + // Only save data for logged-in users. |
| 528 | + if( !$wgUser->isLoggedIn() ) { |
| 529 | + return null; |
| 530 | + } |
| 531 | + |
| 532 | + // I'd really rather have this passed in, to save a query, |
| 533 | + // and rule out consistency problems, but there doesn't seem |
| 534 | + // to be a way to do 'RETUNING af_id' on the insert, or to |
| 535 | + // pre-increment the ID column (since it's a MySQL auto- |
| 536 | + // increment, not a sequence) before the insert. So, fetch |
| 537 | + // the most recent feedback ID for this user on this revision. |
| 538 | + // This gets called imediately after saving, so it'll almost |
| 539 | + // certainly be the right one. |
| 540 | + $feedbackId = $dbr->selectField( |
| 541 | + 'aft_article_feedback', |
| 542 | + 'af_id', |
| 543 | + array( |
| 544 | + 'af_revision_id' => $revisionId, |
| 545 | + 'af_user_id' => $wgUser->getId() |
| 546 | + ), |
| 547 | + __METHOD__, |
| 548 | + array( |
| 549 | + 'ORDER BY' => 'af_id DESC', |
| 550 | + 'LIMIT' => 1 |
| 551 | + ) |
| 552 | + ); |
| 553 | + |
| 554 | + // Total edits by this user |
| 555 | + $rows[] = array( |
| 556 | + 'afp_feedback_id' => $feedbackId, |
| 557 | + 'afp_key' => 'contribs-lifetime', |
| 558 | + 'afp_value_int' => ( integer ) $wgUser->getEditCount() |
| 559 | + ); |
| 560 | + |
| 561 | + // Use the UserDailyContribs extension if it's present. Get |
| 562 | + // edit counts for last 6 months, last 3 months, and last month. |
| 563 | + if ( function_exists( 'getUserEditCountSince' ) ) { |
| 564 | + $now = time(); |
| 565 | + |
| 566 | + $rows[] = array( |
| 567 | + 'afp_feedback_id' => $feedbackId, |
| 568 | + 'afp_key' => 'contribs-6-months', |
| 569 | + 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 365 / 2 ) ) |
| 570 | + ); |
| 571 | + |
| 572 | + $rows[] = array( |
| 573 | + 'afp_feedback_id' => $feedbackId, |
| 574 | + 'afp_key' => 'contribs-3-months', |
| 575 | + 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 365 / 4 ) ) |
| 576 | + ); |
| 577 | + |
| 578 | + $rows[] = array( |
| 579 | + 'afp_feedback_id' => $feedbackId, |
| 580 | + 'afp_key' => 'contribs-1-months', |
| 581 | + 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 30 ) ) |
| 582 | + ); |
| 583 | + } |
| 584 | + |
| 585 | + $dbw->insert( |
| 586 | + 'aft_article_feedback_properties', |
| 587 | + $rows, |
| 588 | + __METHOD__ |
| 589 | + ); |
| 590 | + } |
| 591 | + |
| 592 | + |
516 | 593 | /** |
517 | 594 | * Picks a CTA to send the user to |
518 | 595 | * |