r85561 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85560‎ | r85561 | r85562 >
Date:18:54, 6 April 2011
Author:nimishg
Status:resolved
Tags:
Comment:
bugfixes to user bucketing feature
Modified paths:
  • /trunk/extensions/ClickTracking/ClickTracking.hooks.php (modified) (history)
  • /trunk/extensions/ClickTracking/ClickTracking.php (modified) (history)
  • /trunk/extensions/ClickTracking/modules/ext.UserBuckets.js (modified) (history)
  • /trunk/extensions/ClickTracking/modules/sampleCampaign.js (modified) (history)
  • /trunk/extensions/ClickTracking/patches/ClickTrackingUserProperties.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ClickTracking/ClickTracking.hooks.php
@@ -38,7 +38,7 @@
3939 $updater->addExtensionUpdate( array( 'addTable', 'click_tracking_events',
4040 $dir . 'patches/ClickTrackingEvents.sql', true ) );
4141 $updater->addExtensionUpdate( array( 'addTable', 'click_tracking_user_properties',
42 - $dir . 'patches/ClickTrackingEvents.sql', true ) );
 42+ $dir . 'patches/ClickTrackingUserProperties.sql', true ) );
4343 $updater->addExtensionUpdate( array( 'addIndex', 'click_tracking', 'click_tracking_action_time',
4444 $dir . 'patches/patch-action_time.sql', true ) );
4545 $updater->addExtensionUpdate( array( 'addField', 'click_tracking', 'additional_info',
@@ -70,6 +70,7 @@
7171 */
7272 public static function beforePageDisplay( $out, $skin ) {
7373 global $wgClickTrackThrottle;
 74+ $out->addModules( 'ext.UserBuckets' );
7475
7576 if ( $wgClickTrackThrottle >= 0 && rand() % $wgClickTrackThrottle == 0 ) {
7677 $out->addModules( 'ext.clickTracking' );
@@ -130,8 +131,7 @@
131132 global $wgRequest;
132133
133134 //JSON-encoded because it's simple, can be replaced with any other encoding scheme
134 - return json_decode($wgRequest->getCookie('userbuckets'), true);
135 -
 135+ return json_decode($wgRequest->getCookie('userbuckets',""), true);
136136 }
137137
138138 /**
@@ -140,11 +140,13 @@
141141 * @return unknown_type
142142 */
143143 public static function packBucketInfo( $buckets ){
 144+ global $wgRequest;
144145 //Can be another encoding scheme, just needs to match unpackBucketInfo
145146 $packedBuckets = json_encode( $buckets );
146147
147 - $wgRequest->response()->setCookie( 'userbuckets' , $packedBuckets ,
148 - time() + 60 * 60 * 24 * 365 ); //expire in 1 year
 148+ //NOTE: $wgRequest->response setCookie sets it with a prefix
 149+ setCookie( 'userbuckets' , $packedBuckets ,
 150+ time() + 60 * 60 * 24 * 365 ); //expire in 1 year
149151 }
150152
151153 /**
@@ -167,7 +169,7 @@
168170 */
169171 public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventId, $contribs = 0,
170172 $contribs_in_timespan1 = 0, $contribs_in_timespan2 = 0, $contribs_in_timespan3 = 0, $additional = null, $recordBucketInfo = true ) {
171 -
 173+
172174 $dbw = wfGetDB( DB_MASTER );
173175 $dbw->begin();
174176 // Builds insert information
@@ -185,20 +187,22 @@
186188 );
187189 $db_status_buckets = true;
188190 $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ );
 191+ $dbw->commit();
189192
 193+
190194 if( $recordBucketInfo && $db_status ){
191195 $buckets = self::unpackBucketInfo();
192196 if( $buckets ){
193197 foreach( $buckets as $bucketName => $bucketValue ){
194 - $db_status_buckets = $db_status_buckets &&
195 - $dbw->insert( 'click_tracking_user_properties',
 198+ $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties',
196199 array(
197200 'session_id' => (string) $sessionId,
198 - 'property_id' => (string) $bucketName,
 201+ 'property_name' => (string) $bucketName,
199202 'property_value' => (string) $bucketValue[0],
200203 'property_version' => (int) $bucketValue[1]
201204 ),
202205 __METHOD__);
 206+ $db_status_buckets = $db_status_buckets && $db_current_bucket_insert;
203207 }
204208 }//ifbuckets
205209 }//ifrecord
@@ -206,6 +210,8 @@
207211
208212 $dbw->commit();
209213 return ($db_status && $db_status_buckets);
 214+
 215+
210216 }
211217
212218 public static function editPageShowEditFormFields( $editPage, $output ) {
Index: trunk/extensions/ClickTracking/patches/ClickTrackingUserProperties.sql
@@ -12,10 +12,9 @@
1313
1414 -- property value
1515 property_value varbinary(255),
16 -
 16+
1717 -- property version
1818 property_version INTEGER
19 -
2019 ) /*$wgDBTableOptions*/;
2120
2221 CREATE INDEX /*i*/click_tracking_user_properties_session_idx ON /*_*/click_tracking_user_properties (session_id);
\ No newline at end of file
Index: trunk/extensions/ClickTracking/modules/ext.UserBuckets.js
@@ -4,7 +4,7 @@
55 //include OpenSource JSON stringify from json.org
66 }
77
8 -
 8+( function( $ ) {
99 //lazy-load
1010 $.getBuckets = function (force){
1111 if (typeof(this.userBuckets) == 'undefined' || force ){
@@ -14,9 +14,10 @@
1515 };
1616
1717 $.setBucket = function ( bucketName, bucketValue, bucketVersion ){
18 - var bucketCookies = $.getBuckets();
 18+ var bucketCookies = $.getBuckets();
 19+ if(!bucketCookies) { bucketCookies ={};}
1920 bucketCookies[ bucketName ] = [ bucketValue, bucketVersion ];
20 - $.cookie('userbuckets', JSON.stringify( bucketCookies ) );
 21+ $.cookie('userbuckets', JSON.stringify( bucketCookies ) , { expires: 365 }); //expires in 1 year
2122 bucketCookies = $.getBuckets(true); //force it to rerun and update
2223 };
2324
@@ -27,7 +28,7 @@
2829
2930 // if bucket has been set, or bucket version is out of date,
3031 // set up a user bucket
31 - if( !buckets[campaign.name] || buckets[campaign.name][1] < campaign.version){
 32+ if(!buckets || !buckets[campaign.name] || buckets[campaign.name][1] < campaign.version){
3233 //add up all rates
3334 var bucketTotal = 0;
3435 for ( var rate in campaign.rates ){
@@ -59,4 +60,12 @@
6061
6162 }
6263
63 -};
\ No newline at end of file
 64+};
 65+
 66+//no need to do any of this if there are no active campaigns
 67+if( (typeof(MW) != "undefined") && MW.activeCampaigns){
 68+ $( document ).ready( jQuery.setupActiveBuckets );
 69+}
 70+
 71+
 72+} )( jQuery );
Index: trunk/extensions/ClickTracking/modules/sampleCampaign.js
@@ -1,6 +1,6 @@
22
33 //checks
4 -if(!MW){ MW={};}
 4+if(typeof(MW) == "undefined"){ MW={};}
55 if(!MW.activeCampaigns){ MW.activeCampaigns ={}; }
66
77 //define new active campaign
@@ -46,6 +46,8 @@
4747 $j("#wpSave").click(function(){ $j.trackAction('save'); });
4848 //add click tracking to preview
4949 $j("#wpPreview").click(function(){ $j.trackAction('preview'); });
 50+ $j("#editpage-copywarn").click(function(){ $j.trackAction('copywarn'); });
 51+
5052 }
5153
5254 };
\ No newline at end of file
Index: trunk/extensions/ClickTracking/ClickTracking.php
@@ -87,4 +87,15 @@
8888 'styles' => 'ext.clickTracking.special.css',
8989 'dependencies' => array( 'jquery.ui.datepicker', 'jquery.ui.dialog' ),
9090 ) + $ctResourceTemplate;
 91+$wgResourceModules['ext.UserBuckets'] = array(
 92+ 'scripts' => 'ext.UserBuckets.js',
 93+ 'dependencies' => array('jquery.clickTracking', 'jquery.cookie', /*'ext.UserBuckets.sampleCampaign'*/),
 94+) + $ctResourceTemplate;
9195
 96+//uncomment sample campaign below and sampleCampaign dependency to set up a sample campaign
 97+/*
 98+$wgResourceModules['ext.UserBuckets.sampleCampaign'] = array(
 99+ 'scripts' => 'sampleCampaign.js',
 100+ 'dependencies' => 'jquery.clickTracking',
 101+) + $ctResourceTemplate;
 102+*/

Status & tagging log