r103335 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103334‎ | r103335 | r103336 >
Date:16:25, 16 November 2011
Author:gregchiasson
Status:deferred (Comments)
Tags:
Comment:
Update database schema for AFTv5. Rename tables and set sensible prefixes. Pre-populate fields table. That enum probably still needs to go.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
@@ -1,232 +1,109 @@
22 -- TODO: Take the drops out before release, these are just for convenience while we're developing.
3 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback (
4 - -- Row ID (primary key)
5 - aa_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
6 - -- Foreign key to page.page_id
7 - aa_page_id integer unsigned NOT NULL,
8 - -- User Id (0 if anon)
9 - aa_user_id integer NOT NULL,
10 - -- Username or IP address
11 - aa_user_text varbinary(255) NOT NULL,
12 - -- Unique token for anonymous users (to facilitate ratings from multiple users on the same IP)
13 - aa_user_anon_token varbinary(32) NOT NULL DEFAULT '',
14 - -- Foreign key to revision.rev_id
15 - aa_revision_id integer unsigned NOT NULL,
16 - -- Which rating widget the user was given. Default of 0 is the "old" design
17 - aa_bucket_id int unsigned NOT NULL DEFAULT 0,
18 - -- Which CTA widget was displayed to the user. 0 is "none"
19 - -- Which would come up if they got the edit page CTA, and couldn't edit.
20 - aa_cta_id int unsigned NOT NULL DEFAULT 0,
21 - aa_created timestamp NULL DEFAULT CURRENT_TIMESTAMP,
22 - aa_modified timestamp NULL
23 -) /*$wgDBTableOptions*/;
24 -CREATE INDEX /*i*/aa_page_user_token_id ON /*_*/aft_article_feedback (aa_page_id, aa_user_text, aa_user_anon_token, aa_id);
25 -CREATE INDEX /*i*/aa_revision_id ON /*_*/aft_article_feedback (aa_revision_id);
26 -CREATE INDEX /*i*/article_feedback_timestamp ON /*_*/aft_article_feedback (aa_created);
27 -CREATE INDEX /*i*/aa_page_id ON /*_*/aft_article_feedback (aa_page_id, aa_created);
 3+DROP TABLE IF EXISTS /*_*/aft_article_feedback;
 4+DROP TABLE IF EXISTS /*_*/aft_article_field_group;
 5+DROP TABLE IF EXISTS /*_*/aft_article_field;
 6+DROP TABLE IF EXISTS /*_*/aft_article_field_option;
 7+DROP TABLE IF EXISTS /*_*/aft_article_answer;
 8+DROP TABLE IF EXISTS /*_*/aft_article_feedback_ratings_rollup;
 9+DROP TABLE IF EXISTS /*_*/aft_article_revision_feedback_ratings_rollup;
 10+DROP TABLE IF EXISTS /*_*/aft_article_feedback_select_rollup;
 11+DROP TABLE IF EXISTS /*_*/aft_article_revision_feedback_select_rollup;
 12+DROP TABLE IF EXISTS /*_*/aft_article_hits;
 13+DROP TABLE IF EXISTS /*_*/aft_article_feedback_properties;
