r84623 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84622‎ | r84623 | r84624 >
Date:18:57, 23 March 2011
Author:tparscal
Status:ok
Tags:
Comment:
Added comments to help make it easier to understand the program flow - see r84535
Modified paths:
  • /trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php
@@ -91,6 +91,7 @@
9292 private function insertPageRating( $pageId, $revisionId, $lastRevision, $ratingId, $updateAddition, $thisRating, $lastRating ) {
9393 $dbw = wfGetDB( DB_MASTER );
9494
 95+ // Try to insert a new "totals" row for this page,rev,rating set
9596 $dbw->insert(
9697 'article_feedback_pages',
9798 array(
@@ -104,8 +105,13 @@
105106 array( 'IGNORE' )
106107 );
107108
 109+ // If that succeded in inserting a row, then we are for sure rating a previously unrated
 110+ // revision, and we need to add more information about this rating to the new "totals" row,
 111+ // as well as remove the previous rating values from the previous "totals" row
108112 if ( $dbw->affectedRows() ) {
 113+ // If there was a previous rating, there should be a "totals" row for it's revision
109114 if ( $lastRating ) {
 115+ // Deduct the previous rating values from the previous "totals" row
110116 $dbw->update(
111117 'article_feedback_pages',
112118 array(
@@ -120,6 +126,7 @@
121127 __METHOD__
122128 );
123129 }
 130+ // Add this rating's values to the new "totals" row
124131 $dbw->update(
125132 'article_feedback_pages',
126133 array(
@@ -134,9 +141,10 @@
135142 __METHOD__
136143 );
137144 } else {
138 - // 0 == No change in rating count
139 - // 1 == No rating last time (or new rating), and now there is
140 - // -1 == Rating last time, but abstained this time
 145+ // Calculate the difference between the previous rating and this one
 146+ // * -1 == Rating last time, but abstained this time
 147+ // * 0 == No change in rating count
 148+ // * 1 == No rating last time (or new rating), and now there is
141149 $countChange = 0;
142150 if ( $lastRating === false || $lastRating === 0 ) {
143151 if ( $thisRating === 0 ) {
@@ -144,13 +152,15 @@
145153 } else {
146154 $countChange = 1;
147155 }
148 - } else { // Last rating was > 0
 156+ } else {
 157+ // Last rating was > 0
149158 if ( $thisRating === 0 ) {
150159 $countChange = -1;
151160 } else {
152161 $countChange = 0;
153162 }
154163 }
 164+ // Apply the difference between the previous and new ratings to the current "totals" row
155165 $dbw->update(
156166 'article_feedback_pages',
157167 array(

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84535Step 2 of 2 for implementing expirations....tparscal17:18, 22 March 2011

Status & tagging log