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

Revision: 103329
Author:   rsterbin
Date:     2011-11-16 15:25:31 +0000 (Wed, 16 Nov 2011)
Log Message:
-----------
Client-side bucketing:
        - ArticleFeedbackv5.php:
                - Added config for display bucketing
                  ($wgArticleFeedbackv5DisplayBuckets)
        - ArticleFeedbackv5.hooks.php
                - Added $wgArticleFeedbackv5DisplayBuckets to the config values
                  available to the modules
        - JQuery plugin:
                - $.articleFeedbackv5.loadForm() now uses mw.user.bucket() to 
get the
                  bucket id, rather than making an ajax api call
                - New cookie 'display-bucket' tracks the bucket last shown
        - Removed ApiQueryArticleFeedbackv5, since it's no longer needed

Debug mode now set in the config:
        - ArticleFeedbackv5.php:
                - Added config for debug mode ($wgArticleFeedbackv5Debug)
        - ArticleFeedbackv5.hooks.php
                - Added $wgArticleFeedbackv5Debug to the config values
                  available to the modules
        - $.articleFeedbackv5.debug now defaults to false and is set in
          $.articleFeedbackv5.init() from the config
        - Log the current bucket to the console only in debug mode
        - Passing the bucket in the query string is now debug-only

Bug fixes:
        - Edit link on CTA now goes to the right place
        - Renamed all cookies to be prefixed with 'articleFeedbackv5' rather 
than
          'articleFeedback'
        - Holder div id is now 'mw-articleFeedbackv5' rather than
          'mw-articleFeedback'

Modified Paths:
--------------
    trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
    trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
    
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
    
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.startup.js
    
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js

Removed Paths:
-------------
    trunk/extensions/ArticleFeedbackv5/api/ApiQueryArticleFeedbackv5.php

Modified: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php      
2011-11-16 15:21:44 UTC (rev 103328)
+++ trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php      
2011-11-16 15:25:31 UTC (rev 103329)
@@ -202,6 +202,8 @@
                        $wgArticleFeedbackv5Categories,
                        $wgArticleFeedbackv5BlacklistCategories,
                        $wgArticleFeedbackv5LotteryOdds,
+                       $wgArticleFeedbackv5Debug,
+                       $wgArticleFeedbackv5DisplayBuckets,
                        $wgArticleFeedbackv5Tracking,
                        $wgArticleFeedbackv5Options,
                        $wgArticleFeedbackv5Namespaces;
@@ -209,6 +211,8 @@
                $vars['wgArticleFeedbackv5Categories'] = 
$wgArticleFeedbackv5Categories;
                $vars['wgArticleFeedbackv5BlacklistCategories'] = 
$wgArticleFeedbackv5BlacklistCategories;
                $vars['wgArticleFeedbackv5LotteryOdds'] = 
$wgArticleFeedbackv5LotteryOdds;
+               $vars['wgArticleFeedbackv5Debug'] = $wgArticleFeedbackv5Debug;
+               $vars['wgArticleFeedbackv5DisplayBuckets'] = 
$wgArticleFeedbackv5DisplayBuckets;
                $vars['wgArticleFeedbackv5Tracking'] = 
$wgArticleFeedbackv5Tracking;
                $vars['wgArticleFeedbackv5Options'] = 
$wgArticleFeedbackv5Options;
                $vars['wgArticleFeedbackv5Namespaces'] = 
$wgArticleFeedbackv5Namespaces;

Modified: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php    2011-11-16 
15:21:44 UTC (rev 103328)
+++ trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php    2011-11-16 
15:25:31 UTC (rev 103329)
@@ -41,6 +41,39 @@
 // are the smallest increments used.
 $wgArticleFeedbackv5LotteryOdds = 0;
 
