Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php |
— | — | @@ -91,24 +91,6 @@ |
92 | 92 | private function insertPageRating( $pageId, $ratingId, $updateAddition, $thisRating, $lastRating ) { |
93 | 93 | $dbw = wfGetDB( DB_MASTER ); |
94 | 94 | |
95 | | - // 0 == No change in rating count |
96 | | - // 1 == No rating last time (or new rating), and now there is |
97 | | - // -1 == Rating last time, but abstained this time |
98 | | - $countChange = 0; |
99 | | - if ( $lastRating === false || $lastRating === 0 ) { |
100 | | - if ( $thisRating === 0 ) { |
101 | | - $countChange = 0; |
102 | | - } else { |
103 | | - $countChange = 1; |
104 | | - } |
105 | | - } else { // Last rating was > 0 |
106 | | - if ( $thisRating === 0 ) { |
107 | | - $countChange = -1; |
108 | | - } else { |
109 | | - $countChange = 0; |
110 | | - } |
111 | | - } |
112 | | - |
113 | 95 | // Try to insert a new afp row for this page with zeroes in it |
114 | 96 | // Try will silently fail if the row already exists |
115 | 97 | $dbw->insert( |
— | — | @@ -128,7 +110,7 @@ |
129 | 111 | 'article_feedback_pages', |
130 | 112 | array( |
131 | 113 | 'aap_total = aap_total + ' . $updateAddition, |
132 | | - 'aap_count = aap_count + ' . $countChange, |
| 114 | + 'aap_count = aap_count + ' . $this->getCountChange( $lastRating, $thisRating ), |
133 | 115 | ), |
134 | 116 | array( |
135 | 117 | 'aap_page_id' => $pageId, |
— | — | @@ -192,7 +174,7 @@ |
193 | 175 | 'article_feedback_revisions', |
194 | 176 | array( |
195 | 177 | 'afr_total' => $thisRating, |
196 | | - 'afr_count' => 1, |
| 178 | + 'afr_count' => $thisRating ? 1 : 0, |
197 | 179 | ), |
198 | 180 | array( |
199 | 181 | 'afr_page_id' => $pageId, |
— | — | @@ -202,31 +184,12 @@ |
203 | 185 | __METHOD__ |
204 | 186 | ); |
205 | 187 | } else { |
206 | | - // Calculate the difference between the previous rating and this one |
207 | | - // * -1 == Rating last time, but abstained this time |
208 | | - // * 0 == No change in rating count |
209 | | - // * 1 == No rating last time (or new rating), and now there is |
210 | | - $countChange = 0; |
211 | | - if ( $lastRating === false || $lastRating === 0 ) { |
212 | | - if ( $thisRating === 0 ) { |
213 | | - $countChange = 0; |
214 | | - } else { |
215 | | - $countChange = 1; |
216 | | - } |
217 | | - } else { |
218 | | - // Last rating was > 0 |
219 | | - if ( $thisRating === 0 ) { |
220 | | - $countChange = -1; |
221 | | - } else { |
222 | | - $countChange = 0; |
223 | | - } |
224 | | - } |
225 | 188 | // Apply the difference between the previous and new ratings to the current "totals" row |
226 | 189 | $dbw->update( |
227 | 190 | 'article_feedback_revisions', |
228 | 191 | array( |
229 | 192 | 'afr_total = afr_total + ' . $updateAddition, |
230 | | - 'afr_count = afr_count + ' . $countChange, |
| 193 | + 'afr_count = afr_count + ' . $this->getCountChange( $lastRating, $thisRating ), |
231 | 194 | ), |
232 | 195 | array( |
233 | 196 | 'afr_page_id' => $pageId, |
— | — | @@ -237,6 +200,19 @@ |
238 | 201 | ); |
239 | 202 | } |
240 | 203 | } |
| 204 | + /** |
| 205 | + * Calculate the difference between the previous rating and this one |
| 206 | + * -1 == Rating last time, but abstained this time |
| 207 | + * 0 == No change in rating count |
| 208 | + * 1 == No rating last time (or new rating), and now there is |
| 209 | + */ |
| 210 | + protected function getCountChange( $lastRating, $thisRating ) { |
| 211 | + if ( $lastRating === false || $lastRating === 0 ) { |
| 212 | + return $thisRating === 0 ? 0 : 1; |
| 213 | + } |
| 214 | + // Last rating was > 0 |
| 215 | + return $thisRating === 0 ? -1 : 0; |
| 216 | + } |
241 | 217 | |
242 | 218 | /** |
243 | 219 | * Inserts (or Updates, where appropriate) the users ratings for a specific revision |