2814
29 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_field_group (
30 - aafg_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
31 - aafg_name varchar(255) NOT NULL UNIQUE
32 -) /*$wgDBTableOptions*/;
33 -
34 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_field (
35 - aaf_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
36 - aaf_name varchar(255) NOT NULL UNIQUE,
37 - aaf_data_type ENUM('text', 'boolean', 'rating', 'select'),
38 - -- FKey to article_field_groups.group_id
39 - aafg_group_id integer unsigned NULL
40 -) /*$wgDBTableOptions*/;
41 -
42 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_field_option (
43 - aafo_option_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
44 - aafo_name varchar(255) NOT NULL
45 -) /*$wgDBTableOptions*/;
46 -
47 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_answer (
48 - -- FKEY to article_feedback.aa_id)
49 - aaaa_feedback_id integer unsigned NOT NULL,
50 - -- FKEY to article_fields.article_field_id)
51 - aaaa_field_id integer unsigned NOT NULL,
52 - aaaa_response_rating integer NULL,
53 - aaaa_response_text text NULL,
54 - aaaa_response_boolean boolean NULL,
55 - -- FKey to article_field_options.option_id)
56 - aaaa_response_option_id integer unsigned NULL,
57 - PRIMARY KEY (aaaa_feedback_id, aaaa_field_id)
58 -) /*$wgDBTableOptions*/;
59 -
60 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback_ratings_rollup (
61 - aap_page_id integer unsigned NOT NULL,
62 - aap_rating_id integer unsigned NOT NULL,
63 - aap_total integer unsigned NOT NULL,
64 - aap_count integer unsigned NOT NULL,
65 - PRIMARY KEY (aap_page_id, aap_rating_id)
66 -) /*$wgDBTableOptions*/;
67 -
68 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_revision_feedback_ratings_rollup (
69 - afr_page_id integer unsigned NOT NULL,
70 - afr_revision_id integer unsigned NOT NULL,
71 - afr_rating_id integer unsigned NOT NULL,
72 - afr_total integer unsigned NOT NULL,
73 - afr_count integer unsigned NOT NULL,
74 - PRIMARY KEY (afr_page_id, afr_rating_id, afr_revision_id)
75 -) /*$wgDBTableOptions*/;
76 -
77 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback_select_rollup (
78 - aafsr_page_id integer unsigned NOT NULL,
79 - aafsr_option_id integer unsigned NOT NULL,
80 - aafsr_total integer unsigned NOT NULL,
81 - aafsr_count integer unsigned NOT NULL,
82 - PRIMARY KEY (aafsr_page_id, aafsr_option_id)
83 -) /*$wgDBTableOptions*/;
84 -
85 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_revision_feedback_select_rollup (
86 - aarfsr_page_id integer unsigned NOT NULL,
87 - aarfsr_revision_id integer unsigned NOT NULL,
88 - aarfsr_option_id integer unsigned NOT NULL,
89 - aarfsr_total integer unsigned NOT NULL,
90 - aarfsr_count integer unsigned NOT NULL,
91 - PRIMARY KEY (aarfsr_revision_id, aarfsr_option_id)
92 -) /*$wgDBTableOptions*/;
93 -
94 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_hits (
95 - -- FKey to pages
96 - aah_page_id integer unsigned NOT NULL,
97 - -- Per fabrice, count by day, not by revision
98 - aah_date date NOT NULL,
99 - aah_bucket_id integer unsigned NOT NULL,
100 - aah_hits integer unsigned DEFAULT 0,
101 - PRIMARY KEY (aah_page_id, aah_date)
102 -) /*$wgDBTableOptions*/;
103 -
104 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback_properties (
105 - -- Keys to article_feedback.aa_id
106 - afp_feedback_id integer unsigned NOT NULL,
107 - -- Key/value pair - allow text or numerical metadata
108 - afp_key varbinary(255) NOT NULL,
109 - afp_value_int integer signed NOT NULL,
110 - afp_value_text varbinary(255) DEFAULT '' NOT NULL,
111 - PRIMARY KEY (afp_feedback_id, afp_key)
112 -) /*$wgDBTableOptions*/;
113 -
11415 CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback (
11516 -- Row ID (primary key)
116 - aa_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
 17+ af_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
11718 -- Foreign key to page.page_id
118 - aa_page_id integer unsigned NOT NULL,
 19+ af_page_id integer unsigned NOT NULL,
11920 -- User Id (0 if anon)
120 - aa_user_id integer NOT NULL,
 21+ af_user_id integer NOT NULL,
12122 -- Username or IP address
122 - aa_user_text varbinary(255) NOT NULL,
 23+ af_user_text varbinary(255) NOT NULL,
12324 -- Unique token for anonymous users (to facilitate ratings from multiple users on the same IP)
124 - aa_user_anon_token varbinary(32) NOT NULL DEFAULT '',
 25+ af_user_anon_token varbinary(32) NOT NULL DEFAULT '',
12526 -- Foreign key to revision.rev_id
126 - aa_revision_id integer unsigned NOT NULL,
 27+ af_revision_id integer unsigned NOT NULL,
12728 -- Which rating widget the user was given. Default of 0 is the "old" design
128 - aa_bucket_id int unsigned NOT NULL DEFAULT 0,
 29+ af_bucket_id int unsigned NOT NULL DEFAULT 0,
12930 -- Which CTA widget was displayed to the user. 0 is "none"
13031 -- Which would come up if they got the edit page CTA, and couldn't edit.
131 - aa_cta_id int unsigned NOT NULL DEFAULT 0,
132 - aa_created timestamp NULL DEFAULT CURRENT_TIMESTAMP,
133 - aa_modified timestamp NULL
 32+ af_cta_id int unsigned NOT NULL DEFAULT 0,
 33+ af_created timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 34+ af_modified timestamp NULL
13435 ) /*$wgDBTableOptions*/;
135 -CREATE INDEX /*i*/aa_page_user_token_id ON /*_*/aft_article_feedback (aa_page_id, aa_user_text, aa_user_anon_token, aa_id);
136 -CREATE INDEX /*i*/aa_revision_id ON /*_*/aft_article_feedback (aa_revision_id);
137 -CREATE INDEX /*i*/article_feedback_timestamp ON /*_*/aft_article_feedback (aa_created);
138 -CREATE INDEX /*i*/aa_page_id ON /*_*/aft_article_feedback (aa_page_id, aa_created);
 36+CREATE INDEX /*i*/af_page_user_token_id ON /*_*/aft_article_feedback (af_page_id, af_user_text, af_user_anon_token, af_id);
 37+CREATE INDEX /*i*/af_revision_id ON /*_*/aft_article_feedback (af_revision_id);
 38+-- Create an index on the article_feedback.af_timestamp field
 39+CREATE INDEX /*i*/article_feedback_timestamp ON /*_*/aft_article_feedback (af_created);
 40+CREATE INDEX /*i*/af_page_id ON /*_*/aft_article_feedback (af_page_id, af_created);
