Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php |
— | — | @@ -46,7 +46,6 @@ |
47 | 47 | 'article_feedback', |
48 | 48 | array( 'aa_rating_id', 'aa_rating_value', 'aa_revision' ), |
49 | 49 | array( |
50 | | - 'aa_user_id' => $wgUser->getId(), |
51 | 50 | 'aa_user_text' => $wgUser->getName(), |
52 | 51 | 'aa_page_id' => $params['pageid'], |
53 | 52 | 'aa_rating_id' => array_keys( $wgArticleFeedbackRatingTypes ), |
— | — | @@ -70,11 +69,13 @@ |
71 | 70 | $revisionId = $params['revid']; |
72 | 71 | |
73 | 72 | foreach ( $wgArticleFeedbackRatingTypes as $ratingID => $unused ) { |
74 | | - $lastRating = false; |
75 | | - $lastRevision = false; |
| 73 | + $lastPageRating = false; |
| 74 | + $lastRevRating = false; |
76 | 75 | if ( isset( $lastRatings[$ratingID] ) ) { |
77 | | - $lastRating = intval( $lastRatings[$ratingID]['value'] ); |
78 | | - $lastRevision = intval( $lastRatings[$ratingID]['revision'] ); |
| 76 | + $lastPageRating = intval( $lastRatings[$ratingID]['value'] ); |
| 77 | + if ( intval( $lastRatings[$ratingID]['revision'] ) == $revisionId ) { |
| 78 | + $lastRevRating = $lastPageRating; |
| 79 | + } |
79 | 80 | } |
80 | 81 | |
81 | 82 | $thisRating = false; |
— | — | @@ -82,11 +83,11 @@ |
83 | 84 | $thisRating = intval( $params["r{$ratingID}"] ); |
84 | 85 | } |
85 | 86 | |
86 | | - $this->insertRevisionRating( $pageId, $revisionId, $lastRevision, $ratingID, ( $thisRating - $lastRating ), |
87 | | - $thisRating, $lastRating |
| 87 | + $this->insertRevisionRating( $pageId, $revisionId, $ratingID, $thisRating - $lastRevRating, |
| 88 | + $thisRating, $lastRevRating |
88 | 89 | ); |
89 | 90 | |
90 | | - $this->insertPageRating( $pageId, $ratingID, ( $thisRating - $lastRating ), $thisRating, $lastRating ); |
| 91 | + $this->insertPageRating( $pageId, $ratingID, $thisRating - $lastPageRating, $thisRating, $lastPageRating ); |
91 | 92 | |
92 | 93 | $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $ratingID, $thisRating, $params['bucket'] ); |
93 | 94 | } |
— | — | @@ -157,13 +158,12 @@ |
158 | 159 | * |
159 | 160 | * @param $pageId Integer: Page Id |
160 | 161 | * @param $revisionId Integer: Revision Id |
161 | | - * @param $lastRevision Integer: Revision Id of last rating |
162 | 162 | * @param $ratingId Integer: Rating Id |
163 | 163 | * @param $updateAddition Integer: Difference between user's last rating (if applicable) |
164 | 164 | * @param $thisRating Integer|Boolean: Value of the Rating |
165 | 165 | * @param $lastRating Integer|Boolean: Value of the last Rating |
166 | 166 | */ |
167 | | - private function insertRevisionRating( $pageId, $revisionId, $lastRevision, $ratingId, $updateAddition, $thisRating, $lastRating ) { |
| 167 | + private function insertRevisionRating( $pageId, $revisionId, $ratingId, $updateAddition, $thisRating, $lastRating ) { |
168 | 168 | $dbw = wfGetDB( DB_MASTER ); |
169 | 169 | |
170 | 170 | // Try to insert a new "totals" row for this page,rev,rating set |
— | — | @@ -180,57 +180,20 @@ |
181 | 181 | array( 'IGNORE' ) |
182 | 182 | ); |
183 | 183 | |
184 | | - // If that succeded in inserting a row, then we are for sure rating a previously unrated |
185 | | - // revision, and we need to add more information about this rating to the new "totals" row, |
186 | | - // as well as remove the previous rating values from the previous "totals" row |
187 | | - if ( $dbw->affectedRows() ) { |
188 | | - // If there was a previous rating, there should be a "totals" row for it's revision |
189 | | - if ( $lastRating ) { |
190 | | - // Deduct the previous rating values from the previous "totals" row |
191 | | - $dbw->update( |
192 | | - 'article_feedback_revisions', |
193 | | - array( |
194 | | - 'afr_total = afr_total - ' . intval( $lastRating ), |
195 | | - 'afr_count = afr_count - 1', |
196 | | - ), |
197 | | - array( |
198 | | - 'afr_page_id' => $pageId, |
199 | | - 'afr_rating_id' => $ratingId, |
200 | | - 'afr_revision' => $lastRevision |
201 | | - ), |
202 | | - __METHOD__ |
203 | | - ); |
204 | | - } |
205 | | - // Add this rating's values to the new "totals" row |
206 | | - $dbw->update( |
207 | | - 'article_feedback_revisions', |
208 | | - array( |
209 | | - 'afr_total' => $thisRating, |
210 | | - 'afr_count' => $thisRating ? 1 : 0, |
211 | | - ), |
212 | | - array( |
213 | | - 'afr_page_id' => $pageId, |
214 | | - 'afr_rating_id' => $ratingId, |
215 | | - 'afr_revision' => $revisionId, |
216 | | - ), |
217 | | - __METHOD__ |
218 | | - ); |
219 | | - } else { |
220 | | - // Apply the difference between the previous and new ratings to the current "totals" row |
221 | | - $dbw->update( |
222 | | - 'article_feedback_revisions', |
223 | | - array( |
224 | | - 'afr_total = afr_total + ' . $updateAddition, |
225 | | - 'afr_count = afr_count + ' . $this->getCountChange( $lastRating, $thisRating ), |
226 | | - ), |
227 | | - array( |
228 | | - 'afr_page_id' => $pageId, |
229 | | - 'afr_rating_id' => $ratingId, |
230 | | - 'afr_revision' => $revisionId, |
231 | | - ), |
232 | | - __METHOD__ |
233 | | - ); |
234 | | - } |
| 184 | + // Apply the difference between the previous and new ratings to the current "totals" row |
| 185 | + $dbw->update( |
| 186 | + 'article_feedback_revisions', |
| 187 | + array( |
| 188 | + 'afr_total = afr_total + ' . $updateAddition, |
| 189 | + 'afr_count = afr_count + ' . $this->getCountChange( $lastRating, $thisRating ), |
| 190 | + ), |
| 191 | + array( |
| 192 | + 'afr_page_id' => $pageId, |
| 193 | + 'afr_rating_id' => $ratingId, |
| 194 | + 'afr_revision' => $revisionId, |
| 195 | + ), |
| 196 | + __METHOD__ |
| 197 | + ); |
235 | 198 | } |
236 | 199 | /** |
237 | 200 | * Calculate the difference between the previous rating and this one |
Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php |
— | — | @@ -179,7 +179,6 @@ |
180 | 180 | array( |
181 | 181 | 'aa_page_id' => $params['pageid'], |
182 | 182 | 'aa_rating_id' => array_keys( $wgArticleFeedbackRatingTypes ), |
183 | | - 'aa_user_id' => $wgUser->getId(), |
184 | 183 | 'aa_user_text' => $wgUser->getName(), |
185 | 184 | 'aa_user_anon_token' => $this->getAnonToken( $params ), |
186 | 185 | ), |