Index: trunk/extensions/ArticleFeedback/sql/AddPropertiesValueText.sql |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +ALTER TABLE /*$wgDBprefix*/article_feedback_properties |
| 3 | + ADD afp_value_text varbinary(255) DEFAULT '' NOT NULL; |
\ No newline at end of file |
Property changes on: trunk/extensions/ArticleFeedback/sql/AddPropertiesValueText.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 4 | + native |
Index: trunk/extensions/ArticleFeedback/sql/AddPropertiesTable.sql |
— | — | @@ -7,6 +7,9 @@ |
8 | 8 | |
9 | 9 | -- Key/value pairs |
10 | 10 | afp_key varbinary(255) NOT NULL, |
11 | | - afp_value integer signed NOT NULL |
| 11 | + -- Integer value |
| 12 | + afp_value integer signed NOT NULL, |
| 13 | + -- Text value |
| 14 | + afp_value_text varbinary(255) DEFAULT '' NOT NULL |
12 | 15 | ) /*$wgDBTableOptions*/; |
13 | 16 | CREATE UNIQUE INDEX /*i*/afp_rating_key ON /*_*/article_feedback_properties (afp_revision, afp_user_text, afp_user_anon_token, afp_key); |
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php |
— | — | @@ -51,6 +51,11 @@ |
52 | 52 | 'articlefeedback-form-switch-label', |
53 | 53 | 'articlefeedback-form-panel-title', |
54 | 54 | 'articlefeedback-form-panel-instructions', |
| 55 | + 'articlefeedback-form-panel-expertise', |
| 56 | + 'articlefeedback-form-panel-expertise-studies', |
| 57 | + 'articlefeedback-form-panel-expertise-profession', |
| 58 | + 'articlefeedback-form-panel-expertise-hobby', |
| 59 | + 'articlefeedback-form-panel-expertise-other', |
55 | 60 | 'articlefeedback-form-panel-submit', |
56 | 61 | 'articlefeedback-report-switch-label', |
57 | 62 | 'articlefeedback-report-panel-title', |
— | — | @@ -111,6 +116,15 @@ |
112 | 117 | true |
113 | 118 | ) ); |
114 | 119 | } |
| 120 | + if ( !$db->fieldExists( 'article_feedback_properties', 'afp_value_text', __METHOD__ ) ) { |
| 121 | + $updater->addExtensionUpdate( array( |
| 122 | + 'addField', |
| 123 | + 'article_feedback_properties', |
| 124 | + 'afp_value_text', |
| 125 | + $dir . '/sql/AddPropertiesValueText.sql', |
| 126 | + true |
| 127 | + ) ); |
| 128 | + } |
115 | 129 | $updater->addExtensionUpdate( array( |
116 | 130 | 'addTable', |
117 | 131 | 'article_feedback_properties', |
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js |
— | — | @@ -21,6 +21,15 @@ |
22 | 22 | <div style="clear:both;"></div>\ |
23 | 23 | <div class="articleFeedback-ratings"></div>\ |
24 | 24 | <div style="clear:both;"></div>\ |
| 25 | + <div class="articleFeedback-expertise articleFeedback-visibleWith-form" >\ |
| 26 | + <input type="checkbox" value="general" /><label><html:msg key="form-panel-expertise" /></label>\ |
| 27 | + <div class="articleFeedback-expertise-options">\ |
| 28 | + <input type="checkbox" value="studies" /><label><html:msg key="form-panel-expertise-studies" /></label>\ |
| 29 | + <input type="checkbox" value="profession" /><label><html:msg key="form-panel-expertise-profession" /></label>\ |
| 30 | + <input type="checkbox" value="hobby" /><label><html:msg key="form-panel-expertise-hobby" /></label>\ |
| 31 | + <input type="checkbox" value="other" /><label><html:msg key="form-panel-expertise-other" /></label>\ |
| 32 | + </div>\ |
| 33 | + </div>\ |
25 | 34 | <button class="articleFeedback-submit articleFeedback-visibleWith-form" type="submit" disabled><html:msg key="form-panel-submit" /></button>\ |
26 | 35 | <div style="clear:both;"></div>\ |
27 | 36 | </div>\ |
— | — | @@ -80,6 +89,11 @@ |
81 | 90 | // Default to 0 if the radio set doesn't contain a checked element |
82 | 91 | data['r' + id] = context.$ui.find( 'input[name=r' + id + ']:checked' ).val() || 0; |
83 | 92 | } |
| 93 | + var expertise = []; |
| 94 | + context.$ui.find( '.articleFeedback-expertise input:checked' ).each( function() { |
| 95 | + expertise.push( $(this).val() ); |
| 96 | + } ); |
| 97 | + data.expertise = expertise.join( '|' ); |
84 | 98 | $.ajax( { |
85 | 99 | 'url': mw.config.get( 'wgScriptPath' ) + '/api.php', |
86 | 100 | 'type': 'POST', |
— | — | @@ -149,6 +163,17 @@ |
150 | 164 | mw.log( '<loadReport success with bad data />' ); |
151 | 165 | return; |
152 | 166 | } |
| 167 | + if ( 'expertise' in data.query.articlefeedback[0] ) { |
| 168 | + var $expertise = context.$ui.find( '.articleFeedback-expertise' ); |
| 169 | + var tags = data.query.articlefeedback[0].expertise.split( '|' ); |
| 170 | + for ( var i = 0; i < tags.length; i++ ) { |
| 171 | + $expertise.find( 'input:checkbox[value=' + tags[i] + ']' ) |
| 172 | + .attr( 'checked', true ); |
| 173 | + } |
| 174 | + if ( $expertise.find( 'input:checkbox[value=general]:checked' ).size() ) { |
| 175 | + $expertise.find( '.articleFeedback-expertise-options' ).show(); |
| 176 | + } |
| 177 | + } |
153 | 178 | context.$ui.find( '.articleFeedback-rating' ).each( function() { |
154 | 179 | var ratingData; |
155 | 180 | // Try to get data provided for this rating |
— | — | @@ -300,6 +325,26 @@ |
301 | 326 | 'delayOut': 100 |
302 | 327 | } ) |
303 | 328 | .end() |
| 329 | + .find( '.articleFeedback-expertise > input:checkbox' ) |
| 330 | + .change( function() { |
| 331 | + var $options = context.$ui.find( '.articleFeedback-expertise-options' ); |
| 332 | + if ( $(this).is( ':checked' ) ) { |
| 333 | + $options.slideDown(); |
| 334 | + } else { |
| 335 | + $options.slideUp(); |
| 336 | + $options.find( 'input:checkbox' ).attr( 'checked', false ); |
| 337 | + } |
| 338 | + } ) |
| 339 | + .end() |
| 340 | + .find( '.articleFeedback-expertise input:checkbox' ) |
| 341 | + .each( function() { |
| 342 | + var id = 'articleFeedback-expertise-' + $(this).attr( 'value' ); |
| 343 | + $(this) |
| 344 | + .attr( 'id', id ) |
| 345 | + .next() |
| 346 | + .attr( 'for', id ); |
| 347 | + } ) |
| 348 | + .end() |
304 | 349 | // Buttonify the button |
305 | 350 | .find( '.articleFeedback-submit' ) |
306 | 351 | .button() |
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.css |
— | — | @@ -214,3 +214,32 @@ |
215 | 215 | .articleFeedback-submit { |
216 | 216 | float: right; |
217 | 217 | } |
| 218 | + |
| 219 | +.articleFeedback-expertise { |
| 220 | + float: left; |
| 221 | + margin-bottom: 0.5em; |
| 222 | +} |
| 223 | + |
| 224 | +.articleFeedback-expertise input { |
| 225 | + float: left; |
| 226 | + margin-bottom: 0.5em; |
| 227 | + clear: both; |
| 228 | + cursor: pointer; |
| 229 | +} |
| 230 | + |
| 231 | +.articleFeedback-expertise label { |
| 232 | + margin-left: 0.25em; |
| 233 | + margin-bottom: 0.5em; |
| 234 | + float: left; |
| 235 | + line-height: 1.4em; |
| 236 | + cursor: pointer; |
| 237 | +} |
| 238 | + |
| 239 | +.articleFeedback-expertise-options { |
| 240 | + clear: both; |
| 241 | + display: none; |
| 242 | +} |
| 243 | + |
| 244 | +.articleFeedback-expertise-options input { |
| 245 | + margin-left: 2em; |
| 246 | +} |
Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php |
— | — | @@ -182,7 +182,7 @@ |
183 | 183 | ); |
184 | 184 | } |
185 | 185 | } |
186 | | - |
| 186 | + |
187 | 187 | /** |
188 | 188 | * Inserts or updates properties for a specific rating |
189 | 189 | * @param $revisionId int Revision ID |
— | — | @@ -191,6 +191,7 @@ |
192 | 192 | * @param $params array Request parameters |
193 | 193 | */ |
194 | 194 | private function insertProperties( $revisionId, $user, $token, $params ) { |
| 195 | + // Expertise is given as a list of one or more tags, such as profession, hobby, etc. |
195 | 196 | $this->insertProperty( $revisionId, $user, $token, 'expertise', $params['expertise'] ); |
196 | 197 | } |
197 | 198 | |
— | — | @@ -210,7 +211,8 @@ |
211 | 212 | 'afp_user_text' => $user->getName(), |
212 | 213 | 'afp_user_anon_token' => $token, |
213 | 214 | 'afp_key' => $key, |
214 | | - 'afp_value' => $value |
| 215 | + 'afp_value' => is_int( $value ) ? $value : null, |
| 216 | + 'afp_value_text' => !is_int( $value ) ? strval( $value ) : null, |
215 | 217 | ), |
216 | 218 | __METHOD__, |
217 | 219 | array( 'IGNORE' ) |
— | — | @@ -218,7 +220,10 @@ |
219 | 221 | |
220 | 222 | if ( !$dbw->affectedRows() ) { |
221 | 223 | $dbw->update( 'article_feedback_properties', |
222 | | - array( 'afp_value' => $value ), |
| 224 | + array( |
| 225 | + 'afp_value' => is_int( $value ) ? $value : null, |
| 226 | + 'afp_value_text' => !is_int( $value ) ? strval( $value ) : null, |
| 227 | + ), |
223 | 228 | array( |
224 | 229 | 'afp_revision' => $revisionId, |
225 | 230 | 'afp_user_text' => $user->getName(), |
— | — | @@ -250,8 +255,8 @@ |
251 | 256 | ApiBase::PARAM_MIN => 1 |
252 | 257 | ), |
253 | 258 | 'expertise' => array( |
254 | | - ApiBase::PARAM_TYPE => 'integer', |
255 | | - ) |
| 259 | + ApiBase::PARAM_TYPE => 'string', |
| 260 | + ), |
256 | 261 | ); |
257 | 262 | |
258 | 263 | foreach( $wgArticleFeedbackRatings as $rating ) { |
— | — | @@ -274,7 +279,7 @@ |
275 | 280 | 'revid' => 'Revision ID to submit feedback for', |
276 | 281 | 'anontoken' => 'Token for anonymous users', |
277 | 282 | 'bucket' => 'Which rating widget was shown to the user', |
278 | | - 'expertise' => 'Which expertise level the user claimed to have', |
| 283 | + 'expertise' => 'What kinds of expertise does the user claim to have', |
279 | 284 | ); |
280 | 285 | foreach( $wgArticleFeedbackRatings as $rating ) { |
281 | 286 | $ret["r{$rating}"] = "Rating {$rating}"; |
Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php |
— | — | @@ -27,10 +27,15 @@ |
28 | 28 | if ( $params['userrating'] ) { |
29 | 29 | global $wgUser; |
30 | 30 | |
31 | | - $leftJoinConds = array( |
| 31 | + $leftJoinCondsAF = array( |
32 | 32 | 'aa_page_id=aap_page_id', |
33 | 33 | 'aa_rating_id=aap_rating_id', |
34 | 34 | 'aa_user_id=' . $wgUser->getId() ); |
| 35 | + $leftJoinCondsAFP = array( |
| 36 | + 'afp_revision=aa_revision', |
| 37 | + 'afp_user_text=aa_user_text', |
| 38 | + 'afp_user_anon_token=aa_user_anon_token', |
| 39 | + 'afp_key' => 'expertise' ); |
35 | 40 | |
36 | 41 | if ( $wgUser->isAnon() ) { |
37 | 42 | if ( !isset( $params['anontoken'] ) ) { |
— | — | @@ -39,16 +44,19 @@ |
40 | 45 | $this->dieUsage( 'The anontoken is not 32 characters', 'invalidtoken' ); |
41 | 46 | } |
42 | 47 | |
43 | | - $leftJoinConds['aa_user_anon_token'] = $params['anontoken']; |
| 48 | + $leftJoinCondsAF['aa_user_anon_token'] = $params['anontoken']; |
| 49 | + } else { |
| 50 | + $leftJoinCondsAF['aa_user_anon_token'] = ''; |
44 | 51 | } |
45 | 52 | |
46 | | - $this->addTables( 'article_feedback' ); |
| 53 | + $this->addTables( array( 'article_feedback', 'article_feedback_properties' ) ); |
47 | 54 | $this->addJoinConds( array( |
48 | | - 'article_feedback' => array( 'LEFT JOIN', $leftJoinConds ), |
| 55 | + 'article_feedback' => array( 'LEFT JOIN', $leftJoinCondsAF ), |
| 56 | + 'article_feedback_properties' => array( 'LEFT JOIN', $leftJoinCondsAFP ) |
49 | 57 | ) |
50 | 58 | ); |
51 | 59 | |
52 | | - $this->addFields( array( 'aa_rating_value', 'aa_revision' ) ); |
| 60 | + $this->addFields( array( 'aa_rating_value', 'aa_revision', 'afp_value_text' ) ); |
53 | 61 | |
54 | 62 | $this->addOption( 'ORDER BY', 'aa_revision DESC' ); |
55 | 63 | } |
— | — | @@ -71,6 +79,9 @@ |
72 | 80 | |
73 | 81 | if ( $params['userrating'] ) { |
74 | 82 | $page['revid'] = $row->aa_revision; |
| 83 | + if ( !is_null( $row->afp_value_text ) ) { |
| 84 | + $page['expertise'] = $row->afp_value_text; |
| 85 | + } |
75 | 86 | } |
76 | 87 | |
77 | 88 | $ratings[$pageId] = $page; |
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php |
— | — | @@ -30,6 +30,11 @@ |
31 | 31 | 'articlefeedback-form-switch-label' => 'Rate this page', |
32 | 32 | 'articlefeedback-form-panel-title' => 'Rate this page', |
33 | 33 | 'articlefeedback-form-panel-instructions' => 'Please take a moment to rate this page.', |
| 34 | + 'articlefeedback-form-panel-expertise' => 'I have prior knowledge on this topic', |
| 35 | + 'articlefeedback-form-panel-expertise-studies' => 'I\'ve studied it', |
| 36 | + 'articlefeedback-form-panel-expertise-profession' => 'It\'s part of my profession', |
| 37 | + 'articlefeedback-form-panel-expertise-hobby' => 'It\'s related to my hobbies or interests', |
| 38 | + 'articlefeedback-form-panel-expertise-other' => 'The source of my knowledge is not listed here', |
34 | 39 | 'articlefeedback-form-panel-submit' => 'Submit feedback', |
35 | 40 | 'articlefeedback-report-switch-label' => 'View page ratings', |
36 | 41 | 'articlefeedback-report-panel-title' => 'Page ratings', |