Index: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql |
— | — | @@ -147,7 +147,10 @@ |
148 | 148 | PRIMARY KEY (afp_feedback_id, afp_key) |
149 | 149 | ) /*$wgDBTableOptions*/; |
150 | 150 | |
| 151 | +-- TODO: Add indicesafi_data_type); |
| 152 | +CREATE INDEX /*i*/af_page_revision ON /*_*/aft_article_feedback (af_page_id, af_revision_id); |
| 153 | +CREATE INDEX /*i*/afi_data_type ON /*_*/aft_article_field (afi_data_type); |
| 154 | +CREATE INDEX /*i*/aa_feedback_field_option ON /*_*/aft_article_answer (aa_feedback_id, aa_field_id, aa_response_option_id); |
151 | 155 | |
152 | 156 | INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES ('found', 'boolean', 1); |
153 | 157 | INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES ('comment', 'text', 1); |
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js |
— | — | @@ -2205,7 +2205,6 @@ |
2206 | 2206 | var data = $.extend( formdata, { |
2207 | 2207 | 'action': 'articlefeedbackv5', |
2208 | 2208 | 'format': 'json', |
2209 | | - 'anontoken': $.articleFeedbackv5.userId, |
2210 | 2209 | 'pageid': $.articleFeedbackv5.pageId, |
2211 | 2210 | 'revid': $.articleFeedbackv5.revisionId, |
2212 | 2211 | 'bucket': $.articleFeedbackv5.bucketId, |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php |
— | — | @@ -16,6 +16,8 @@ |
17 | 17 | * @subpackage Api |
18 | 18 | */ |
19 | 19 | class ApiArticleFeedbackv5 extends ApiBase { |
| 20 | + // Cache this, so we don't have to look it up every time. |
| 21 | + private $revision_limit = null; |
20 | 22 | |
21 | 23 | /** |
22 | 24 | * Constructor |
— | — | @@ -44,14 +46,15 @@ |
45 | 47 | $pageId = $params['pageid']; |
46 | 48 | $bucket = $params['bucket']; |
47 | 49 | $revisionId = $params['revid']; |
| 50 | + $error = null; |
| 51 | + $user_answers = array(); |
| 52 | + $fields = ApiArticleFeedbackv5Utils::getFields(); |
48 | 53 | $email_data = array( |
49 | 54 | 'ratingData' => array(), |
50 | 55 | 'pageID' => $pageId, |
51 | 56 | 'bucketId' => $bucket |
52 | 57 | ); |
53 | 58 | |
54 | | - $user_answers = array(); |
55 | | - $fields = ApiArticleFeedbackv5Utils::getFields(); |
56 | 59 | foreach ( $fields as $field ) { |
57 | 60 | if ( $field->afi_bucket_id != $bucket ) { |
58 | 61 | continue; |
— | — | @@ -73,11 +76,18 @@ |
74 | 77 | $user_answers[] = $data; |
75 | 78 | $email_data['ratingData'][$field->afi_name] = $value; |
76 | 79 | } else { |
77 | | - // TODO: ERROR |
| 80 | + $error = 'articlefeedbackv5-error-validation'; |
78 | 81 | } |
79 | 82 | } |
80 | 83 | } |
81 | 84 | |
| 85 | + if($error) { |
| 86 | + $this->getResult()->addValue( |
| 87 | + null, 'error', $error |
| 88 | + ); |
| 89 | + return; |
| 90 | + } |
| 91 | + |
82 | 92 | $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket ); |
83 | 93 | $this->updateRollupTables( $pageId, $revisionId ); |
84 | 94 | |
— | — | @@ -91,10 +101,8 @@ |
92 | 102 | wfAppendQuery( wfScript( 'api' ), array( |
93 | 103 | 'action' => 'query', |
94 | 104 | 'format' => 'json', |
95 | | - 'list' => 'articlefeedback', |
| 105 | + 'list' => 'articlefeedbackv5-view-ratings', |
96 | 106 | 'afpageid' => $pageId, |
97 | | - 'afanontoken' => '', |
98 | | - 'afuserrating' => 0, |
99 | 107 | 'maxage' => 0, |
100 | 108 | 'smaxage' => $wgArticleFeedbackv5SMaxage |
101 | 109 | ) ) |
— | — | @@ -183,11 +191,34 @@ |
184 | 192 | } |
185 | 193 | |
186 | 194 | /** |
| 195 | + * Cache result of ApiArticleFeedbackv5Utils::getRevisionLimit to avoid |
| 196 | + * multiple fetches. |
| 197 | + |
| 198 | + * @param $pageID int the page id |
| 199 | + * @return int the oldest revision to still count |
| 200 | + */ |
| 201 | + public function getRevisionLimit( $pageId ) { |
| 202 | + if( $this->revision_limit === null ) { |
| 203 | + $this->revision_limit = ApiArticleFeedbackv5Utils::getRevisionLimit( $pageId ); |
| 204 | + } |
| 205 | + return $this->revision_limit; |
| 206 | + } |
| 207 | + |
| 208 | + /** |
187 | 209 | * Update the rollup tables |
188 | 210 | * |
189 | 211 | * @param $page int the page id |
190 | 212 | * @param $revision int the revision id |
191 | 213 | * @param $type string the type (rating, select, or boolean) |
| 214 | + |
| 215 | + * Selects feedback across the last $wgArticleFeedbackv5RatingLifetime |
| 216 | + * revisions of this page, grouped by revisionId. Each revision row |
| 217 | + * is replaced, as well as the page-level one in that rollup, which is |
| 218 | + * the sum of all revision-level rollups. We don't know if the revision |
| 219 | + * window has changed, so every time we're checking for the relevent |
| 220 | + * revisions and replacing the page value, as old revisions fall out of |
| 221 | + * the window. |
| 222 | + |
192 | 223 | */ |
193 | 224 | private function updateRollup( $pageId, $revId, $type ) { |
194 | 225 | # sanity check |
— | — | @@ -198,7 +229,7 @@ |
199 | 230 | global $wgArticleFeedbackv5RatingLifetime; |
200 | 231 | $dbr = wfGetDB( DB_SLAVE ); |
201 | 232 | $dbw = wfGetDB( DB_MASTER ); |
202 | | - $limit = ApiArticleFeedbackv5Utils::getRevisionLimit( $pageId ); |
| 233 | + $limit = $this->getRevisionLimit( $pageId ); |
203 | 234 | $page_data = array(); |
204 | 235 | $rev_data = array(); |
205 | 236 | $rev_table = 'aft_article_revision_feedback_' |
— | — | @@ -239,13 +270,17 @@ |
240 | 271 | $group |
241 | 272 | ); |
242 | 273 | |
243 | | - # Fake the select counts, because we want to group by ughhh |
| 274 | + // We've already grouped by option_id, so in order to get |
| 275 | + // counts grouped by field_id, we need to sum them up here. |
| 276 | + // Necessary for select rollups, unused on ratings/booleans. |
244 | 277 | $totals = array(); |
245 | | - foreach ( $rows as $row ) { |
246 | | - if( !array_key_exists( $row->aa_field_id, $totals ) ) { |
247 | | - $totals[$row->aa_field_id] = 0; |
| 278 | + if( $type == 'option_id' ) { |
| 279 | + foreach ( $rows as $row ) { |
| 280 | + if( !array_key_exists( $row->aa_field_id, $totals ) ) { |
| 281 | + $totals[$row->aa_field_id] = 0; |
| 282 | + } |
| 283 | + $totals[$row->aa_field_id] += $row->earned; |
248 | 284 | } |
249 | | - $totals[$row->aa_field_id] += $row->earned; |
250 | 285 | } |
251 | 286 | |
252 | 287 | foreach ( $rows as $row ) { |
— | — | @@ -415,7 +450,6 @@ |
416 | 451 | ApiBase::PARAM_TYPE => 'integer', |
417 | 452 | ApiBase::PARAM_REQUIRED => true, |
418 | 453 | ), |
419 | | - 'anontoken' => null, |
420 | 454 | 'bucket' => array( |
421 | 455 | ApiBase::PARAM_TYPE => 'integer', |
422 | 456 | ApiBase::PARAM_REQUIRED => true, |