+// This puts the javascript into debug mode. In debug mode, you can set your
+// own bucket by passing it in the url (e.g., ?bucket=1), and the showstopper
+// error mode will have a useful error message, if one exists, rather than the
+// default message.
+$wgArticleFeedbackv5Debug = true;
+
+// Bucket settings for display options
+$wgArticleFeedbackv5DisplayBuckets = array(
+       // Users can fall into one of several display buckets (these are 
defined in
+       // modules/jquery.articlefeedbackv5/jquery.articlefeedbackv5.js).  When 
a
+       // user arrives at the page, this config will be used by core bucketing 
to
+       // decide which of the available form options they see.  Whenever 
there's
+       // an update to the available buckets, change the version number to 
ensure
+       // the new odds are applied to everyone, not just people who have yet 
to be
+       // placed in a bucket.
+       'buckets' => array(
+               '1' => 34,
+               '5' => 33,
+               '6' => 33,
+       ),
+       // This version number is added to all tracking event names, so that
+       // changes in the software don't corrupt the data being collected. Bump
+       // this when you want to start a new "experiment".
+       'version' => 0,
+       // Let users be tracked for a month, and then rebucket them, allowing 
some
+       // churn.
+       'expires' => 30,
+       // Track the event of users being bucketed - so we can be sure the odds
+       // worked out right.
+       '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

Deleted: trunk/extensions/ArticleFeedbackv5/api/ApiQueryArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/api/ApiQueryArticleFeedbackv5.php        
2011-11-16 15:21:44 UTC (rev 103328)
+++ trunk/extensions/ArticleFeedbackv5/api/ApiQueryArticleFeedbackv5.php        
2011-11-16 15:25:31 UTC (rev 103329)
@@ -1,309 +0,0 @@
-<?php
-/**
- * ApiQueryArticleFeedbackv5 class
- *
- * @package    ArticleFeedback
- * @subpackage Api
- * @author     Greg Chiasson <[email protected]>
- * @author     Reha Sterbin <[email protected]>
- * @version    $Id$
- */
-
-/**
- * This class loads data.  The other one saves it.
- *
- * @package    ArticleFeedback
- * @subpackage Api
- */
-class ApiQueryArticleFeedbackv5 extends ApiQueryBase {
-
-       /**
-        * Constructor
-        */
-       public function __construct( $query, $moduleName ) {
-               parent::__construct( $query, $moduleName, 'af' );
-       }
-
-       /**
-        * Execute the API call: initialize a brand new request
-        *
-        * JS passes in a page id and, sometimes, a revision id.  Return back 
the
-        * correct bucket id.
-        *
-        * NB: This call used to return a feedback id and any associated 
answers as
-        * well as the bucket id (each user was allowed one rating/comment saved
-        * per page per revision); it no longer does, as per the 11/10 meeting 
--
-        * instead, we'll store everything the user submits.
-        */
-       public function execute() {
-               $params = $this->extractRequestParams();
-               global $wgArticleFeedbackv5RatingTypes, $wgUser;
-               $params     = $this->extractRequestParams();
-               $bucket     = $this->getBucket( $params );
-               $result     = $this->getResult();
-
-               if ( !$params['revid'] ) {
-                       $params['revid'] = 
ApiArticleFeedbackv5Utils::getRevisionId( $params['pageid'] );
-               }
-               if ( !$params['pageid'] || !$params['revid'] ) {
-                       return null;
-               }
-
-               // $this->logHit( $params['pageid'], $params['revid'], $bucket 
);
-
-               $result->addValue( 'form', 'pageId', $params['pageid'] );
-               $result->addValue( 'form', 'bucketId', $bucket );
-
-               // $feedbackId = $this->getFeedbackId($params, $bucket);
-               // $result->addValue('form', 'feedbackId', $feedbackId);
-       }
-
-       /**
-        * Determine into which bucket this request should fall
-        *
-        * @TODO Base this on last 2 digits of IP address per requirements; 
when we
-        * have markup, we can add other buckets
-        *
-        * @param  array $params [optional] the params passed in
-        * @return int   the bucket id
-        */
-       protected function getBucket( $params = array() ) {
-               $allowedBuckets = array( 1, 5, 6 );
-               if ( !empty( $params['bucketrequested'] )
-                       && is_numeric( $params['bucketrequested'] )
-                       && in_array( $params['bucketrequested'],  
$allowedBuckets ) ) {
-                       $bucket = $params['bucketrequested'];
-// error_log('Using requested bucket');
-               } else {
-                       // Randomize for now; use the designated algorithm later
-                       $bucket = $allowedBuckets[rand( 0, count( 
$allowedBuckets ) - 1 )];
-// error_log('Using random bucket');
-// error_log(var_export($params, true));
-               }
-               return $bucket;
-       }
-
-       /**
-        * Log that this bucket was served for this page and revision
-        *
-        * @param $page     int the page id
-        * @param $revision int the revision id
-        * @param $bucket   int the bucket id
-        */
-       private function logHit( $page, $revision, $bucket ) {
-               $dbr  = wfGetDB( DB_SLAVE );
-               $dbw = wfGetDB( DB_MASTER );
-               $date = date( 'Y-m-d' );
-
-               if ( !$page && !$revision ) {
-                       return;
-               }
-
-               // Select hit counter row
-               $hits = $dbr->selectField(
-                       'aft_article_hits',
-                       'aah_hits',
-                       array(
-                               'aah_page_id'   => $page,
-                               'aah_date'      => $date,
-                               'aah_bucket_id' => $bucket,
-                       )
-               );
-
-               // If there's a row, update it.
-               if ( $hits ) {
-                       $dbw->update(
-                               'aft_article_hits',
-                               array( 'aah_hits' => ( $hits + 1 ) ),
-                               array(
-                                       'aah_page_id'   => $page,
-                                       'aah_date'      => $date,
-                                       'aah_bucket_id' => $bucket,
-                               )
-                       );
-               } else {
-                       // Otherwise, there's no row, insert one.
-                       $dbw->insert('aft_article_hits', array(
-                               'aah_page_id'   => $page,
-                               'aah_date'      => $date,
-                               'aah_bucket_id' => $bucket,
-                               'aah_hits'      => 1
-                       ));
-               }
-       }
-
-       /**
-        * Gets the user's feedback for this page.
-        *
-        * Only works on userids, NOT IP adderesses. Idea being that IPs can 
move,
-        * and we don't want your comments being shown to a different person who
-        * took your IP.  ALSO take revision limit into account.
-        *
-        * NB: Mostly deprecated; do not use in new code.
-        *
-        * @param  $feedbackId the feedback id
-        * @return array       the previous answers
-        */
-       protected function getUserRatings( $feedbackId ) {
-               global $wgUser;
-               $dbr      = wfGetDB( DB_SLAVE );
-               $feedback = array();
-               $rows     = $dbr->select(
-                       array('aft_article_answer', 'aft_article_field',
-                               'aft_article_feedback'),
-                       array('aaaa_response_rating', 'aaaa_response_text',
-                               'aaaa_response_bool', 'aaaa_response_option_id',
-                               'aaf_name', 'aaf_data_type'),
-                       array(
-                               'aa_revision >= ' . $this->getRevisionLimit(),
-                               'aaaa_feedback_id' => $feedbackId,
-                               'aa_user_id'       => $wgUser->getId(),
-                               'aa_is_submitted'  => 1,
-                       )
-               );
-
-               foreach ( $rows as $row ) {
-                       $method = 'response_'.$row->aaf_data_type;
-                       $feeedback[] = array(
-                               'name'  => $row->aaf_name,
-                               'value' => $row->$method
-                       );
-               }
-               return $feedback;
-       }
-
-       /**
-        * Get the revision number of the oldest revision still being counted in
-        * totals
-        *
-        * @param  $pageId int ID of page to check revisions for
-        * @return int     oldest valid revision number or 0 of all revisions 
are valid
-        */
-       protected function getRevisionLimit( $pageId ) {
-               global $wgArticleFeedbackv5RatingLifetime;
-
-               $revision = $this->getDB()->selectField(
-                       'revision',
-                       'rev_id',
-                       array( 'rev_page' => $pageId ),
-                       __METHOD__,
-                       array(
-                               'ORDER BY' => 'rev_id DESC',
-                               'LIMIT'    => 1,
-                               'OFFSET'   => 
$wgArticleFeedbackv5RatingLifetime - 1
-                       )
-               );
-               if ( $revision ) {
-                       return intval( $revision );
-               }
-               return 0;
-       }
-
-       /**
-        * Gets the cache mode
-        *
-        * @param  $params array the params passed in
-        * @return string  the cache mode ('anon-public-user-private' or 
'public')
-        */
-       public function getCacheMode( $params ) {
-               if ( $params['userrating'] ) {
-                       return 'anon-public-user-private';
-               } else {
-                       return 'public';
-               }
-       }
-
-       /**
-        * TODO
-        * Gets the allowed parameters
-        *
-        * @return array the params info, indexed by allowed key
-        */
-       public function getAllowedParams() {
-               return array(
-                       'userrating' => 0,
-                       'anontoken'  => null,
-                       'bucketrequested' => null,
-                       'subaction'  => array(
-                               ApiBase::PARAM_REQUIRED => false,
-                               ApiBase::PARAM_ISMULTI  => false,
-                               ApiBase::PARAM_TYPE     => array( 
'showratings', 'newform' ),
-                       ),
-                       'revid'     => array(
-                               ApiBase::PARAM_REQUIRED => false,
-                               ApiBase::PARAM_ISMULTI  => false,
-                               ApiBase::PARAM_TYPE     => 'integer',
-                       ),
-                       'pageid'     => array(
-                               ApiBase::PARAM_REQUIRED => true,
-                               ApiBase::PARAM_ISMULTI  => false,
-                               ApiBase::PARAM_TYPE     => 'integer',
-                       ),
-               );
-       }
-
-       /**
-        * TODO
-        * Gets the parameter descriptions
-        *
-        * @return array the descriptions, indexed by allowed key
-        */
-       public function getParamDescription() {
-               return array(
-                       'pageid'          => 'Page ID to get feedback ratings 
for',
-                       'revid'           => 'Rev ID to get feedback ratings 
for',
-                       'anontoken'       => 'Token for anonymous users',
-                       'bucketrequested' => 'The bucket number requested in 
the url',
-               );
-       }
-
-       /**
-        * TODO
-        * Gets the api descriptions
-        *
-        * @return array the description as the first element in an array
-        */
-       public function getDescription() {
-               return array(
-                       'List article feedback ratings for a specified page'
-               );
-       }
-
-       /**
-        * TODO
-        * Gets any possible errors
-        *
-        * @return array the errors
-        */
-       public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(), array(
-                               array( 'missingparam', 'anontoken' ),
-                               array( 'code' => 'invalidtoken', 'info' => 'The 
anontoken is not 32 characters' ),
-                       )
-               );
-       }
-
-       /**
-        * TODO
-        * Gets an example
-        *
-        * @return array the example as the first element in an array
-        */
-       protected function getExamples() {
-               return array(
-                       
'api.php?action=query&list=articlefeedbackv5&afpageid=1',
-               );
-       }
-
-       /**
-        * TODO
-        * Gets the version info
-        *
-        * @return string the SVN version info
-        */
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
-       }
-
-}
-