13941
14042 CREATE TABLE IF NOT EXISTS /*_*/aft_article_field_group (
141 - aafg_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
142 - aafg_name varchar(255) NOT NULL UNIQUE
 43+ afg_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
 44+ afg_name varchar(255) NOT NULL UNIQUE
14345 ) /*$wgDBTableOptions*/;
14446
 47+-- We already used af_ above, so this is ArticleFIeld instead
14548 CREATE TABLE IF NOT EXISTS /*_*/aft_article_field (
146 - aaf_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
147 - aaf_name varchar(255) NOT NULL UNIQUE,
148 - aaf_data_type ENUM('text', 'boolean', 'rating', 'select'),
149 - -- FKey to article_field_groups.group_id
150 - aafg_group_id integer unsigned NULL
 49+ afi_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
 50+ afi_name varchar(255) NOT NULL UNIQUE,
 51+ afi_data_type ENUM('text', 'boolean', 'rating', 'select'),
 52+ -- FKey to article_field_groups.group_id
 53+ afi_group_id integer unsigned NULL
15154 ) /*$wgDBTableOptions*/;
15255
15356 CREATE TABLE IF NOT EXISTS /*_*/aft_article_field_option (
154 - aafo_option_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
155 - aafo_name varchar(255) NOT NULL
 57+ afo_option_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
 58+ afo_name varchar(255) NOT NULL
15659 ) /*$wgDBTableOptions*/;
15760
15861 CREATE TABLE IF NOT EXISTS /*_*/aft_article_answer (
159 - -- FKEY to article_feedback.aa_id)
160 - aaaa_feedback_id integer unsigned NOT NULL,
161 - -- FKEY to article_fields.article_field_id)
162 - aaaa_field_id integer unsigned NOT NULL,
163 - aaaa_response_rating integer NULL,
164 - aaaa_response_text text NULL,
165 - aaaa_response_boolean boolean NULL,
166 - -- FKey to article_field_options.option_id)
167 - aaaa_response_option_id integer unsigned NULL,
168 - PRIMARY KEY (aaaa_feedback_id, aaaa_field_id)
 62+ -- FKEY to article_feedback.aa_id)
 63+ aa_feedback_id integer unsigned NOT NULL,
 64+ -- FKEY to article_fields.article_field_id)
 65+ aa_field_id integer unsigned NOT NULL,
 66+ aa_response_rating integer NULL,
 67+ aa_response_text text NULL,
 68+ aa_response_boolean boolean NULL,
 69+ -- FKey to article_field_options.option_id)
 70+ aa_response_option_id integer unsigned NULL,
 71+ PRIMARY KEY (aa_feedback_id, aa_field_id)
