Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | } |
65 | 65 | |
66 | 66 | $this->insertPageRating( $pageId, $rating, ( $thisRating - $lastRating ), |
67 | | - ( $lastRating === false && $thisRating !== false ) |
| 67 | + $thisRating, $lastRating |
68 | 68 | ); |
69 | 69 | |
70 | 70 | $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $rating, $thisRating ); |
— | — | @@ -79,11 +79,22 @@ |
80 | 80 | * @param $pageId Integer: Page Id |
81 | 81 | * @param $ratingId Integer: Rating Id |
82 | 82 | * @param $updateAddition Integer: Difference between user's last rating (if applicable) |
83 | | - * @param $newRating Boolean: Whether this is a new rating (for update, whether this increases the count) |
| 83 | + * @param $thisRating Integer|Boolean: Value of the Rating |
| 84 | + * @param $lastRating Integer|Boolean: Value of the last Rating |
84 | 85 | */ |
85 | | - private function insertPageRating( $pageId, $ratingId, $updateAddition, $newRating ) { |
| 86 | + private function insertPageRating( $pageId, $ratingId, $updateAddition, $thisRating, $lastRating ) { |
86 | 87 | $dbw = wfGetDB( DB_MASTER ); |
87 | 88 | |
| 89 | + $newRating = ( $lastRating === false && $thisRating !== false ); |
| 90 | + $countChange = 0; |
| 91 | + if ( $newRating ) { |
| 92 | + $countChange = 1; // Garunteed new rating |
| 93 | + } else if ( $lastRating === 0 && $thisRating !== 0 ) { |
| 94 | + $countChange = 1; // "New" rating as last was 0 (abstained) |
| 95 | + } else if ( $lastRating !== 0 && $thisRating === 0 ) { |
| 96 | + $countChange = -1; // Rating abstained this time, but there was a prior rating |
| 97 | + } |
| 98 | + |
88 | 99 | $dbw->insert( |
89 | 100 | 'article_feedback_pages', |
90 | 101 | array( |
— | — | @@ -100,7 +111,7 @@ |
101 | 112 | 'article_feedback_pages', |
102 | 113 | array( |
103 | 114 | 'aap_total = aap_total + ' . $updateAddition, |
104 | | - 'aap_count = aap_count + ' . ( $newRating ? 1 : 0 ), |
| 115 | + 'aap_count = aap_count + ' . $countChange, |
105 | 116 | ), |
106 | 117 | array( |
107 | 118 | 'aap_page_id' => $pageId, |