Modified: 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
===================================================================
--- 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
   2011-11-16 15:21:44 UTC (rev 103328)
+++ 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
   2011-11-16 15:25:31 UTC (rev 103329)
@@ -5,7 +5,7 @@
 
 // Only track users who have been assigned to the tracking group
 var tracked = 'track' === mw.user.bucket(
-       'ext.articleFeedback-tracking', mw.config.get( 
'wgArticleFeedbackv5Tracking' )
+       'ext.articleFeedbackv5-tracking', mw.config.get( 
'wgArticleFeedbackv5Tracking' )
 );
 
 /**
@@ -16,7 +16,7 @@
  */
 function prefix( key ) {
        var version = mw.config.get( 'wgArticleFeedbackv5Tracking' ).version || 
0;
-       return 'ext.articleFeedback@' + version + '-' + key;
+       return 'ext.articleFeedbackv5@' + version + '-' + key;
 }
 
 /**
@@ -316,7 +316,7 @@
 };
 
 /* Load at the bottom of the article */
-var $aftDiv = $( '<div id="mw-articlefeedback"></div>' ).articleFeedbackv5( 
config );
+var $aftDiv = $( '<div id="mw-articlefeedbackv5"></div>' ).articleFeedbackv5( 
config );
 
 // Put on bottom of article before #catlinks (if it exists)
 // Except in legacy skins, which have #catlinks above the article but inside 