16972 ) /*$wgDBTableOptions*/;
17073
17174 CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback_ratings_rollup (
172 - aap_page_id integer unsigned NOT NULL,
173 - aap_rating_id integer unsigned NOT NULL,
174 - aap_total integer unsigned NOT NULL,
175 - aap_count integer unsigned NOT NULL,
176 - PRIMARY KEY (aap_page_id, aap_rating_id)
 75+ arr_page_id integer unsigned NOT NULL,
 76+ arr_rating_id integer unsigned NOT NULL,
 77+ arr_total integer unsigned NOT NULL,
 78+ arr_count integer unsigned NOT NULL,
 79+ PRIMARY KEY (arr_page_id, arr_rating_id)
17780 ) /*$wgDBTableOptions*/;
17881
17982 CREATE TABLE IF NOT EXISTS /*_*/aft_article_revision_feedback_ratings_rollup (
180 - afr_page_id integer unsigned NOT NULL,
181 - afr_revision_id integer unsigned NOT NULL,
182 - afr_rating_id integer unsigned NOT NULL,
183 - afr_total integer unsigned NOT NULL,
184 - afr_count integer unsigned NOT NULL,
185 - PRIMARY KEY (afr_page_id, afr_rating_id, afr_revision_id)
 83+ afrr_page_id integer unsigned NOT NULL,
 84+ afrr_revision_id integer unsigned NOT NULL,
 85+ afrr_rating_id integer unsigned NOT NULL,
 86+ afrr_total integer unsigned NOT NULL,
 87+ afrr_count integer unsigned NOT NULL,
 88+ PRIMARY KEY (afrr_page_id, afrr_rating_id, afrr_revision_id)
18689 ) /*$wgDBTableOptions*/;
18790
18891 CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback_select_rollup (
189 - aafsr_page_id integer unsigned NOT NULL,
190 - aafsr_option_id integer unsigned NOT NULL,
191 - aafsr_total integer unsigned NOT NULL,
192 - aafsr_count integer unsigned NOT NULL,
193 - PRIMARY KEY (aafsr_page_id, aafsr_option_id)
 92+ afsr_page_id integer unsigned NOT NULL,
 93+ afsr_option_id integer unsigned NOT NULL,
 94+ afsr_total integer unsigned NOT NULL,
 95+ afsr_count integer unsigned NOT NULL,
 96+ PRIMARY KEY (afsr_page_id, afsr_option_id)
19497 ) /*$wgDBTableOptions*/;
19598
19699 CREATE TABLE IF NOT EXISTS /*_*/aft_article_revision_feedback_select_rollup (
197 - aarfsr_page_id integer unsigned NOT NULL,
198 - aarfsr_revision_id integer unsigned NOT NULL,
199 - aarfsr_option_id integer unsigned NOT NULL,
200 - aarfsr_total integer unsigned NOT NULL,
201 - aarfsr_count integer unsigned NOT NULL,
202 - PRIMARY KEY (aarfsr_revision_id, aarfsr_option_id)
 100+ arfsr_page_id integer unsigned NOT NULL,
 101+ arfsr_revision_id integer unsigned NOT NULL,
 102+ arfsr_option_id integer unsigned NOT NULL,
 103+ arfsr_total integer unsigned NOT NULL,
 104+ arfsr_count integer unsigned NOT NULL,
 105+ PRIMARY KEY (arfsr_revision_id, arfsr_option_id)
203106 ) /*$wgDBTableOptions*/;
204107
205 -CREATE TABLE IF NOT EXISTS /*_*/aft_article_hits (
206 - -- FKey to pages
207 - aah_page_id integer unsigned NOT NULL,
208 - -- Per fabrice, count by day, not by revision
209 - aah_date date NOT NULL,
210 - aah_bucket_id integer unsigned NOT NULL,
211 - aah_hits integer unsigned DEFAULT 0,
212 - PRIMARY KEY (aah_page_id, aah_date)
213 -) /*$wgDBTableOptions*/;
214 -
215108 -- Mostyl taken from avtV4
216109 CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback_properties (
217110 -- Keys to article_feedback.aa_id
@@ -240,7 +117,9 @@
241118
242119 -- TODO: Add indices
243120
244 -INSERT INTO aft_article_field(aaf_name, aaf_data_type) VALUES ('trustworthy', 'rating');
245 -INSERT INTO aft_article_field(aaf_name, aaf_data_type) VALUES ('objective', 'rating');
246 -INSERT INTO aft_article_field(aaf_name, aaf_data_type) VALUES ('complete', 'rating');
247 -INSERT INTO aft_article_field(aaf_name, aaf_data_type) VALUES ('wellwritten', 'rating');
 121+INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('trustworthy', 'rating');
 122+INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('objective', 'rating');
 123+INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('complete', 'rating');
 124+INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('wellwritten', 'rating');
 125+INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('expertise', 'boolean');
 126+INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('comment', 'text');
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
@@ -83,8 +83,12 @@
8484 // this number to ensure the new odds are applied to everyone, not just people who have yet to
8585 // be placed in a bucket.
8686 'buckets' => array(
87 - 'ignore' => 100,
88 - 'track' => 0,
 87+ 'one' => 16,
 88+ 'two' => 16,
 89+ 'three' => 16,
 90+ 'four' => 16,
 91+ 'five' => 16,
 92+ 'six' => 16,
8993 ),
9094 // This version number is added to all tracking event names, so that changes in the software
9195 // don't corrupt the data being collected. Bump this when you want to start a new "experiment".
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -31,19 +31,28 @@
3232 $revisionId = $params['revid'];
3333 $answers = $dbr->select(
3434 'aft_article_field',
35 - array('aaf_id', 'aaf_name', 'aaf_data_type'),
36 - array('aaf_name' => $keys),
 35+ array('afi_id', 'afi_name', 'afi_data_type'),
 36+ array('afi_name' => $keys),
3737 __METHOD__
3838 );
3939
4040 foreach($answers as $answer) {
41 - $type = $answer->aaf_data_type;
42 - $user_answers[] = array(
43 - 'aaaa_feedback_id' => $feedbackId,
44 - 'aaaa_field_id' => $answer->aaf_id,
45 - "aaaa_response_$type" => $params[$answer->aaf_name]
46 - );
 41+ $type = $answer->afi_data_type;
 42+ # TODO: validation
 43+ # rating: int between 1 and 5 (inclusive)
 44+ # boolean: 1 or 0
 45+ # option: option exists
 46+ # text: none (maybe xss encode)
 47+ if($params[$answer->afi_name]) {
 48+ $user_answers[] = array(
 49+ 'aa_feedback_id' => $feedbackId,
 50+ 'aa_field_id' => $answer->afi_id,
 51+ "aa_response_$type" => $params[$answer->afi_name]
 52+ );
 53+ }
4754 }
 55+error_log('user answers are');
 56+error_log(print_r($user_answers,1));
4857
4958 $ctaId = $this->saveUserRatings($user_answers, $feedbackId, $bucket);
5059 $this->updateRollupTables($pageId, $revisionId);
@@ -93,7 +102,7 @@
94103 if($scope != 'page' && $scope != 'revision') { return 0; }
95104
96105 # TODO
97 - $table = 'article_'.$rev.'_feedback_'.$type.'_rollup';
 106+ $table = 'aft_article_'.$rev.'_feedback_'.$type.'_rollup';
98107 }
99108
100109 public function getFeedbackId($params) {
@@ -114,19 +123,18 @@
115124 }
116125
117126 $dbw->insert('aft_article_feedback', array(
118 - 'aa_page_id' => $params['pageid'],
119 - 'aa_revision_id' => $revId,
120 - 'aa_created' => $timestamp,
121 - 'aa_user_id' => $wgUser->getId(),
122 - 'aa_user_text' => $wgUser->getName(),
123 - 'aa_user_anon_token' => $token,
124 - 'aa_bucket_id' => $bucket,
 127+ 'af_page_id' => $params['pageid'],
 128+ 'af_revision_id' => $revId,
 129+ 'af_created' => $timestamp,
 130+ 'af_user_id' => $wgUser->getId(),
 131+ 'af_user_text' => $wgUser->getName(),
 132+ 'af_user_anon_token' => $token,
 133+ 'af_bucket_id' => $bucket,
125134 ));
126135
127136 return $dbw->insertID();
128137 }
129138
130 -
131139 /**
132140 * Inserts the user's rating for a specific revision
133141 */
@@ -134,14 +142,12 @@
135143 $dbw = wfGetDB(DB_MASTER);
136144 $ctaId = $this->getCTAId($data, $bucket);
137145
138 - # TODO: Move these deleted rows to an archive table or flag
139 - # them as archived or something.
140146 $dbw->begin();
141 - $dbw->insert('aft_article_answer', $data, __METHOD__);
 147+ $dbw->insert( 'aft_article_answer', $data, __METHOD__ );
