https://www.mediawiki.org/wiki/Special:Code/MediaWiki/103439

Revision: 103439
Author:   rsterbin
Date:     2011-11-17 03:19:01 +0000 (Thu, 17 Nov 2011)
Log Message:
-----------
Updated ratings info collection and display:
        - sql/ArticleFeedbackv5.sql:
                - Insert statements for aft_article_field now include the 
bucket id
                - Added inserts for the expertise detail fields of bucket 5 and 
for
                  bucket 1
        - ArticleFeedbackv5.php:
                - Updated to add $wgArticleFeedbackv5Bucket5RatingCategories --
                  basically just the names from aft_article_field with bucket 
id 5 and
                  data type rating, but pulling from the database wouldn't give 
us order
        - ArticleFeedbackv5.hooks.php:
                - Updated resourceLoaderRegisterModules() and
                  resourceLoaderGetConfigVars() to use
                  $wgArticleFeedbackv5Bucket5RatingCategories rather than
                  $wgArticleFeedbackv5RatingTypes and
                  $wgArticleFeedbackv5RatingTypesFlipped
        - jquery.articleFeedbackv5.js:
                - Replaced wgArticleFeedbackv5RatingTypesFlipped with
                  wgArticleFeedbackv5Bucket5RatingCategories
                - Updated all uses to take into account the fact that it's a 
regular
                  index array rather than an associative one
                - Bucket 5 no longer uses the so-called rating id (really just 
an
                  index); instead it uses the name throughout
        - ext.articleFeedbackv5.js:
                Removed old use of wgArticleFeedbackv5RatingTypesFlipped
        - ApiViewRatingsArticleFeedbackv5:
                - Updated execute() to send the aggregate data indexed by field 
name
                  rather than id
                - Now only pulls aggregate data for bucket 5 (later versions 
may want
                  to pass in the bucket id instead of having it hardcoded)

Submit now works properly:
        - jquery.articleFeedbackv5.js:
                - Fixed collection of form data -- the fact that 
$('input:checked') is
                  not equivalent to $('input[checked]'), so radio buttons 
selected via
                  jquery and checkboxes selected manually must use different 
selectors
                - Added a value to the "yes" radio button
                - If you submit bucket 1 with the default text in the comment 
box, it
                  now sends an empty string rather than the default text
        - ApiArticleFeedbackv5:
                - Now makes use of ApiArticleFeedbackv5Utils::getFields() to 
collect
                  the appropriate answer fields
                - Corrected for coding style and added doc blocks
        - ApiArticleFeedbackv5Utils:
                - Updated getFields() to pull the bucket id as well
                - Updated isFeedbackEnabled() to return booleans rather than 
ints
                - Corrected for coding style and added doc blocks

Bug fix: Corrected the message tag for empty ratings
Bug fix: View ratings no longer shows an incorrect average

Modified Paths:
--------------
    trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
    trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
    trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
    trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
    trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php
    
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
    
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
    trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql

