r86586 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86585‎ | r86586 | r86587 >
Date:00:21, 21 April 2011
Author:tparscal
Status:ok
Tags:
Comment:
Converted ad-hoc bucketing system for tracking to use new mw.user.bucket function.
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php
@@ -214,12 +214,10 @@
215215 public static function resourceLoaderGetConfigVars( &$vars ) {
216216 global $wgArticleFeedbackCategories,
217217 $wgArticleFeedbackLotteryOdds,
218 - $wgArticleFeedbackTrackingVersion,
219 - $wgArticleFeedbackTrackingOdds;
 218+ $wgArticleFeedbackTracking;
220219 $vars['wgArticleFeedbackCategories'] = $wgArticleFeedbackCategories;
221220 $vars['wgArticleFeedbackLotteryOdds'] = $wgArticleFeedbackLotteryOdds;
222 - $vars['wgArticleFeedbackTrackingVersion'] = $wgArticleFeedbackTrackingVersion;
223 - $vars['wgArticleFeedbackTrackingOdds'] = $wgArticleFeedbackTrackingOdds;
 221+ $vars['wgArticleFeedbackTracking'] = $wgArticleFeedbackTracking;
224222 return true;
225223 }
226224 }
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js
@@ -5,7 +5,9 @@
66 ( function( $, mw ) {
77
88 // Only track users who have been assigned to the tracking group
9 -var tracked = Number( $.cookie( 'ext.articleFeedback-tracking' ) );
 9+var tracked = mw.user.bucket(
 10+ 'ext.articleFeedback-tracking', mw.config.get( 'wgArticleFeedbackTracking' )
 11+);
1012
1113 /**
1214 * Prefixes a key for cookies or events, with extension and version information
@@ -14,7 +16,7 @@
1517 * @return String: Prefixed event name
1618 */
1719 function prefix( key ) {
18 - var version = mw.config.get( 'wgArticleFeedbackTrackingVersion' ) || 0;
 20+ var version = mw.config.get( 'wgArticleFeedbackTracking' ).version || 0;
1921 return 'ext.articleFeedback@' + version + '-' + key;
2022 }
2123
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
@@ -5,7 +5,9 @@
66 ( function( $, mw ) {
77
88 // Only track users who have been assigned to the tracking group
9 -var tracked = Number( $.cookie( 'ext.articleFeedback-tracking' ) );
 9+var tracked = 'track' === mw.user.bucket(
 10+ 'ext.articleFeedback-tracking', mw.config.get( 'wgArticleFeedbackTracking' )
 11+);
1012
1113 /**
1214 * Prefixes a key for cookies or events, with extension and version information
@@ -14,7 +16,7 @@
1517 * @return String: Prefixed event name
1618 */
1719 function prefix( key ) {
18 - var version = mw.config.get( 'wgArticleFeedbackTrackingVersion' ) || 0;
 20+ var version = mw.config.get( 'wgArticleFeedbackTracking' ).version || 0;
1921 return 'ext.articleFeedback@' + version + '-' + key;
2022 }
2123
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js
@@ -12,36 +12,9 @@
1313 && mw.util.getParamValue( 'diff' ) === null
1414 && mw.util.getParamValue( 'oldid' ) === null
1515 ) {
16 - // If the version in the client's cookie doesn't match wgArticleFeedbackTrackingVersion,
17 - // then we need to disregard the bucket they may already be in to ensure accurate
18 - // redistribution when the odds are changed
19 - var previousVersion = $.cookie( 'ext.articleFeedback-version' );
20 - var currentVersion = Number( mw.config.get( 'wgArticleFeedbackTrackingVersion', 0 ) );
21 - var tracking = null;
22 - if ( previousVersion === null || Number( previousVersion ) != currentVersion ) {
23 - $.cookie( 'ext.articleFeedback-version', currentVersion );
24 - } else {
25 - tracking = $.cookie( 'ext.articleFeedback-tracking' );
26 - }
27 - if ( tracking === null ) {
28 - // Percentage chance of being tracked
29 - var odds = Math.min( 100, Math.max( 0,
30 - Number( mw.config.get( 'wgArticleFeedbackTrackingOdds', 0 ) )
31 - ) );
32 - // 0 = not tracked, 1 = tracked
33 - tracking = Number( Math.random() * 100 < odds );
34 - // Let the cookie expire after 30 days, allowing rotation in which users are tracked
35 - $.cookie( 'ext.articleFeedback-tracking', tracking, { 'path': '/', 'expires': 30 } );
36 - // To be extra-sure that the odds are being applied properly, track whether a user is to
37 - // be tracked or not - this way we can compare the number of people in each bucket to
38 - // the intended percentages defined by wgArticleFeedbackTrackingOdds
39 - if ( 'trackAction' in $ ) {
40 - $.trackAction(
41 - 'ext.articleFeedback@' + currentVersion + '-tracking-' +
42 - ( tracking ? 'on' : 'off' )
43 - );
44 - }
45 - }
 16+ var trackingBucket = mw.user.bucket(
 17+ 'ext.articleFeedback-tracking', mw.config.get( 'wgArticleFeedbackTracking' )
 18+ );
4619 // Category activation
4720 var articleFeedbackCategories = mw.config.get( 'wgArticleFeedbackCategories', [] );
4821 var articleCategories = mw.config.get( 'wgCategories', [] );
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.php
@@ -31,17 +31,27 @@
3232 // are the smallest increments used.
3333 $wgArticleFeedbackLotteryOdds = 0;
3434
35 -// This version number is added to all tracking event names, so that changes in the software don't
36 -// corrupt the data being collected. Bump this when you want to start a new "experiment".
37 -$wgArticleFeedbackTrackingVersion = 0;
 35+// Bucket settings for tracking users
 36+$wgArticleFeedbackTracking = array(
 37+ // Not all users need to be tracked, but we do want to track some users over time - these
 38+ // buckets are used when deciding to track someone or not, placing them in one of two buckets:
 39+ // "ignore" or "track". When $wgArticleFeedbackTrackingVersion changes, users will be
 40+ // re-bucketed, so you should always increment $wgArticleFeedbackTrackingVersion when changing
 41+ // this number to ensure the new odds are applied to everyone, not just people who have yet to
 42+ // be placed in a bucket.
 43+ 'buckets' => array(
 44+ 'ignore' => 100,
 45+ 'track' => 0,
 46+ ),
 47+ // This version number is added to all tracking event names, so that changes in the software
 48+ // don't corrupt the data being collected. Bump this when you want to start a new "experiment".
 49+ 'version' => 0,
 50+ // Let user's be tracked for a month, and then rebucket them, allowing some churn
 51+ 'expires' => 30,
 52+ // Track the event of users being bucketed - so we can be sure the odds worked out right
 53+ 'tracked' => true
 54+);
3855
39 -// Not all users need to be tracked, but we do want to track some users over time - this value is
40 -// used when deciding to track someone or not, placing them in one of two buckets: tracked and not.
41 -// When $wgArticleFeedbackTrackingVersion changes, users will be re-bucketed, so you should always
42 -// increment $wgArticleFeedbackTrackingVersion when changing this number to ensure the new odds
43 -// are applied to everyone, not just people who have yet to be placed in a bucket.
44 -$wgArticleFeedbackTrackingOdds = 100;
45 -
4656 // Would ordinarily call this articlefeedback but survey names are 16 chars max
4757 $wgPrefSwitchSurveys['articlerating'] = array(
4858 'updatable' => false,

Status & tagging log