r85974 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85973‎ | r85974 | r85975 >
Date:18:46, 13 April 2011
Author:catrope
Status:ok
Tags:
Comment:
ArticleFeedback: Rename insertPageRating() to insertRevisionRating() and reintroduce insertPageRating() from an old copy from SVN. Followup to r85964
Modified paths:
  • /trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php
@@ -64,9 +64,11 @@
6565 $thisRating = intval( $params["r{$rating}"] );
6666 }
6767
68 - $this->insertPageRating( $pageId, $revisionId, $lastRevision, $rating, ( $thisRating - $lastRating ),
 68+ $this->insertRevisionRating( $pageId, $revisionId, $lastRevision, $rating, ( $thisRating - $lastRating ),
6969 $thisRating, $lastRating
7070 );
 71+
 72+ $this->insertPageRating( $pageId, $rating, ( $thisRating - $lastRating ), $thisRating, $lastRating );
7173
7274 $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $rating, $thisRating, $params['bucket'] );
7375 }
@@ -76,11 +78,70 @@
7779 $r = array( 'result' => 'Success' );
7880 $this->getResult()->addValue( null, $this->getModuleName(), $r );
7981 }
80 -
 82+
8183 /**
8284 * Inserts (or Updates, where appropriate) the aggregate page rating
8385 *
8486 * @param $pageId Integer: Page Id
 87+ * @param $ratingId Integer: Rating Id
 88+ * @param $updateAddition Integer: Difference between user's last rating (if applicable)
 89+ * @param $thisRating Integer|Boolean: Value of the Rating
 90+ * @param $lastRating Integer|Boolean: Value of the last Rating
 91+ */
 92+ private function insertPageRating( $pageId, $ratingId, $updateAddition, $thisRating, $lastRating ) {
 93+ $dbw = wfGetDB( DB_MASTER );
 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+ // Try to insert a new afp row for this page with zeroes in it
 114+ // Try will silently fail if the row already exists
 115+ $dbw->insert(
 116+ 'article_feedback_pages',
 117+ array(
 118+ 'aap_page_id' => $pageId,
 119+ 'aap_total' => 0,
 120+ 'aap_count' => 0,
 121+ 'aap_rating_id' => $ratingId,
 122+ ),
 123+ __METHOD__,
 124+ array( 'IGNORE' )
 125+ );
 126+
 127+ // We now know the row exists, so increment it
 128+ $dbw->update(
 129+ 'article_feedback_pages',
 130+ array(
 131+ 'aap_total = aap_total + ' . $updateAddition,
 132+ 'aap_count = aap_count + ' . $countChange,
 133+ ),
 134+ array(
 135+ 'aap_page_id' => $pageId,
 136+ 'aap_rating_id' => $ratingId,
 137+ ),
 138+ __METHOD__
 139+ );
 140+ }
 141+
 142+ /**
 143+ * Inserts (or Updates, where appropriate) the aggregate revision rating
 144+ *
 145+ * @param $pageId Integer: Page Id
85146 * @param $revisionId Integer: Revision Id
86147 * @param $lastRevision Integer: Revision Id of last rating
87148 * @param $ratingId Integer: Rating Id
@@ -88,7 +149,7 @@
89150 * @param $thisRating Integer|Boolean: Value of the Rating
90151 * @param $lastRating Integer|Boolean: Value of the last Rating
91152 */
92 - private function insertPageRating( $pageId, $revisionId, $lastRevision, $ratingId, $updateAddition, $thisRating, $lastRating ) {
 153+ private function insertRevisionRating( $pageId, $revisionId, $lastRevision, $ratingId, $updateAddition, $thisRating, $lastRating ) {
93154 $dbw = wfGetDB( DB_MASTER );
94155
95156 // Try to insert a new "totals" row for this page,rev,rating set

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85964ArticleFeedback: Revert most of r84535, removing aap_revision again. This wil...catrope17:58, 13 April 2011

Status & tagging log