r78409 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78408‎ | r78409 | r78410 >
Date:23:28, 14 December 2010
Author:reedy
Status:deferred
Tags:
Comment:
Allow rating abstination, alter the count whether it's a new rating, a removed rating, or just an updated rating
Modified paths:
  • /trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php
@@ -63,7 +63,7 @@
6464 }
6565
6666 $this->insertPageRating( $pageId, $rating, ( $thisRating - $lastRating ),
67 - ( $lastRating === false && $thisRating !== false )
 67+ $thisRating, $lastRating
6868 );
6969
7070 $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $rating, $thisRating );
@@ -79,11 +79,22 @@
8080 * @param $pageId Integer: Page Id
8181 * @param $ratingId Integer: Rating Id
8282 * @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
8485 */
85 - private function insertPageRating( $pageId, $ratingId, $updateAddition, $newRating ) {
 86+ private function insertPageRating( $pageId, $ratingId, $updateAddition, $thisRating, $lastRating ) {
8687 $dbw = wfGetDB( DB_MASTER );
8788
 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+
8899 $dbw->insert(
89100 'article_feedback_pages',
90101 array(
@@ -100,7 +111,7 @@
101112 'article_feedback_pages',
102113 array(
103114 'aap_total = aap_total + ' . $updateAddition,
104 - 'aap_count = aap_count + ' . ( $newRating ? 1 : 0 ),
 115+ 'aap_count = aap_count + ' . $countChange,
105116 ),
106117 array(
107118 'aap_page_id' => $pageId,

Follow-up revisions

RevisionCommit summaryAuthorDate
r78415Followup r78409, fix tired coding...reedy00:21, 15 December 2010

Status & tagging log