r72540 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72539‎ | r72540 | r72541 >
Date:14:52, 7 September 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Swap out count number for array of ratings


Could possibly use key (or some description) to give the api help parameters some more info. i18n key into wfMsg()/similar?
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiQueryArticleAssessment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.php
@@ -4,8 +4,8 @@
55 // then consider the last rating "stale"
66 $wgArticleAssessmentStaleCount = 5;
77
8 -// Number of "ratings" to store. Allows it to be a bit more dynamic
9 -$wgArticleAssessmentRatingCount = 4;
 8+// Array of the "ratings" id's to store. Allows it to be a bit more dynamic
 9+$wgArticleAssessmentRatings = array( 1, 2, 3, 4 );
1010
1111 // Which category the pages must belong to have the rating widget added (with _ in text)
1212 // Extension is "disabled" if this field is an empty string (as per default configuration)
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiQueryArticleAssessment.php
@@ -53,9 +53,9 @@
5454 $this->addOption( 'ORDER BY', 'aa_revision DESC' );
5555 }
5656
57 - global $wgArticleAssessmentRatingCount;
 57+ global $wgArticleAssessmentRatings;
5858
59 - $this->addOption( 'LIMIT', $wgArticleAssessmentRatingCount );
 59+ $this->addOption( 'LIMIT', count( $wgArticleAssessmentRatings ) );
6060
6161 $res = $this->select( __METHOD__ );
6262
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php
@@ -5,7 +5,7 @@
66 }
77
88 public function execute() {
9 - global $wgUser, $wgArticleAssessmentRatingCount;
 9+ global $wgUser, $wgArticleAssessmentRatings;
1010 $params = $this->extractRequestParams();
1111
1212 $token = array();
@@ -50,22 +50,22 @@
5151 $revisionId = $params['revid'];
5252
5353 // TODO: Fold for loop into foreach above?
54 - for ( $i = 1; $i <= $wgArticleAssessmentRatingCount; $i++ ) {
 54+ foreach( $wgArticleAssessmentRatings as $rating ) {
5555 $lastRating = 0;
56 - if ( isset( $lastRatings[$i] ) ) {
57 - $lastRating = $lastRatings[$i];
 56+ if ( isset( $lastRatings[$rating] ) ) {
 57+ $lastRating = $lastRatings[$rating];
5858 }
5959
6060 $thisRating = 0;
61 - if ( isset( $params["r{$i}"] ) ) {
62 - $thisRating = $params["r{$i}"];
 61+ if ( isset( $params["r{$rating}"] ) ) {
 62+ $thisRating = $params["r{$rating}"];
6363 }
6464
6565 $this->insertPageRating( $pageId, $i, ( $thisRating - $lastRating ),
6666 ( $lastRating == 0 && $thisRating != 0 )
6767 );
6868
69 - $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $i, $thisRating );
 69+ $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $rating, $thisRating );
7070 }
7171
7272 $r = array( 'result' => 'Success' );
@@ -164,7 +164,7 @@
165165 }
166166
167167 public function getAllowedParams() {
168 - global $wgArticleAssessmentRatingCount;
 168+ global $wgArticleAssessmentRatings;
169169 $ret = array(
170170 'pageid' => array(
171171 ApiBase::PARAM_TYPE => 'integer',
@@ -178,9 +178,9 @@
179179 ),
180180 'anontoken' => null,
181181 );
182 -
183 - for ( $i = 1; $i <= $wgArticleAssessmentRatingCount; $i++ ) {
184 - $ret["r{$i}"] = array(
 182+
 183+ foreach( $wgArticleAssessmentRatings as $rating ) {
 184+ $ret["r{$rating}"] = array(
185185 ApiBase::PARAM_TYPE => 'integer',
186186 ApiBase::PARAM_DFLT => 0,
187187 ApiBase::PARAM_MIN => 0,
@@ -191,14 +191,14 @@
192192 }
193193
194194 public function getParamDescription() {
195 - global $wgArticleAssessmentRatingCount;
 195+ global $wgArticleAssessmentRatings;
196196 $ret = array(
197197 'pageid' => 'Page ID to submit assessment for',
198198 'revid' => 'Revision ID to submit assessment for',
199199 'anontoken' => 'Token for anonymous users',
200200 );
201 - for ( $i = 1; $i <= $wgArticleAssessmentRatingCount; $i++ ) {
202 - $ret["r{$i}"] = "Rating {$i}";
 201+ foreach( $wgArticleAssessmentRatings as $rating ) {
 202+ $ret["r{$rating}"] = "Rating {$rating}";
203203 }
204204 return $ret;
205205 }

Comments

#Comment by Catrope (talk | contribs)   20:26, 7 September 2010

The queries should also be adapted to include 'aap_rating_id' => $wgArticleAssessmentRatings to prevent deprecated ratings from showing up and 'stealing' other ratings' slots.

#Comment by Reedy (talk | contribs)   23:57, 7 September 2010

Status & tagging log