content-div.
@@ -329,14 +329,16 @@
 }
 
 /* Add link so users can navigate to the feedback tool from the toolbox */
-var $tbAft = $( '<li id="t-articlefeedback"><a 
href="#mw-articlefeedback"></a></li>' )
+var $tbAft = $( '<li id="t-articlefeedbackv5"><a 
href="#mw-articlefeedbackv5"></a></li>' )
        .find( 'a' )
+               // TODO: Find out whether this needs to change per bucket.  
Bucketing
+               // logic may need to move out of the jquery component into here.
                .text( mw.msg( 'articlefeedbackv5-bucket5-form-switch-label' ) )
                .click( function() {
                        // Click tracking
                        trackClick( 'toolbox-link' );
                        // Get the image, set the count and an interval.
-                       var $box = $( '#mw-articlefeedback' );
+                       var $box = $( '#mw-articlefeedbackv5' );
                        var count = 0;
                        var interval = setInterval( function() {
                                // Animate the opacity over .2 seconds

Modified: 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.startup.js
===================================================================
--- 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.startup.js
   2011-11-16 15:21:44 UTC (rev 103328)
+++ 
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.startup.js
   2011-11-16 15:25:31 UTC (rev 103329)
@@ -20,7 +20,7 @@
                && mw.util.getParamValue( 'diff' ) == null
                && mw.util.getParamValue( 'oldid' ) == null
                // Not disabled via preferences
-               && !mw.user.options.get( 'articlefeedback-disable' )
+               && !mw.user.options.get( 'articlefeedbackv5-disable' )
                // Not viewing a redirect
                && mw.util.getParamValue( 'redirect' ) != 'no'
                // Not viewing the printable version
@@ -28,7 +28,7 @@
        ) {
                // Assign a tracking bucket using options from 
wgArticleFeedbackv5Tracking
                mw.user.bucket(
-                       'ext.articleFeedback-tracking', mw.config.get( 
'wgArticleFeedbackv5Tracking' )
+                       'ext.articleFeedbackv5-tracking', mw.config.get( 
'wgArticleFeedbackv5Tracking' )
                );
 
                // Collect categories for intersection tests

Modified: 
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
===================================================================
--- 
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
     2011-11-16 15:21:44 UTC (rev 103328)
+++ 
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
     2011-11-16 15:25:31 UTC (rev 103329)
@@ -56,9 +56,10 @@
        // {{{ Properties
 
        /**
-        * Temporary -- this will need to come from the config.
+        * Whether we're in debug mode.  We'll pull the config value on load, 
but
+        * default it to false for now.
         */
-       $.articleFeedbackv5.debug = true;
+       $.articleFeedbackv5.debug = false;
 
        /**
         * The bucket ID is the variation of the Article Feedback form chosen 
for this
@@ -361,14 +362,13 @@
                        /**
                         * Only certain users can see the expertise checkboxes 
and email
                         */
-                       showOptions: 'show' === mw.user.bucket( 
'ext.articleFeedback-options', mw.config.get( 'wgArticleFeedbackv5Options' ) ),
+                       showOptions: 'show' === mw.user.bucket( 
'ext.articleFeedbackv5-options', mw.config.get( 'wgArticleFeedbackv5Options' ) 
),
 
                        /**
-                        * Whether we need to load the aggregate ratings the 
next time the
-                        * button is clicked.  This is initially set to true, 
turned to
-                        * false after the first time, then turned back to true 
on form
-                        * submission, in case the user wants to go back and 
see the ratings with
-                        * theirs included.
+                        * Whether we need to load the aggregate ratings the 
next time the button is
+                        * clicked.  This is initially set to true, turned to 
false after the first
+                        * time, then turned back to true on form submission, 
in case the user wants
+                        * to go back and see the ratings with theirs included.
                         */
                        loadAggregate: true,
 
@@ -1074,10 +1074,14 @@
                                var $block = $( block_tpl );
 
                                // Fill in the link
-                               $block.find( '.articleFeedbackv5-edit-link' )
-                                       .attr( 'href', mw.config.get( 
'wgArticlePath' ).replace(
-                                               '$1', mw.config.get( 
'wgArticleFeedbackv5WhatsThisPage' )
-                                       ) );
+                               $block.find( '.articleFeedbackv5-edit-cta-link' 
)
+                                       .attr(
+                                               'href',
+                                               mw.config.get( 'wgScript' ) + 
'?' + $.param( {
+                                                       'title': mw.config.get( 
'wgPageName' ),
+                                                       'action': 'edit'
+                                               } )
+                                       );
 
                                return $block;
                        }
@@ -1109,7 +1113,8 @@
                $.articleFeedbackv5.config = config;
                // Has the user already submitted ratings for this page at this 
revision?
                $.articleFeedbackv5.alreadySubmitted = $.cookie( 
$.articleFeedbackv5.prefix( 'submitted' ) ) === 'true';
-               // Go ahead and load the form
+               // Are we in debug mode?
+               $.articleFeedbackv5.debug = mw.config.get( 
'wgArticleFeedbackv5Debug' ) ? true : false;
                // When the tool is visible, load the form
                $.articleFeedbackv5.$holder.appear( function () {
                        $.articleFeedbackv5.loadForm();
@@ -1172,46 +1177,39 @@
        // {{{ Form loading methods
 
        /**
-        * Loads the appropriate form
+        * Chooses a bucket and loads the appropriate form
         *
-        * The load method uses an ajax request to pull down the bucket ID, the
-        * feedback ID, and using those, build the form.
+        * If the plugin is in debug mode, you'll be able to pass in a 
particular
+        * bucket in the url.  Otherwise, it will use the core bucketing
+        * (configuration for this module passed in) to choose a bucket.
         */
        $.articleFeedbackv5.loadForm = function () {
+               // Find out which display bucket they go in:
+               // 1. Requested in query string (debug only)
+               // 2. From cookie (see below)
+               // 3. Core bucketing
+               var knownBuckets = { 1: true, 5: true, 6: true };
                var requested = mw.util.getParamValue( 'bucket' );
-               $.ajax( {
-                       'url': $.articleFeedbackv5.apiUrl,
-                       'type': 'GET',
-                       'dataType': 'json',
-                       'data': {
-                               'list': 'articlefeedbackv5',
-                               'action': 'query',
-                               'format': 'json',
-                               'afsubaction': 'newform',
-                               'afanontoken': $.articleFeedbackv5.userId,
-                               'afpageid': $.articleFeedbackv5.pageId,
-                               'afrevid': $.articleFeedbackv5.revisionId,
-                               'afbucketrequested': requested
-                       },
-                       'success': function ( data ) {
-                               if ( !( 'form' in data ) || !( 'bucketId' in 
data.form ) ) {
-                                       mw.log( 'ArticleFeedback invalid 
response error.' );
-                                       if ( 'error' in data && 'info' in 
data.error ) {
-                                               console.log(data.error.info);
-                                       } else {
-                                               console.log(data);
-                                       }
-                                       $.articleFeedbackv5.bucketId = 6; // No 
form
-                               } else {
-                                       $.articleFeedbackv5.bucketId = 
data.form.bucketId;
-                               }
-                               $.articleFeedbackv5.buildForm( 'form' in data ? 
data.form.response : null );
-                       },
-                       'error': function () {
-                               mw.log( 'Report loading error' );
-                               $.articleFeedbackv5.buildForm();
-                       }
-               } );
+               var cookieval = $.cookie( $.articleFeedbackv5.prefix( 
'display-bucket' ) );
+               if ( $.articleFeedbackv5.debug && requested in knownBuckets ) {
+                       $.articleFeedbackv5.bucketId = requested;
+               } else if ( cookieval in knownBuckets ) {
+                       $.articleFeedbackv5.bucketId = cookieval;
+               } else {
+                       $.articleFeedbackv5.bucketId = mw.user.bucket(
+                               'ext.articleFeedbackv5-display',
+                               mw.config.get( 
'wgArticleFeedbackv5DisplayBuckets' )
+                       );
+               }
+               // Drop in a cookie to keep track of their display bucket;
+               // use the config to determine how long to hold onto it.
+               var cfg = mw.config.get( 'wgArticleFeedbackv5DisplayBuckets' );
+               $.cookie(
+                       $.articleFeedbackv5.prefix( 'display-bucket' ),
+                       $.articleFeedbackv5.bucketId,
+                       { 'expires': cfg.expires, 'path': '/' }
+               );
+               $.articleFeedbackv5.buildForm();
        };
 
        /**
@@ -1220,7 +1218,9 @@
         * @param response object any existing answers
         */
        $.articleFeedbackv5.buildForm = function ( response ) {
-               console.log( 'Using bucket #' + $.articleFeedbackv5.bucketId );
+               if ( $.articleFeedbackv5.debug ) {
+                       console.log( 'Using bucket #' + 
$.articleFeedbackv5.bucketId );
+               }
                var bucket = $.articleFeedbackv5.currentBucket();
                if ( !( 'buildForm' in bucket ) ) {
                        return;


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

Reply via email to