r81180 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81179‎ | r81180 | r81181 >
Date:01:27, 29 January 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added expertise information to user interface, query and submission API.
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.css (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js (modified) (history)
  • /trunk/extensions/ArticleFeedback/sql/AddPropertiesTable.sql (modified) (history)
  • /trunk/extensions/ArticleFeedback/sql/AddPropertiesValueText.sql (added) (history)

Diff [purge]

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
14 + native
Index: trunk/extensions/ArticleFeedback/sql/AddPropertiesTable.sql
@@ -7,6 +7,9 @@
88
99 -- Key/value pairs
1010 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
1215 ) /*$wgDBTableOptions*/;
1316 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 @@
5252 'articlefeedback-form-switch-label',
5353 'articlefeedback-form-panel-title',
5454 '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',
5560 'articlefeedback-form-panel-submit',
5661 'articlefeedback-report-switch-label',
5762 'articlefeedback-report-panel-title',
@@ -111,6 +116,15 @@
112117 true
113118 ) );
114119 }
 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+ }
115129 $updater->addExtensionUpdate( array(
116130 'addTable',
117131 'article_feedback_properties',
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js
@@ -21,6 +21,15 @@
2222 <div style="clear:both;"></div>\
2323 <div class="articleFeedback-ratings"></div>\
2424 <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>\
2534 <button class="articleFeedback-submit articleFeedback-visibleWith-form" type="submit" disabled><html:msg key="form-panel-submit" /></button>\
2635 <div style="clear:both;"></div>\
2736 </div>\
@@ -80,6 +89,11 @@
8190 // Default to 0 if the radio set doesn't contain a checked element
8291 data['r' + id] = context.$ui.find( 'input[name=r' + id + ']:checked' ).val() || 0;
8392 }
 93+ var expertise = [];
 94+ context.$ui.find( '.articleFeedback-expertise input:checked' ).each( function() {
 95+ expertise.push( $(this).val() );
 96+ } );
 97+ data.expertise = expertise.join( '|' );
8498 $.ajax( {
8599 'url': mw.config.get( 'wgScriptPath' ) + '/api.php',
86100 'type': 'POST',
@@ -149,6 +163,17 @@
150164 mw.log( '<loadReport success with bad data />' );
151165 return;
152166 }
 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+ }
153178 context.$ui.find( '.articleFeedback-rating' ).each( function() {
154179 var ratingData;
155180 // Try to get data provided for this rating
@@ -300,6 +325,26 @@
301326 'delayOut': 100
302327 } )
303328 .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()
304349 // Buttonify the button
305350 .find( '.articleFeedback-submit' )
306351 .button()
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.css
@@ -214,3 +214,32 @@
215215 .articleFeedback-submit {
216216 float: right;
217217 }
 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 @@
183183 );
184184 }
185185 }
186 -
 186+
187187 /**
188188 * Inserts or updates properties for a specific rating
189189 * @param $revisionId int Revision ID
@@ -191,6 +191,7 @@
192192 * @param $params array Request parameters
193193 */
194194 private function insertProperties( $revisionId, $user, $token, $params ) {
 195+ // Expertise is given as a list of one or more tags, such as profession, hobby, etc.
195196 $this->insertProperty( $revisionId, $user, $token, 'expertise', $params['expertise'] );
196197 }
197198
@@ -210,7 +211,8 @@
211212 'afp_user_text' => $user->getName(),
212213 'afp_user_anon_token' => $token,
213214 '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,
215217 ),
216218 __METHOD__,
217219 array( 'IGNORE' )
@@ -218,7 +220,10 @@
219221
220222 if ( !$dbw->affectedRows() ) {
221223 $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+ ),
223228 array(
224229 'afp_revision' => $revisionId,
225230 'afp_user_text' => $user->getName(),
@@ -250,8 +255,8 @@
251256 ApiBase::PARAM_MIN => 1
252257 ),
253258 'expertise' => array(
254 - ApiBase::PARAM_TYPE => 'integer',
255 - )
 259+ ApiBase::PARAM_TYPE => 'string',
 260+ ),
256261 );
257262
258263 foreach( $wgArticleFeedbackRatings as $rating ) {
@@ -274,7 +279,7 @@
275280 'revid' => 'Revision ID to submit feedback for',
276281 'anontoken' => 'Token for anonymous users',
277282 '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',
279284 );
280285 foreach( $wgArticleFeedbackRatings as $rating ) {
281286 $ret["r{$rating}"] = "Rating {$rating}";
Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php
@@ -27,10 +27,15 @@
2828 if ( $params['userrating'] ) {
2929 global $wgUser;
3030
31 - $leftJoinConds = array(
 31+ $leftJoinCondsAF = array(
3232 'aa_page_id=aap_page_id',
3333 'aa_rating_id=aap_rating_id',
3434 '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' );
3540
3641 if ( $wgUser->isAnon() ) {
3742 if ( !isset( $params['anontoken'] ) ) {
@@ -39,16 +44,19 @@
4045 $this->dieUsage( 'The anontoken is not 32 characters', 'invalidtoken' );
4146 }
4247
43 - $leftJoinConds['aa_user_anon_token'] = $params['anontoken'];
 48+ $leftJoinCondsAF['aa_user_anon_token'] = $params['anontoken'];
 49+ } else {
 50+ $leftJoinCondsAF['aa_user_anon_token'] = '';
4451 }
4552
46 - $this->addTables( 'article_feedback' );
 53+ $this->addTables( array( 'article_feedback', 'article_feedback_properties' ) );
4754 $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 )
4957 )
5058 );
5159
52 - $this->addFields( array( 'aa_rating_value', 'aa_revision' ) );
 60+ $this->addFields( array( 'aa_rating_value', 'aa_revision', 'afp_value_text' ) );
5361
5462 $this->addOption( 'ORDER BY', 'aa_revision DESC' );
5563 }
@@ -71,6 +79,9 @@
7280
7381 if ( $params['userrating'] ) {
7482 $page['revid'] = $row->aa_revision;
 83+ if ( !is_null( $row->afp_value_text ) ) {
 84+ $page['expertise'] = $row->afp_value_text;
 85+ }
7586 }
7687
7788 $ratings[$pageId] = $page;
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php
@@ -30,6 +30,11 @@
3131 'articlefeedback-form-switch-label' => 'Rate this page',
3232 'articlefeedback-form-panel-title' => 'Rate this page',
3333 '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',
3439 'articlefeedback-form-panel-submit' => 'Submit feedback',
3540 'articlefeedback-report-switch-label' => 'View page ratings',
3641 'articlefeedback-report-panel-title' => 'Page ratings',

Status & tagging log