142148 $dbw->update(
143149 'aft_article_feedback',
144 - array( 'aa_cta_id' => $ctaId ),
145 - array( 'aa_id' => $feedbackId ),
 150+ array( 'af_cta_id' => $ctaId ),
 151+ array( 'af_id' => $feedbackId ),
146152 __METHOD__
147153 );
148154 $dbw->commit();
@@ -156,31 +162,28 @@
157163 public function getAllowedParams() {
158164 $ret = array(
159165 'pageid' => array(
160 - ApiBase::PARAM_TYPE => 'integer',
 166+ ApiBase::PARAM_TYPE => 'integer',
161167 ApiBase::PARAM_REQUIRED => true,
162 - ApiBase::PARAM_ISMULTI => false,
 168+ ApiBase::PARAM_ISMULTI => false,
163169 ),
164170 'revid' => array(
165 - ApiBase::PARAM_TYPE => 'integer',
 171+ ApiBase::PARAM_TYPE => 'integer',
166172 ApiBase::PARAM_REQUIRED => true,
167 - ApiBase::PARAM_ISMULTI => false,
 173+ ApiBase::PARAM_ISMULTI => false,
168174 ),
169175 'anontoken' => null,
170176 'bucket' => array(
171 - ApiBase::PARAM_TYPE => 'integer',
 177+ ApiBase::PARAM_TYPE => 'integer',
172178 ApiBase::PARAM_REQUIRED => true,
173 - ApiBase::PARAM_ISMULTI => false,
174 - ApiBase::PARAM_MIN => 0
 179+ ApiBase::PARAM_ISMULTI => false,
 180+ ApiBase::PARAM_MIN => 1
175181 ),
176 - 'expertise' => array(
177 - ApiBase::PARAM_TYPE => 'string',
178 - ),
179182 );
180183
181184 $fields = ApiArticleFeedbackv5Utils::getFields();
182185 foreach( $fields as $field ) {
183 - $ret[$field->aaf_name] = array(
184 - ApiBase::PARAM_TYPE => 'text',
 186+ $ret[$field->afi_name] = array(
 187+ ApiBase::PARAM_TYPE => 'string',
185188 ApiBase::PARAM_REQUIRED => false,
186189 ApiBase::PARAM_ISMULTI => false,
187190 );
@@ -200,7 +203,7 @@
201204 );
202205
203206 foreach( $fields as $f ) {
204 - $ret[$f->aaf_name] = 'Optional feedbackl field, only appears in certain "buckets".';
 207+ $ret[$f->afi_name] = 'Optional feedback field, only appears on certain "buckets".';
205208 }
206209
207210 return $ret;
@@ -226,7 +229,7 @@
227230
228231 protected function getExamples() {
229232 return array(
230 - 'api.php?action=articlefeedback'
 233+ 'api.php?action=articlefeedbackv5'
231234 );
232235 }
233236
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
@@ -6,64 +6,59 @@
77 public static function getAnonToken($params) {
88 global $wgUser;
99 $token = null;
10 - if ( $wgUser->isAnon() ) {
 10+ if ( $wgUser->isAnon() ) {
1111 # TODO: error handling
12 - if ( !isset( $params['anontoken'] ) ) {
 12+ if ( !isset( $params['anontoken'] ) ) {
1313 # $this->dieUsageMsg( array( 'missingparam', 'anontoken' ) );
14 - } elseif ( strlen( $params['anontoken'] ) != 32 ) {
 14+ } elseif ( strlen( $params['anontoken'] ) != 32 ) {
1515 # $this->dieUsage( 'The anontoken is not 32 characters', 'invalidtoken' );
16 - }
 16+ }
 17+ $token = $params['anontoken'];
 18+ } else {
 19+ $token = '';
 20+ }
1721
18 - $token = $params['anontoken'];
19 - } else {
20 - $token = '';
21 - }
22 -
2322 return $token;
2423 }
2524
26 - public static function isFeedbackEnabled($params) {
27 -return 1;
28 - global $wgArticleFeedbackNamespaces;
29 - $title = Title::newFromID( $params['pageid'] );
30 -error_log("page $title is ".$title->getNamespace());
31 - # TODO check user permissions
32 - if (
33 - // not an existing page?
34 - is_null( $title )
35 - // Namespace not a valid ArticleFeedback namespace?
36 - || !in_array( $title->getNamespace(), $wgArticleFeedbackv5Namespaces )
37 - // Page a redirect?
38 - || $title->isRedirect()
39 - ) {
40 - // ...then feedback diabled
41 - return 0;
42 - }
43 -
44 - return 1;
 25+ public static function isFeedbackEnabled($params) {
 26+ global $wgArticleFeedbackNamespaces;
 27+ $title = Title::newFromID( $params['pageid'] );
 28+ if (
 29+ // not an existing page?
 30+ is_null( $title )
 31+ // Namespace not a valid ArticleFeedback namespace?
 32+ || !in_array( $title->getNamespace(), $wgArticleFeedbackv5Namespaces )
 33+ // Page a redirect?
 34+ || $title->isRedirect()
 35+ ) {
 36+ // ...then feedback diabled
 37+ return 0;
4538 }
 39+ return 1;
 40+ }
4641
47 - public static function getRevisionId($pageId) {
48 - $dbr = wfGetDB( DB_SLAVE );
49 - $revId = $dbr->selectField(
50 - 'revision', 'rev_id',
51 - array( 'rev_page' => $pageId ),
52 - __METHOD__,
53 - array(
54 - 'ORDER BY' => 'rev_id DESC',
55 - 'LIMIT' => 1
56 - )
57 - );
 42+ public static function getRevisionId($pageId) {
 43+ $dbr = wfGetDB( DB_SLAVE );
 44+ $revId = $dbr->selectField(
 45+ 'revision', 'rev_id',
 46+ array( 'rev_page' => $pageId ),
 47+ __METHOD__,
 48+ array(
 49+ 'ORDER BY' => 'rev_id DESC',
 50+ 'LIMIT' => 1
 51+ )
 52+ );
5853
59 - return $revId;
60 - }
 54+ return $revId;
 55+ }
6156
62 - # TODO: Find a way to cache this, instesd of hitting the DB every pageload.
 57+ # TODO: use memcache
6358 public static function getFields() {
6459 $dbr = wfGetDB( DB_SLAVE );
6560 $rv = $dbr->select(
6661 'aft_article_field',
67 - array( 'aaf_name', 'aaf_id', 'aaf_data_type' )
 62+ array( 'afi_name', 'afi_id', 'afi_data_type' )
6863 );
6964
7065 return $rv;
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php
@@ -90,19 +90,19 @@
9191
9292 if ( $type == 'page' ) {
9393 $table = 'article_feedback_ratings_rollup';
94 - $prefix = 'aap';
 94+ $prefix = 'arr';
9595 } else {
9696 $table = 'article_revision_feedback_ratings_rollup';
97 - $prefix = 'afr';
98 - $where[] = 'afr_revision_id >= ' . $revisionLimit;
 97+ $prefix = 'afrr';
 98+ $where[] = 'afrr_revision_id >= ' . $revisionLimit;
9999 }
100100 $where[$prefix . '_page_id'] = $pageId;
101 - $where[] = $prefix . '_rating_id = aaf_id';
 101+ $where[] = $prefix . '_rating_id = afi_id';
102102
103103 $rows = $dbr->select(
104104 array( 'aft_' . $table, 'aft_article_field' ),
105105 array(
106 - 'aaf_name AS field_name',
 106+ 'afi_name AS field_name',
107107 $prefix . '_rating_id AS field_id',
108108 'SUM(' . $prefix . '_total) AS points',
109109 'SUM(' . $prefix . '_count) AS reviews',
@@ -110,7 +110,7 @@
111111 $where,
112112 __METHOD__,
113113 array(
114 - 'GROUP BY' => $prefix . '_rating_id, aaf_name'
 114+ 'GROUP BY' => $prefix . '_rating_id, afi_name'
115115 )
116116 );
117117

Follow-up revisions

RevisionCommit summaryAuthorDate
r104866Updated display bucketing config to include all six forms; Fixed mistaken rev...rsterbin15:53, 1 December 2011

Comments

#Comment by Johnduhart (talk | contribs)   03:31, 18 November 2011
+error_log('user answers are');
+error_log(print_r($user_answers,1));

Debugging code

Status & tagging log