r110962 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110961‎ | r110962 | r110963 >
Date:20:52, 8 February 2012
Author:catrope
Status:ok
Tags:aft 
Comment:
Followup r110959: reapply the good parts of r96722:
* Drop useless aa_user_id conditions from queries.
* Removed the useless and broken behavior of decrementing values in article_feedback_revisions. It was implemented inconsistently and never worked properly for that reason. This makes insertRevisionRating() much simpler
* Due to the insertRevisionRating() change. $lastRevision is no longer needed. To properly update the revision delta, though, we still need to look at whether the previous rating's revid matches this one's, and only take that rating into account if it does.
Modified paths:
  • /trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php
@@ -46,7 +46,6 @@
4747 'article_feedback',
4848 array( 'aa_rating_id', 'aa_rating_value', 'aa_revision' ),
4949 array(
50 - 'aa_user_id' => $wgUser->getId(),
5150 'aa_user_text' => $wgUser->getName(),
5251 'aa_page_id' => $params['pageid'],
5352 'aa_rating_id' => array_keys( $wgArticleFeedbackRatingTypes ),
@@ -70,11 +69,13 @@
7170 $revisionId = $params['revid'];
7271
7372 foreach ( $wgArticleFeedbackRatingTypes as $ratingID => $unused ) {
74 - $lastRating = false;
75 - $lastRevision = false;
 73+ $lastPageRating = false;
 74+ $lastRevRating = false;
7675 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+ }
7980 }
8081
8182 $thisRating = false;
@@ -82,11 +83,11 @@
8384 $thisRating = intval( $params["r{$ratingID}"] );
8485 }
8586
86 - $this->insertRevisionRating( $pageId, $revisionId, $lastRevision, $ratingID, ( $thisRating - $lastRating ),
87 - $thisRating, $lastRating
 87+ $this->insertRevisionRating( $pageId, $revisionId, $ratingID, $thisRating - $lastRevRating,
 88+ $thisRating, $lastRevRating
8889 );
8990
90 - $this->insertPageRating( $pageId, $ratingID, ( $thisRating - $lastRating ), $thisRating, $lastRating );
 91+ $this->insertPageRating( $pageId, $ratingID, $thisRating - $lastPageRating, $thisRating, $lastPageRating );
9192
9293 $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $ratingID, $thisRating, $params['bucket'] );
9394 }
@@ -157,13 +158,12 @@
158159 *
159160 * @param $pageId Integer: Page Id
160161 * @param $revisionId Integer: Revision Id
161 - * @param $lastRevision Integer: Revision Id of last rating
162162 * @param $ratingId Integer: Rating Id
163163 * @param $updateAddition Integer: Difference between user's last rating (if applicable)
164164 * @param $thisRating Integer|Boolean: Value of the Rating
165165 * @param $lastRating Integer|Boolean: Value of the last Rating
166166 */
167 - private function insertRevisionRating( $pageId, $revisionId, $lastRevision, $ratingId, $updateAddition, $thisRating, $lastRating ) {
 167+ private function insertRevisionRating( $pageId, $revisionId, $ratingId, $updateAddition, $thisRating, $lastRating ) {
168168 $dbw = wfGetDB( DB_MASTER );
169169
170170 // Try to insert a new "totals" row for this page,rev,rating set
@@ -180,57 +180,20 @@
181181 array( 'IGNORE' )
182182 );
183183
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+ );
235198 }
236199 /**
237200 * Calculate the difference between the previous rating and this one
Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php
@@ -179,7 +179,6 @@
180180 array(
181181 'aa_page_id' => $params['pageid'],
182182 'aa_rating_id' => array_keys( $wgArticleFeedbackRatingTypes ),
183 - 'aa_user_id' => $wgUser->getId(),
184183 'aa_user_text' => $wgUser->getName(),
185184 'aa_user_anon_token' => $this->getAnonToken( $params ),
186185 ),

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96722Epic followup to r94404, r94509: change the ArticleFeedback schema such that ...catrope15:26, 10 September 2011
r110959Revert most of r96722. The massive schema change was way overkill given that ...catrope20:21, 8 February 2012

Status & tagging log