Index: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql |
— | — | @@ -1,232 +1,109 @@ |
2 | 2 | -- 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; |
28 | 14 | |
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 | | - |
114 | 15 | CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback ( |
115 | 16 | -- 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, |
117 | 18 | -- Foreign key to page.page_id |
118 | | - aa_page_id integer unsigned NOT NULL, |
| 19 | + af_page_id integer unsigned NOT NULL, |
119 | 20 | -- User Id (0 if anon) |
120 | | - aa_user_id integer NOT NULL, |
| 21 | + af_user_id integer NOT NULL, |
121 | 22 | -- Username or IP address |
122 | | - aa_user_text varbinary(255) NOT NULL, |
| 23 | + af_user_text varbinary(255) NOT NULL, |
123 | 24 | -- 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 '', |
125 | 26 | -- Foreign key to revision.rev_id |
126 | | - aa_revision_id integer unsigned NOT NULL, |
| 27 | + af_revision_id integer unsigned NOT NULL, |
127 | 28 | -- 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, |
129 | 30 | -- Which CTA widget was displayed to the user. 0 is "none" |
130 | 31 | -- 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 |
134 | 35 | ) /*$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); |
139 | 41 | |
140 | 42 | 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 |
143 | 45 | ) /*$wgDBTableOptions*/; |
144 | 46 | |
| 47 | +-- We already used af_ above, so this is ArticleFIeld instead |
145 | 48 | 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 |
151 | 54 | ) /*$wgDBTableOptions*/; |
152 | 55 | |
153 | 56 | 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 |
156 | 59 | ) /*$wgDBTableOptions*/; |
157 | 60 | |
158 | 61 | 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) |
169 | 72 | ) /*$wgDBTableOptions*/; |
170 | 73 | |
171 | 74 | 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) |
177 | 80 | ) /*$wgDBTableOptions*/; |
178 | 81 | |
179 | 82 | 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) |
186 | 89 | ) /*$wgDBTableOptions*/; |
187 | 90 | |
188 | 91 | 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) |
194 | 97 | ) /*$wgDBTableOptions*/; |
195 | 98 | |
196 | 99 | 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) |
203 | 106 | ) /*$wgDBTableOptions*/; |
204 | 107 | |
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 | | - |
215 | 108 | -- Mostyl taken from avtV4 |
216 | 109 | CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback_properties ( |
217 | 110 | -- Keys to article_feedback.aa_id |
— | — | @@ -240,7 +117,9 @@ |
241 | 118 | |
242 | 119 | -- TODO: Add indices |
243 | 120 | |
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 @@ |
84 | 84 | // this number to ensure the new odds are applied to everyone, not just people who have yet to |
85 | 85 | // be placed in a bucket. |
86 | 86 | '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, |
89 | 93 | ), |
90 | 94 | // This version number is added to all tracking event names, so that changes in the software |
91 | 95 | // 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 @@ |
32 | 32 | $revisionId = $params['revid']; |
33 | 33 | $answers = $dbr->select( |
34 | 34 | '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), |
37 | 37 | __METHOD__ |
38 | 38 | ); |
39 | 39 | |
40 | 40 | 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 | + } |
47 | 54 | } |
| 55 | +error_log('user answers are'); |
| 56 | +error_log(print_r($user_answers,1)); |
48 | 57 | |
49 | 58 | $ctaId = $this->saveUserRatings($user_answers, $feedbackId, $bucket); |
50 | 59 | $this->updateRollupTables($pageId, $revisionId); |
— | — | @@ -93,7 +102,7 @@ |
94 | 103 | if($scope != 'page' && $scope != 'revision') { return 0; } |
95 | 104 | |
96 | 105 | # TODO |
97 | | - $table = 'article_'.$rev.'_feedback_'.$type.'_rollup'; |
| 106 | + $table = 'aft_article_'.$rev.'_feedback_'.$type.'_rollup'; |
98 | 107 | } |
99 | 108 | |
100 | 109 | public function getFeedbackId($params) { |
— | — | @@ -114,19 +123,18 @@ |
115 | 124 | } |
116 | 125 | |
117 | 126 | $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, |
125 | 134 | )); |
126 | 135 | |
127 | 136 | return $dbw->insertID(); |
128 | 137 | } |
129 | 138 | |
130 | | - |
131 | 139 | /** |
132 | 140 | * Inserts the user's rating for a specific revision |
133 | 141 | */ |
— | — | @@ -134,14 +142,12 @@ |
135 | 143 | $dbw = wfGetDB(DB_MASTER); |
136 | 144 | $ctaId = $this->getCTAId($data, $bucket); |
137 | 145 | |
138 | | - # TODO: Move these deleted rows to an archive table or flag |
139 | | - # them as archived or something. |
140 | 146 | $dbw->begin(); |
141 | | - $dbw->insert('aft_article_answer', $data, __METHOD__); |
| 147 | + $dbw->insert( 'aft_article_answer', $data, __METHOD__ ); |
142 | 148 | $dbw->update( |
143 | 149 | '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 ), |
146 | 152 | __METHOD__ |
147 | 153 | ); |
148 | 154 | $dbw->commit(); |
— | — | @@ -156,31 +162,28 @@ |
157 | 163 | public function getAllowedParams() { |
158 | 164 | $ret = array( |
159 | 165 | 'pageid' => array( |
160 | | - ApiBase::PARAM_TYPE => 'integer', |
| 166 | + ApiBase::PARAM_TYPE => 'integer', |
161 | 167 | ApiBase::PARAM_REQUIRED => true, |
162 | | - ApiBase::PARAM_ISMULTI => false, |
| 168 | + ApiBase::PARAM_ISMULTI => false, |
163 | 169 | ), |
164 | 170 | 'revid' => array( |
165 | | - ApiBase::PARAM_TYPE => 'integer', |
| 171 | + ApiBase::PARAM_TYPE => 'integer', |
166 | 172 | ApiBase::PARAM_REQUIRED => true, |
167 | | - ApiBase::PARAM_ISMULTI => false, |
| 173 | + ApiBase::PARAM_ISMULTI => false, |
168 | 174 | ), |
169 | 175 | 'anontoken' => null, |
170 | 176 | 'bucket' => array( |
171 | | - ApiBase::PARAM_TYPE => 'integer', |
| 177 | + ApiBase::PARAM_TYPE => 'integer', |
172 | 178 | ApiBase::PARAM_REQUIRED => true, |
173 | | - ApiBase::PARAM_ISMULTI => false, |
174 | | - ApiBase::PARAM_MIN => 0 |
| 179 | + ApiBase::PARAM_ISMULTI => false, |
| 180 | + ApiBase::PARAM_MIN => 1 |
175 | 181 | ), |
176 | | - 'expertise' => array( |
177 | | - ApiBase::PARAM_TYPE => 'string', |
178 | | - ), |
179 | 182 | ); |
180 | 183 | |
181 | 184 | $fields = ApiArticleFeedbackv5Utils::getFields(); |
182 | 185 | 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', |
185 | 188 | ApiBase::PARAM_REQUIRED => false, |
186 | 189 | ApiBase::PARAM_ISMULTI => false, |
187 | 190 | ); |
— | — | @@ -200,7 +203,7 @@ |
201 | 204 | ); |
202 | 205 | |
203 | 206 | 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".'; |
205 | 208 | } |
206 | 209 | |
207 | 210 | return $ret; |
— | — | @@ -226,7 +229,7 @@ |
227 | 230 | |
228 | 231 | protected function getExamples() { |
229 | 232 | return array( |
230 | | - 'api.php?action=articlefeedback' |
| 233 | + 'api.php?action=articlefeedbackv5' |
231 | 234 | ); |
232 | 235 | } |
233 | 236 | |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php |
— | — | @@ -6,64 +6,59 @@ |
7 | 7 | public static function getAnonToken($params) { |
8 | 8 | global $wgUser; |
9 | 9 | $token = null; |
10 | | - if ( $wgUser->isAnon() ) { |
| 10 | + if ( $wgUser->isAnon() ) { |
11 | 11 | # TODO: error handling |
12 | | - if ( !isset( $params['anontoken'] ) ) { |
| 12 | + if ( !isset( $params['anontoken'] ) ) { |
13 | 13 | # $this->dieUsageMsg( array( 'missingparam', 'anontoken' ) ); |
14 | | - } elseif ( strlen( $params['anontoken'] ) != 32 ) { |
| 14 | + } elseif ( strlen( $params['anontoken'] ) != 32 ) { |
15 | 15 | # $this->dieUsage( 'The anontoken is not 32 characters', 'invalidtoken' ); |
16 | | - } |
| 16 | + } |
| 17 | + $token = $params['anontoken']; |
| 18 | + } else { |
| 19 | + $token = ''; |
| 20 | + } |
17 | 21 | |
18 | | - $token = $params['anontoken']; |
19 | | - } else { |
20 | | - $token = ''; |
21 | | - } |
22 | | - |
23 | 22 | return $token; |
24 | 23 | } |
25 | 24 | |
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; |
45 | 38 | } |
| 39 | + return 1; |
| 40 | + } |
46 | 41 | |
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 | + ); |
58 | 53 | |
59 | | - return $revId; |
60 | | - } |
| 54 | + return $revId; |
| 55 | + } |
61 | 56 | |
62 | | - # TODO: Find a way to cache this, instesd of hitting the DB every pageload. |
| 57 | + # TODO: use memcache |
63 | 58 | public static function getFields() { |
64 | 59 | $dbr = wfGetDB( DB_SLAVE ); |
65 | 60 | $rv = $dbr->select( |
66 | 61 | 'aft_article_field', |
67 | | - array( 'aaf_name', 'aaf_id', 'aaf_data_type' ) |
| 62 | + array( 'afi_name', 'afi_id', 'afi_data_type' ) |
68 | 63 | ); |
69 | 64 | |
70 | 65 | return $rv; |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php |
— | — | @@ -90,19 +90,19 @@ |
91 | 91 | |
92 | 92 | if ( $type == 'page' ) { |
93 | 93 | $table = 'article_feedback_ratings_rollup'; |
94 | | - $prefix = 'aap'; |
| 94 | + $prefix = 'arr'; |
95 | 95 | } else { |
96 | 96 | $table = 'article_revision_feedback_ratings_rollup'; |
97 | | - $prefix = 'afr'; |
98 | | - $where[] = 'afr_revision_id >= ' . $revisionLimit; |
| 97 | + $prefix = 'afrr'; |
| 98 | + $where[] = 'afrr_revision_id >= ' . $revisionLimit; |
99 | 99 | } |
100 | 100 | $where[$prefix . '_page_id'] = $pageId; |
101 | | - $where[] = $prefix . '_rating_id = aaf_id'; |
| 101 | + $where[] = $prefix . '_rating_id = afi_id'; |
102 | 102 | |
103 | 103 | $rows = $dbr->select( |
104 | 104 | array( 'aft_' . $table, 'aft_article_field' ), |
105 | 105 | array( |
106 | | - 'aaf_name AS field_name', |
| 106 | + 'afi_name AS field_name', |
107 | 107 | $prefix . '_rating_id AS field_id', |
108 | 108 | 'SUM(' . $prefix . '_total) AS points', |
109 | 109 | 'SUM(' . $prefix . '_count) AS reviews', |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | $where, |
112 | 112 | __METHOD__, |
113 | 113 | array( |
114 | | - 'GROUP BY' => $prefix . '_rating_id, aaf_name' |
| 114 | + 'GROUP BY' => $prefix . '_rating_id, afi_name' |
115 | 115 | ) |
116 | 116 | ); |
117 | 117 | |