Modified: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php      
2011-11-17 03:14:05 UTC (rev 103438)
+++ trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php      
2011-11-17 03:19:01 UTC (rev 103439)
@@ -174,25 +174,24 @@
         * ResourceLoaderRegisterModules hook
         */
        public static function resourceLoaderRegisterModules( &$resourceLoader 
) {
-               global $wgExtensionAssetsPath;
+               global $wgExtensionAssetsPath,
+                       $wgArticleFeedbackv5Bucket5RatingCategories;
+
                $localpath = dirname( __FILE__ ) . '/modules';
                $remotepath = 
"$wgExtensionAssetsPath/ArticleFeedbackv5/modules";
 
                foreach ( self::$modules as $name => $resources ) {
                        if ( $name == 'jquery.articleFeedbackv5' ) {
                                // Bucket 5: labels and tooltips
-                               $fields = 
ApiArticleFeedbackv5Utils::getFields();
                                $prefix = 'articlefeedbackv5-bucket5-';
-                               foreach( $fields as $field ) {
-                                       if($fielf->afi_data_type == 'rating') {
-                                               $resources['messages'][] = 
$prefix . $field->afi_name . '-label';
-                                               $resources['messages'][] = 
$prefix . $field->afi_name . '-tip';
-                                               $resources['messages'][] = 
$prefix . $field->afi_name . '-tooltip-1';
-                                               $resources['messages'][] = 
$prefix . $field->afi_name . '-tooltip-2';
-                                               $resources['messages'][] = 
$prefix . $field->afi_name . '-tooltip-3';
-                                               $resources['messages'][] = 
$prefix . $field->afi_name . '-tooltip-4';
-                                               $resources['messages'][] = 
$prefix . $field->afi_name . '-tooltip-5';
-                                       }
+                               foreach ( 
$wgArticleFeedbackv5Bucket5RatingCategories as $field ) {
+                                       $resources['messages'][] = $prefix . 
$field . '-label';
+                                       $resources['messages'][] = $prefix . 
$field . '-tip';
+                                       $resources['messages'][] = $prefix . 
$field . '-tooltip-1';
+                                       $resources['messages'][] = $prefix . 
$field . '-tooltip-2';
+                                       $resources['messages'][] = $prefix . 
$field . '-tooltip-3';
+                                       $resources['messages'][] = $prefix . 
$field . '-tooltip-4';
+                                       $resources['messages'][] = $prefix . 
$field . '-tooltip-5';
                                }
                        }
                        $resourceLoader->register(
@@ -211,6 +210,7 @@
                        $wgArticleFeedbackv5BlacklistCategories,
                        $wgArticleFeedbackv5LotteryOdds,
                        $wgArticleFeedbackv5Debug,
+                       $wgArticleFeedbackv5Bucket5RatingCategories,
                        $wgArticleFeedbackv5DisplayBuckets,
                        $wgArticleFeedbackv5Tracking,
                        $wgArticleFeedbackv5Options,
@@ -220,18 +220,13 @@
                $vars['wgArticleFeedbackv5BlacklistCategories'] = 
$wgArticleFeedbackv5BlacklistCategories;
                $vars['wgArticleFeedbackv5LotteryOdds'] = 
$wgArticleFeedbackv5LotteryOdds;
                $vars['wgArticleFeedbackv5Debug'] = $wgArticleFeedbackv5Debug;
+               $vars['wgArticleFeedbackv5Bucket5RatingCategories'] = 
$wgArticleFeedbackv5Bucket5RatingCategories;
                $vars['wgArticleFeedbackv5DisplayBuckets'] = 
$wgArticleFeedbackv5DisplayBuckets;
                $vars['wgArticleFeedbackv5Tracking'] = 
$wgArticleFeedbackv5Tracking;
                $vars['wgArticleFeedbackv5Options'] = 
$wgArticleFeedbackv5Options;
                $vars['wgArticleFeedbackv5Namespaces'] = 
$wgArticleFeedbackv5Namespaces;
                $vars['wgArticleFeedbackv5WhatsThisPage'] = wfMsgForContent( 
'articlefeedbackv5-bucket5-form-panel-explanation-link' );
                $vars['wgArticleFeedbackv5TermsPage'] = wfMsgForContent( 
'articlefeedbackv5-transparency-terms-url' );
-
-               $fields = ApiArticleFeedbackv5Utils::getFields();
-               foreach( $fields as $field ) {
-                       $vars['wgArticleFeedbackv5RatingTypes'][] = 
$field->afi_name;
-                       
$vars['wgArticleFeedbackv5RatingTypesFlipped'][$field->afi_name] = 
$field->afi_id;
-               }
                return true;
        }
 

Modified: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php    2011-11-17 
03:14:05 UTC (rev 103438)
+++ trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php    2011-11-17 
03:19:01 UTC (rev 103439)
@@ -47,6 +47,9 @@
 // default message.
 $wgArticleFeedbackv5Debug = true;
 
+// The rating categories for bucket 5 -- these MUST match the field names in 
the database.
+$wgArticleFeedbackv5Bucket5RatingCategories = array( 'trustworthy', 
'objective', 'complete', 'wellwritten' );
+
 // Bucket settings for display options
 $wgArticleFeedbackv5DisplayBuckets = array(
        // Users can fall into one of several display buckets (these are 
defined in
@@ -73,7 +76,6 @@
        'tracked' => true
 );
 
-
 // Bucket settings for tracking users
 $wgArticleFeedbackv5Tracking = array(
        // Not all users need to be tracked, but we do want to track some users 
over time - these
@@ -209,3 +211,4 @@
 // Special Page
 $wgSpecialPages['ArticleFeedbackv5'] = 'SpecialArticleFeedbackv5';
 $wgSpecialPageGroups['ArticleFeedbackv5'] = 'other';
+

Modified: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php     
2011-11-17 03:14:05 UTC (rev 103438)
+++ trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php     
2011-11-17 03:19:01 UTC (rev 103439)
@@ -1,17 +1,36 @@
 <?php
-# This file saves the data and all. The other one loads it.
+/**
+ * ApiArticleFeedbackv5 class
+ *
+ * @package    ArticleFeedback
+ * @subpackage Api
+ * @author     Greg Chiasson <[email protected]>
+ * @author     Reha Sterbin <[email protected]>
+ * @version    $Id$
+ */
+
+/**
+ * This saves the ratings
+ *
+ * @package    ArticleFeedback
+ * @subpackage Api
+ */
 class ApiArticleFeedbackv5 extends ApiBase {
+
+       /**
+        * Constructor
+        */
        public function __construct( $query, $moduleName ) {
                parent::__construct( $query, $moduleName, '' );
        }
 
+       /**
+        * Execute the API call: Save the form values
+        */
        public function execute() {
                global $wgUser, $wgArticleFeedbackv5SMaxage;
                $params = $this->extractRequestParams();
 
-error_log('saving form');
-error_log(print_r($params,1));
-
                // Anon token check
                $token = ApiArticleFeedbackv5Utils::getAnonToken( $params );
 
@@ -20,40 +39,44 @@
 #                      $this->dieUsage( 'ArticleFeedback is not enabled on 
this page', 'invalidpage' );
 #              }
 
-               $feedbackId   = $this->getFeedbackId($params);
+               $feedbackId   = $this->getFeedbackId( $params );
                $dbr          = wfGetDB( DB_SLAVE );
-               $keys         = array();
-               foreach($params as $key => $unused) { $keys[] = $key; }
-               $user_answers = array();
                $pageId       = $params['pageid'];
                $bucket       = $params['bucket'];
                $revisionId   = $params['revid'];
-               $answers      = $dbr->select(
-                       'aft_article_field',
-                       array('afi_id', 'afi_name', 'afi_data_type'),
-                       array('afi_name' => $keys),
-                       __METHOD__
-               );
 
-               foreach($answers as $answer) {
-                       $type  = $answer->afi_data_type;
-                       $value = $params[$answer->afi_name];
-                       if($value && $this->validateParam($value, $type)) {
-                               $user_answers[] = array(
-                                       'aa_feedback_id'    => $feedbackId,
-                                       'aa_field_id'       => $answer->afi_id,
-                                       "aa_response_$type" => $value
-                               );
+               $user_answers = array();
+               $fields = ApiArticleFeedbackv5Utils::getFields();
+               foreach ( $fields as $field ) {
+                       if ( $field->afi_bucket_id != $bucket ) {
+                               continue;
                        }
+                       if ( isset( $params[$field->afi_name] ) ) {
+                               $value = $params[$field->afi_name];
+                               $type  = $field->afi_data_type;
+                               if ( $value === '' ) {
+                                       continue;
+                               }
+                               if ( $this->validateParam( $value, $type ) ) {
+                                       $data = array(
+                                               'aa_feedback_id' => $feedbackId,
+                                               'aa_field_id'    => 
$field->afi_id,
+                                       );
+                                       foreach ( array( 'rating', 'text', 
'boolean', 'option_id' ) as $t ) {
+                                               $data["aa_response_$t"] = $t == 
$type ? $value : null;
+                                       }
+                                       $user_answers[] = $data;
+                               } else {
+                                       // TODO: ERROR
+                               }
+                       }
                }
-error_log('user answers are');
-error_log(print_r($user_answers,1));
 
-               $ctaId = $this->saveUserRatings($user_answers, $feedbackId, 
$bucket);
-               $this->updateRollupTables($pageId, $revisionId);
+               $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, 
$bucket );
+               $this->updateRollupTables( $pageId, $revisionId );
 
-               $squidUpdate = new SquidUpdate(array(
-                       wfAppendQuery(wfScript('api'), array(
+               $squidUpdate = new SquidUpdate( array(
+                       wfAppendQuery( wfScript( 'api' ), array(
                                'action'       => 'query',
                                'format'       => 'json',
                                'list'         => 'articlefeedback',
@@ -62,83 +85,100 @@
                                'afuserrating' => 0,
                                'maxage'       => 0,
                                'smaxage'      => $wgArticleFeedbackv5SMaxage
-                       ))
-               ));
+                       ) )
+               ) );
                $squidUpdate->doUpdate();
 
-               wfRunHooks('ArticleFeedbackChangeRating', array($params));
+               wfRunHooks( 'ArticleFeedbackChangeRating', array( $params ) );
 
-               $this->getResult()->addValue(null, $this->getModuleName(),
-                       array('result' => 'Success')
+               $this->getResult()->addValue(
+                       null,
+                       $this->getModuleName(),
+                       array( 'result' => 'Success' )
                );
        }
 
-       protected function validateParam($value, $type) {
+       /**
+        * Validates a value against a field type
+        *
+        * @param  $value mixed  the value
+        * @param  $type  string the field type
+        * @return bool whether this is okay
+        */
+       protected function validateParam( $value, $type ) {
                # rating: int between 1 and 5 (inclusive)
                # boolean: 1 or 0
                # option:  option exists
                # text:    none (maybe xss encode)
-               switch($type) {
+               switch ( $type ) {
                        case 'rating':
-                               if(preg_match('/^(1|2|3|4|5)$/', $value)) {
-                                       return 1;
+                               if ( preg_match( '/^(1|2|3|4|5)$/', $value ) ) {
+                                       return true;
                                }
                                break;
                        case 'boolean':
-                               if(preg_match('/^(1|0)$/', $value)) {
-                                       return 1;
+                               if ( preg_match( '/^(1|0)$/', $value ) ) {
+                                       return true;
                                }
                                break;
                        case 'option':
                                # TODO: check for option existance.
+                               break;
                        case 'text':
-                               return 1;
-                               break;
+                               return true;
                        default:
-                               return 0;
-                               break;
+                               return false;
                }
-
-               return 0;
+               return false;
        }
 
-       public function updateRollupTables($page, $revision) {
+       /**
+        * Update the rollup tables
+        *
+        * @param $page     int the page id
+        * @param $revision int the revision id
+        */
+       public function updateRollupTables( $page, $revision ) {
+# Select rollup doesn't work yet
 #              foreach( array( 'rating', 'boolean', 'select' ) as $type ) {
-#              foreach( array( 'rating', 'boolean' ) as $type ) {
-               foreach( array( 'rating' ) as $type ) {
+               foreach( array( 'rating', 'boolean' ) as $type ) {
                        $this->updateRollup( $page, $revision, $type );
                }
        }
 
-       # TODO: This breaks on the select/option_id type.
+       /**
+        * Update the rollup tables
+        *
+        * @param $page     int    the page id
+        * @param $revision int    the revision id
+        * @param $type     string the type (rating, select, or boolean)
+        */
        private function updateRollup($pageId, $revId, $type) {
                global $wgArticleFeedbackv5RatingLifetime;
                $dbr   = wfGetDB( DB_SLAVE );
                $dbw   = wfGetDB( DB_MASTER );
-               $limit = ApiArticleFeedbackv5Utils::getRevisionLimit($pageId);
+               $limit = ApiArticleFeedbackv5Utils::getRevisionLimit( $pageId );
 
                # sanity check
-               if( $type != 'rating' && $type != 'select' 
-                && $type != 'boolean' ) { return 0; }
+               if ( $type != 'rating' && $type != 'select' && $type != 
'boolean' ) {
+                       return 0;
+               }
 
                $rows = $dbr->select(
-                       array( 'aft_article_answer', 'aft_article_feedback', 
-                        'aft_article_field' ),
-                       array( 'aa_field_id', 
-                        "SUM(aa_response_$type) AS earned", 
-                        'COUNT(*) AS submits'),
+                       array( 'aft_article_answer', 'aft_article_feedback', 
'aft_article_field' ),
+                       array( 'aa_field_id', "SUM(aa_response_$type) AS 
earned", 'COUNT(*) AS submits' ),
                        array(
                                'afi_data_type'  => $type,
                                'af_page_id'     => $pageId,
                                'aa_feedback_id = af_id',
                                'afi_id = aa_field_id',
-                               "af_revision_id >= $limit"
+                               "af_revision_id >= $limit",
                        ),
                        __METHOD__,
                        array( 'GROUP BY' =>  'aa_field_id' )
                );
 
-               if( $type == 'select' ) {
+               if ( $type == 'select' ) {
                        $page_prefix = 'afsr_';
                        $rev_prefix  = 'arfsr_';
                } else {
@@ -148,76 +188,74 @@
                $page_data  = array();
                $rev_data   = array();
                $rev_table  = 'aft_article_revision_feedback_'
-                .( $type == 'select' ? 'select' : 'ratings' ).'_rollup'; 
+                       . ( $type == 'select' ? 'select' : 'ratings' )
+                       . '_rollup';
                $page_table = 'aft_article_feedback_'
-                .( $type == 'select' ? 'select' : 'ratings' ).'_rollup'; 
+                       . ( $type == 'select' ? 'select' : 'ratings' )
+                       . '_rollup';
 
-               foreach($rows as $row) {
-                       if($type == 'rating') {
-                               $points = $row->submits * 5;
-                       } else {
-                               $points = $row->submits;
-                       }
-
-                       if(!array_key_exists($row->aa_field_id, $page_data)) {
+               foreach ( $rows as $row ) {
+                       if ( !array_key_exists( $row->aa_field_id, $page_data ) 
) {
                                $page_data[$row->aa_field_id] = array(
-                                       $page_prefix.'page_id' => $pageId,
-                                       $page_prefix.'total'   => 0,
-                                       $page_prefix.'count'   => 0,
-                                       $page_prefix.($type == 'select' ? 
'option' : 'rating').'_id' => $row->aa_field_id
+                                       $page_prefix . 'page_id' => $pageId,
+                                       $page_prefix . 'total'   => 0,
+                                       $page_prefix . 'count'   => 0,
+                                       $page_prefix . ($type == 'select' ? 
'option' : 'rating') . '_id' => $row->aa_field_id
                                );
                        }
 
                        $rev_data[] = array(
-                               $rev_prefix.'page_id'     => $pageId,
-                               $rev_prefix.'revision_id' => $revId,
-                               $rev_prefix.'total'       => $row->earned,
-                               $rev_prefix.'count'       => $points,
-                               $rev_prefix.($type == 'select' ? 'option' : 
'rating').'_id' => $row->aa_field_id
+                               $rev_prefix . 'page_id'     => $pageId,
+                               $rev_prefix . 'revision_id' => $revId,
+                               $rev_prefix . 'total'       => $row->earned,
+                               $rev_prefix . 'count'       => $points,
+                               $rev_prefix . ($type == 'select' ? 'option' : 
'rating') . '_id' => $row->aa_field_id
                        );
                        $page_data[$row->aa_field_id][$page_prefix.'total'] += 
$row->earned;
-                       $page_data[$row->aa_field_id][$page_prefix.'count'] += 
$points;
+                       $page_data[$row->aa_field_id][$page_prefix.'count'] += 
$row->submits;
                }
 
-               # Hack becuse you can't use array keys or insert barfs.
-               $tmp = array();
-               foreach($page_data as $p) {
-                       $tmp[] = $p;
-               }
-               $page_data = $tmp;
-
                $dbw->begin();
                $dbw->delete( $rev_table, array(
-                       $rev_prefix.'page_id'     => $pageId,
-                       $rev_prefix.'revision_id' => $revId,
+                       $rev_prefix . 'page_id'     => $pageId,
+                       $rev_prefix . 'revision_id' => $revId,
+                       $rev_prefix . 'rating_id'   => array_keys( $page_data ),
                ) );
-               $dbw->insert( $rev_table,  $rev_data );
+               $dbw->insert( $rev_table, $rev_data );
                $dbw->delete( $page_table, array(
-                       $page_prefix.'page_id'     => $pageId,
+                       $page_prefix . 'page_id'   => $pageId,
+                       $page_prefix . 'rating_id' => array_keys( $page_data ),
                ) );
-               $dbw->insert( $page_table, $page_data );
+               $dbw->insert( $page_table, array_values ( $page_data ) );
 
                $dbw->commit();
        }
 
+       /**
+        * Gets the feedback id
+        *
+        * @param  $params array the parameters
+        * @return int the feedback id
+        */
        public function getFeedbackId($params) {
                global $wgUser;
                $dbw       = wfGetDB( DB_MASTER );
                $revId     = $params['revid'];
                $bucket    = $params['revid'];
-               $token     = ApiArticleFeedbackv5Utils::getAnonToken($params);
+               $token     = ApiArticleFeedbackv5Utils::getAnonToken( $params );
                $timestamp = $dbw->timestamp();
 
                # make sure we have a page/user
-               if(!$params['pageid'] || !$wgUser) { return null; }
+               if ( !$params['pageid'] || !$wgUser) {
+                       return null;
+               }
 
                # Fetch this if it wasn't passed in
-               if(!$revId) {
+               if ( !$revId ) {
                        $revId = 
ApiArticleFeedbackv5Utils::getRevisionId($params['pageid']);
-error_log('rev id?');
                }
 
-               $dbw->insert('aft_article_feedback', array(
+               $dbw->insert( 'aft_article_feedback', array(
                        'af_page_id'         => $params['pageid'],
                        'af_revision_id'     => $revId,
                        'af_created'         => $timestamp,
@@ -225,17 +263,22 @@
                        'af_user_text'       => $wgUser->getName(),
                        'af_user_anon_token' => $token,
                        'af_bucket_id'       => $bucket,
-               ));
+               ) );
 
                return $dbw->insertID();
        }
 
        /**
         * Inserts the user's rating for a specific revision
+        *
+        * @param  array $data       the data
+        * @param  int   $feedbackId the feedback id
+        * @param  int   $bucket     the bucket id
+        * @return int   the cta id
         */
-       private function saveUserRatings($data, $feedbackId, $bucket) {
-               $dbw   = wfGetDB(DB_MASTER);
-               $ctaId = $this->getCTAId($data, $bucket);
+       private function saveUserRatings( $data, $feedbackId, $bucket ) {
+               $dbw   = wfGetDB( DB_MASTER );
+               $ctaId = $this->getCTAId( $data, $bucket );
 
                $dbw->begin();
                $dbw->insert( 'aft_article_answer', $data, __METHOD__ );
@@ -250,10 +293,22 @@
                return $ctaId;
        }
 
+       /**
+        * Picks a CTA to send the user to
+        *
+        * @param  $answers array the user's answers
+        * @param  $bucket  int   the bucket id
+        * @return int the cta id
+        */
        public function getCTAId($answers, $bucket) {
-           return 1; # Hard-code this for now.
+               return 1; # Hard-code this for now.
        }
 
+       /**
+        * Gets the allowed parameters
+        *
+        * @return array the params info, indexed by allowed key
+        */
        public function getAllowedParams() {
                $ret = array(
                        'pageid' => array(
@@ -276,7 +331,7 @@
                );
 
                $fields = ApiArticleFeedbackv5Utils::getFields();
-               foreach( $fields as $field ) {
+               foreach ( $fields as $field ) {
                        $ret[$field->afi_name] = array(
                                ApiBase::PARAM_TYPE     => 'string',
                                ApiBase::PARAM_REQUIRED => false,
@@ -287,27 +342,45 @@
                return $ret;
        }
 
+       /**
+        * Gets the parameter descriptions
+        *
+        * @return array the descriptions, indexed by allowed key
+        */
        public function getParamDescription() {
-               $fields = ApiArticleFeedbackv5Utils::getFields();
-               $ret    = array(
+               $ret = array(
                        'pageid'    => 'Page ID to submit feedback for',
                        'revid'     => 'Revision ID to submit feedback for',
                        'anontoken' => 'Token for anonymous users',
                        'bucket'    => 'Which rating widget was shown to the 
user',
-                       'expertise' => 'What kinds of expertise does the user 
claim to have',
                );
-
-               foreach( $fields as $f ) {
-                   $ret[$f->afi_name] = 'Optional feedback field, only appears 
on certain "buckets".';
+               $fields = ApiArticleFeedbackv5Utils::getFields();
+               foreach ( $fields as $f ) {
+                       $ret[$f->afi_name] = 'Optional feedback field, only 
appears on certain "buckets".';
                }
-
                return $ret;
        }
 
+       /**
+        * Returns whether this API call is post-only
+        *
+        * @return bool
+        */
        public function mustBePosted() { return true; }
 
+       /**
+        * Returns whether this is a write call
+        *
+        * @return bool
+        */
        public function isWriteMode() { return true; }
 
+       /**
+        * TODO
+        * Gets a list of possible errors
+        *
+        * @return bool
+        */
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'missingparam', 'anontoken' ),
@@ -316,19 +389,37 @@
                ) );
        }
 
+       /**
+        * Gets a description
+        *
+        * @return string
+        */
        public function getDescription() {
                return array(
                        'Submit article feedback'
                );
        }
 
+       /**
+        * TODO
+        * Gets a list of examples
+        *
+        * @return array
+        */
        protected function getExamples() {
                return array(
                        'api.php?action=articlefeedbackv5'
                );
        }
 
+       /**
+        * Gets the version info
+        *
+        * @return string the SVN version info
+        */
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }
+
 }
+

Modified: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php        
2011-11-17 03:14:05 UTC (rev 103438)
+++ trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php        
2011-11-17 03:19:01 UTC (rev 103439)
@@ -1,9 +1,33 @@
 <?php
-# ApiArticleFeedback and ApiQueryArticleFeedback don't descend from the same
-# parent, which is why these are all static methods instead of just a parent
-# class with inheritable methods. I don't get it either.
+/**
+ * ApiViewRatingsArticleFeedbackv5 class
+ *
+ * @package    ArticleFeedback
+ * @subpackage Api
+ * @author     Greg Chiasson <[email protected]>
+ * @author     Reha Sterbin <[email protected]>
+ * @version    $Id: ApiViewRatingsArticleFeedbackv5.php 103335 2011-11-16 
16:25:53Z gregchiasson $
+ */
+
+/**
+ * Utility methods used by api calls
+ *
+ * ApiArticleFeedback and ApiQueryArticleFeedback don't descend from the same
+ * parent, which is why these are all static methods instead of just a parent
+ * class with inheritable methods. I don't get it either.
+ *
+ * @package    ArticleFeedback
+ * @subpackage Api
+ */
 class ApiArticleFeedbackv5Utils {
-       public static function getAnonToken($params) {
+
+       /**
+        * Gets the anonymous token from the params
+        *
+        * @param  $params array the params
+        * @return string the token, or null if the user is not anonymous
+        */
+       public static function getAnonToken( $params ) {
                global $wgUser;
                $token = null;
                if ( $wgUser->isAnon() ) {
@@ -17,11 +41,16 @@
                } else {
                        $token = '';
                }
-
                return $token;
        }
 
-       public static function isFeedbackEnabled($params) {
+       /**
+        * Returns whether feedback is enabled for this page
+        *
+        * @param  $params array the params
+        * @return bool
+        */
+       public static function isFeedbackEnabled( $params ) {
                global $wgArticleFeedbackNamespaces;
                $title = Title::newFromID( $params['pageid'] );
                if (
@@ -33,11 +62,17 @@
                        || $title->isRedirect()
                ) {
                        // ...then feedback diabled
-                       return 0;
+                       return false;
                }
-               return 1;
+               return true;
        }
 
+       /**
+        * Returns the revision limit for a page
+        *
+        * @param  $pageId int the page id
+        * @return int the revision limit
+        */
        public static function getRevisionLimit( $pageId ) {
                global $wgArticleFeedbackv5RatingLifetime;
                $dbr      = wfGetDB( DB_SLAVE );
@@ -51,11 +86,16 @@
                                'OFFSET'   => 
$wgArticleFeedbackv5RatingLifetime - 1
                        )
                );
-
-               return $revision ? intval($revision) : 0;
+               return $revision ? intval( $revision ) : 0;
        }
 
-       public static function getRevisionId($pageId) {
+       /**
+        * Gets the most recent revision id for a page id
+        *
+        * @param  $pageId int the page id
+        * @return int the revision id
+        */
+       public static function getRevisionId( $pageId ) {
                $dbr   = wfGetDB( DB_SLAVE );
                $revId = $dbr->selectField(
                        'revision', 'rev_id',
@@ -70,14 +110,21 @@
                return $revId;
        }
 
-       # TODO: use memcache
+       /**
+        * Gets the known feedback fields
+        *
+        * TODO: use memcache
+        *
+        * @return array the rows in the aft_article_field table
+        */
        public static function getFields() {
                $dbr = wfGetDB( DB_SLAVE );
                $rv  = $dbr->select(
                        'aft_article_field',
-                       array( 'afi_name', 'afi_id', 'afi_data_type' )
+                       array( 'afi_name', 'afi_id', 'afi_data_type', 
'afi_bucket_id' )
                );
-
                return $rv;
        }
+
 }
+

Modified: 
trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php  
2011-11-17 03:14:05 UTC (rev 103438)
+++ trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php  
2011-11-17 03:19:01 UTC (rev 103439)
@@ -43,7 +43,7 @@
 
                $info = array();
                foreach ( $rollup as $row ) {
-                       $info[$row->field_id] = array(
+                       $info[$row->field_name] = array(
                                'ratingdesc' => $row->field_name,
                                'ratingid'   => (int) $row->field_id,
                                'total'      => (int) $row->points,
@@ -98,6 +98,7 @@
                }
                $where[$prefix . '_page_id']  = $pageId;
                $where[] = $prefix . '_rating_id = afi_id';
+               $where['afi_bucket_id'] = 5; // TODO: Pass this in
 
                $rows  = $dbr->select(
                        array( 'aft_' . $table, 'aft_article_field' ),

Modified: 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
===================================================================
--- 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
   2011-11-17 03:14:05 UTC (rev 103438)
+++ 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
   2011-11-17 03:19:01 UTC (rev 103439)
@@ -213,7 +213,6 @@
 } )();
 
 var config = {
-       'ratings': mw.config.get( 'wgArticleFeedbackv5RatingTypesFlipped' ),
        'pitches': {
                'survey': {
                        'weight': 1,

Modified: 
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
===================================================================
--- 
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
     2011-11-17 03:14:05 UTC (rev 103438)
+++ 
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
     2011-11-17 03:19:01 UTC (rev 103439)
@@ -151,7 +151,7 @@
                                                        <div class="form-item" 
rel="yes" id="articleFeedbackv5-bucket1-toggle-wrapper-yes">\
                                                                <label 
for="articleFeedbackv5-bucket1-toggle-yes"><html:msg 
key="bucket1-toggle-found-yes-full" /></label>\
                                                                <span 
class="articleFeedbackv5-button-placeholder"><html:msg 
key="bucket1-toggle-found-yes" value="yes" /></span>\
-                                                               <input 
type="radio" name="toggle" id="articleFeedbackv5-bucket1-toggle-yes" 
class="query-button" />\
+                                                               <input 
type="radio" name="toggle" id="articleFeedbackv5-bucket1-toggle-yes" 
class="query-button" value="yes" />\
                                                        </div>\
                                                        <div class="form-item" 
rel="no" id="articleFeedbackv5-bucket1-toggle-wrapper-no">\
                                                                <label 
for="articleFeedbackv5-bucket1-toggle-no"><html:msg 
key="bucket1-toggle-found-no-full" /></label>\
@@ -238,7 +238,7 @@
                                                $other_wrap.find( 'span' 
).removeClass( 'articleFeedbackv5-button-placeholder-active' );
                                                // check/uncheck radio buttons
                                                $wrap.find( 'input' ).attr( 
'checked', 'checked' );
-                                               $other_wrap.find( 'input' 
).attr( 'checked', '' );
+                                               $other_wrap.find( 'input' 
).removeAttr( 'checked' );
                                                // set default comment message
                                                var $txt = 
$.articleFeedbackv5.$holder.find( '.articleFeedbackv5-comment textarea' );
                                                var def_msg_yes = mw.msg( 
'articlefeedbackv5-bucket1-question-comment-yes' );
@@ -254,7 +254,7 @@
                                $block.find( '.articleFeedbackv5-comment 
textarea' )
                                        .focus( function () {
                                                var def_msg = '';
-                                               var val = 
$.articleFeedbackv5.$holder.find( '.articleFeedbackv5-bucket1-toggle 
input:checked' ).val();
+                                               var val = 
$.articleFeedbackv5.$holder.find( '.articleFeedbackv5-bucket1-toggle 
input[checked]' ).val();
                                                if ( val == 'yes' ) {
                                                        def_msg = mw.msg( 
'articlefeedbackv5-bucket1-question-comment-yes' );
                                                } else if ( val == 'no' ) {
@@ -266,7 +266,7 @@
                                        } )
                                        .blur( function () {
                                                var def_msg = '';
-                                               var val = 
$.articleFeedbackv5.$holder.find( '.articleFeedbackv5-bucket1-toggle 
input:checked' ).val();
+                                               var val = 
$.articleFeedbackv5.$holder.find( '.articleFeedbackv5-bucket1-toggle 
input[checked]' ).val();
                                                if ( val == 'yes' ) {
                                                        def_msg = mw.msg( 
'articlefeedbackv5-bucket1-question-comment-yes' );
                                                } else if ( val == 'no' ) {
@@ -318,8 +318,14 @@
                         */
                        getFormData: function () {
                                var data = {};
-                               data.toggle = $.articleFeedbackv5.$holder.find( 
'.articleFeedbackv5-bucket1-toggle input:checked' ).val() == 'yes' ?  true : 
false;
+                               var $check = $.articleFeedbackv5.$holder.find( 
'.articleFeedbackv5-bucket1-toggle input[checked]' );
+                               data.found = $check.val() == 'yes' ?  1 : 0;
                                data.comment = 
$.articleFeedbackv5.$holder.find( '.articleFeedbackv5-comment textarea' ).val();
+                               var def_msg_yes = mw.msg( 
'articlefeedbackv5-bucket1-question-comment-yes' );
+                               var def_msg_no = mw.msg( 
'articlefeedbackv5-bucket1-question-comment-no' );
+                               if ( data.comment == def_msg_yes || 
data.comment == def_msg_no ) {
+                                       data.comment = '';
+                               }
                                return data;
                        },
 
@@ -335,7 +341,7 @@
                        localValidation: function ( formdata ) {
                                var error = {};
                                var ok = true;
-                               if ( $.articleFeedbackv5.$holder.find( 
'.articleFeedbackv5-bucket1-toggle input:checked' ).length < 1 ) {
+                               if ( $.articleFeedbackv5.$holder.find( 
'.articleFeedbackv5-bucket1-toggle input[checked]' ).length < 1 ) {
                                        error.toggle = 'Please select an 
option';
                                        ok = false;
                                }
@@ -393,7 +399,7 @@
                         * The ratings right now are coming from the config, 
but they really
                         * can't be configured.  Eventually, these should just 
be hardcoded.
                         */
-                       ratingInfo: mw.config.get( 
'wgArticleFeedbackv5RatingTypesFlipped' ),
+                       ratingInfo: mw.config.get( 
'wgArticleFeedbackv5Bucket5RatingCategories' ),
 
                        /**
                         * Only certain users can see the expertise checkboxes 
and email
@@ -465,7 +471,7 @@
                                var rating_tpl = '\
                                        <div class="articleFeedbackv5-rating">\
                                                <div 
class="articleFeedbackv5-label"></div>\
-                                               <input type="hidden" />\
+                                               <input type="hidden" name="" />\
                                                <div 
class="articleFeedbackv5-rating-labels articleFeedbackv5-visibleWith-form">\
                                                        <div 
class="articleFeedbackv5-rating-label" rel="1"></div>\
                                                        <div 
class="articleFeedbackv5-rating-label" rel="2"></div>\
@@ -489,7 +495,9 @@
 
                                // Add the ratings from the options
                                $block.find( '.articleFeedbackv5-ratings' 
).each( function () {
-                                       for ( var key in 
$.articleFeedbackv5.currentBucket().ratingInfo ) {
+                                       var info = 
$.articleFeedbackv5.currentBucket().ratingInfo;
+                                       for ( var i in info ) {
+                                               var key = info[i];
                                                var     tip_msg = 
'articlefeedbackv5-bucket5-' + key + '-tip';
                                                var label_msg = 
'articlefeedbackv5-bucket5-' + key + '-label';
                                                var $rtg = $( rating_tpl 
).attr( 'rel', key );
@@ -561,8 +569,7 @@
                                // Name the hidden rating fields
                                $block.find( '.articleFeedbackv5-rating' )
                                        .each( function () {
-                                               var name = 
$.articleFeedbackv5.currentBucket().ratingInfo[$(this).attr( 'rel' )];
-                                               $(this).find( 'input:hidden' ) 
.attr( 'name', 'r' + name );
+                                               $(this).find( 'input:hidden' ) 
.attr( 'name', $(this).attr( 'rel' ) );
                                        } );
 
                                // Hide the additional options, if the user's 
in a bucket that
@@ -841,8 +848,7 @@
                                                // Ratings
                                                
$.articleFeedbackv5.$holder.find( '.articleFeedbackv5-rating' ).each( function 
() {
                                                        var name = 
$(this).attr( 'rel' );
-                                                       var info = 
$.articleFeedbackv5.currentBucket().ratingInfo;
-                                                       var rating = name in 
info && info[name] in rollup ? rollup[info[name]] : null;
+                                                       var rating = name in 
rollup ? rollup[name] : null;
                                                        if (
                                                                rating !== null
                                                                && 'total' in 
rating
@@ -863,7 +869,7 @@
                                                                $(this).find( 
'.articleFeedbackv5-rating-meter div' )
                                                                        .css( 
'width', 0 );
                                                                $(this).find( 
'.articleFeedbackv5-rating-count' )
-                                                                       .text( 
mw.msg( 'articlefeedbackv5-report-empty' ) );
+                                                                       .text( 
mw.msg( 'articlefeedbackv5-bucket5-report-empty' ) );
                                                        }
                                                } );
 
@@ -902,15 +908,14 @@
                        getFormData: function () {
                                var data = {};
                                var info = 
$.articleFeedbackv5.currentBucket().ratingInfo;
-                               for ( var key in info ) {
-                                       var id = info[key];
-                                       data['r' + id] = 
$.articleFeedbackv5.$holder.find( 'input[name="r' + id + '"]' ).val();
+                               for ( var i in info ) {
+                                       var key = info[i];
+                                       data[key] = 
$.articleFeedbackv5.$holder.find( 'input[name="' + key + '"]' ).val();
                                }
-                               var expertise = [];
                                $.articleFeedbackv5.$holder.find( 
'.articleFeedbackv5-expertise input:checked' ).each( function () {
-                                       expertise.push( $(this).val() );
+                                       console.log($(this).is(':checked'));
+                                       data['expertise-' + $( this ).val()] = 
1;
                                } );
-                               data.expertise = expertise.join( '|' );
                                return data;
                        },
 
@@ -1486,9 +1491,3 @@
 
 } )( jQuery );
 
-
-
-
-
-
-

Modified: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
===================================================================
--- trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql        
2011-11-17 03:14:05 UTC (rev 103438)
+++ trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql        
2011-11-17 03:19:01 UTC (rev 103439)
@@ -97,12 +97,12 @@
 ) /*$wgDBTableOptions*/;
 
 CREATE TABLE IF NOT EXISTS /*_*/aft_article_revision_feedback_select_rollup (
-    arfsr_page_id     integer unsigned NOT NULL,
-    arfsr_revision_id integer unsigned NOT NULL,
-    arfsr_option_id   integer unsigned NOT NULL,
-    arfsr_total       integer unsigned NOT NULL,
-    arfsr_count       integer unsigned NOT NULL,
-    PRIMARY KEY (arfsr_revision_id, arfsr_option_id)
+       arfsr_page_id     integer unsigned NOT NULL,
+       arfsr_revision_id integer unsigned NOT NULL,
+       arfsr_option_id   integer unsigned NOT NULL,
+       arfsr_total       integer unsigned NOT NULL,
+       arfsr_count       integer unsigned NOT NULL,
+       PRIMARY KEY (arfsr_revision_id, arfsr_option_id)
 ) /*$wgDBTableOptions*/;
 
 -- Mostyl taken from avtV4
@@ -118,9 +118,15 @@
 
 -- TODO: Add indices
 
-INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('trustworthy', 
'rating');
-INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('objective', 
'rating');
-INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('complete', 
'rating');
-INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('wellwritten', 
'rating');
-INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('expertise', 
'boolean');
-INSERT INTO aft_article_field(afi_name, afi_data_type) VALUES ('comment', 
'text');
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('found', 'boolean', 1);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('comment', 'text', 1);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('trustworthy', 'rating', 5);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('objective', 'rating', 5);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('complete', 'rating', 5);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('wellwritten', 'rating', 5);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('expertise-general', 'boolean', 5);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('expertise-studies', 'boolean', 5);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('expertise-profession', 'boolean', 5);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('expertise-hobby', 'boolean', 5);
+INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES 
('expertise-other', 'boolean', 5);
+


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to