r108470 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108469‎ | r108470 | r108471 >
Date:20:28, 9 January 2012
Author:catrope
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/ArticleFeedbackv5 (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
@@ -1030,7 +1030,10 @@
10311031 */
10321032 getFormData: function () {
10331033 var data = {};
1034 - data.rating = $.articleFeedbackv5.find( '.articleFeedbackv5-rating input:hidden' ).val();
 1034+ var rating = $.articleFeedbackv5.find( '.articleFeedbackv5-rating input:hidden' ).val();
 1035+ if ( '0' != rating ) {
 1036+ data.rating = rating;
 1037+ }
10351038 data.comment = $.articleFeedbackv5.find( '.articleFeedbackv5-comment textarea' ).val();
10361039 if ( data.comment == mw.msg( 'articlefeedbackv5-bucket3-comment-default' ) ) {
10371040 data.comment = '';
@@ -1723,7 +1726,10 @@
17241727 var info = $.articleFeedbackv5.currentBucket().ratingInfo;
17251728 for ( var i = 0; i < info.length; i++ ) {
17261729 var key = info[i];
1727 - data[key] = $.articleFeedbackv5.find( 'input[name="' + key + '"]' ).val();
 1730+ var val = $.articleFeedbackv5.find( 'input[name="' + key + '"]' ).val();
 1731+ if ( '0' != val ) {
 1732+ data[key] = val;
 1733+ }
17281734 }
17291735 $.articleFeedbackv5.find( '.articleFeedbackv5-expertise input:checked' ).each( function () {
17301736 data['expertise-' + $( this ).val()] = 1;
@@ -2547,7 +2553,7 @@
25482554 } else {
25492555 var msg;
25502556 if ( 'error' in data ) {
2551 - msg = data.error;
 2557+ msg = mw.msg( data.error );
25522558 } else {
25532559 msg = { info: mw.msg( 'articlefeedbackv5-error-unknown' ) };
25542560 }
@@ -2761,12 +2767,17 @@
27622768 */
27632769 $.articleFeedbackv5.markFormErrors = function ( errors ) {
27642770 if ( '_api' in errors ) {
2765 - if ( $.articleFeedbackv5.debug ) {
2766 - $.articleFeedbackv5.markTopError( errors._api.info );
 2771+ if ( typeof errors._api == 'object' ) {
 2772+ if ( 'info' in errors._api ) {
 2773+ mw.log( mw.msg( errors._api.info ) );
 2774+ } else {
 2775+ mw.log( mw.msg( 'articlefeedbackv5-error-submit' ) );
 2776+ }
 2777+ $.articleFeedbackv5.markTopError( mw.msg( 'articlefeedbackv5-error-submit' ) );
27672778 } else {
2768 - mw.log( mw.msg( 'articlefeedbackv5-error-submit' ) );
 2779+ mw.log( mw.msg( errors._api ) );
 2780+ $.articleFeedbackv5.markTopError( errors._api );
27692781 }
2770 - mw.log( mw.msg( errors._api.info ) );
27712782 } else {
27722783 mw.log( mw.msg( 'articlefeedbackv5-error-validation' ) );
27732784 if ( 'nofeedback' in errors ) {
Index: branches/wmf/1.18wmf1/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -41,7 +41,6 @@
4242 $this->dieUsage( 'ArticleFeedback is not enabled on this page', 'invalidpage' );
4343 }
4444
45 - $feedbackId = $this->newFeedback( $params );
4645 $dbr = wfGetDB( DB_SLAVE );
4746 $pageId = $params['pageid'];
4847 $bucket = $params['bucket'];
@@ -68,7 +67,6 @@
6968 }
7069 if ( $this->validateParam( $value, $type, $field['afi_id'] ) ) {
7170 $data = array(
72 - 'aa_feedback_id' => $feedbackId,
7371 'aa_field_id' => $field['afi_id'],
7472 );
7573 foreach ( array( 'rating', 'text', 'boolean', 'option_id' ) as $t ) {
@@ -88,8 +86,10 @@
8987 );
9088 return;
9189 }
 90+ $ratingIds = $this->saveUserRatings( $user_answers, $bucket, $params );
 91+ $ctaId = $ratingIds['cta_id'];
 92+ $feedbackId = $ratingIds['feedback_id'];
9293
93 - $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket );
9494 $this->updateRollupTables( $pageId, $revisionId, $user_answers );
9595
9696 if ( $params['email'] ) {
@@ -116,9 +116,9 @@
117117 null,
118118 $this->getModuleName(),
119119 array(
120 - 'result' => 'Success',
 120+ 'result' => 'Success',
121121 'feedback_id' => $feedbackId,
122 - 'cta_id' => $ctaId,
 122+ 'cta_id' => $ctaId,
123123 )
124124 );
125125 }
@@ -435,14 +435,18 @@
436436 }
437437
438438 /**
439 - * Creates a new feedback row and returns the id
 439+ * Creates a new feedback record and inserts the user's rating
 440+ * for a specific revision
440441 *
441 - * @param $params array the parameters
442 - * @return int the feedback id
 442+ * @param array $data the data
 443+ * @param int $feedbackId the feedback id
 444+ * @param int $bucket the bucket id
 445+ * @return int the cta id
443446 */
444 - public function newFeedback( $params ) {
 447+ private function saveUserRatings( $data, $bucket, $params ) {
445448 global $wgUser;
446449 $dbw = wfGetDB( DB_MASTER );
 450+ $ctaId = $this->getCTAId( $data, $bucket );
447451 $revId = $params['revid'];
448452 $bucket = $params['bucket'];
449453 $link = $params['link'];
@@ -473,6 +477,8 @@
474478 $revId = $title->getLatestRevID();
475479 }
476480
 481+ $dbw->begin();
 482+
477483 $dbw->insert( 'aft_article_feedback', array(
478484 'af_page_id' => $params['pageid'],
479485 'af_revision_id' => $revId,
@@ -484,22 +490,12 @@
485491 'af_link_id' => $link,
486492 ) );
487493
488 - return $dbw->insertID();
489 - }
 494+ $feedbackId = $dbw->insertID();
490495
491 - /**
492 - * Inserts the user's rating for a specific revision
493 - *
494 - * @param array $data the data
495 - * @param int $feedbackId the feedback id
496 - * @param int $bucket the bucket id
497 - * @return int the cta id
498 - */
499 - private function saveUserRatings( $data, $feedbackId, $bucket ) {
500 - $dbw = wfGetDB( DB_MASTER );
501 - $ctaId = $this->getCTAId( $data, $bucket );
 496+ foreach($data as $key => $item) {
 497+ $data[$key]['aa_feedback_id'] = $feedbackId;
 498+ }
502499
503 - $dbw->begin();
504500 $dbw->insert( 'aft_article_answer', $data, __METHOD__ );
505501 $dbw->update(
506502 'aft_article_feedback',
@@ -509,7 +505,10 @@
510506 );
511507 $dbw->commit();
512508
513 - return $ctaId;
 509+ return array(
 510+ 'cta_id' => ($ctaId ? $ctaId : 0),
 511+ 'feedback_id' => ($feedbackId ? $feedbackId : 0)
 512+ );
514513 }
515514
516515 /**
Property changes on: branches/wmf/1.18wmf1/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
___________________________________________________________________
Modified: svn:mergeinfo
517516 Merged /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php:r108239,108245,108247,108250,108269,108280
Property changes on: branches/wmf/1.18wmf1/extensions/ArticleFeedbackv5
___________________________________________________________________
Modified: svn:mergeinfo
518517 Merged /trunk/extensions/ArticleFeedbackv5:r108239,108245,108247,108250,108269,108280

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108239Bug fix: Empty ratings should not be sent as rating=0, but rather not include...rsterbin15:30, 6 January 2012
r108245Bug fix: when an error comes back from the submit api, it's a message token, ...rsterbin16:03, 6 January 2012
r108247AFTv5 - Refactor feedback/answer saving so we can get it all in one transacti...gregchiasson16:12, 6 January 2012
r108250Fixed the error messaging logic: a string in the api field is a message; an o...rsterbin16:23, 6 January 2012
r108269Debug code needs removingrsterbin19:15, 6 January 2012
r108280Dropped debug line from r108247rsterbin20:26, 6 January 2012

Status & tagging log