r86436 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86435‎ | r86436 | r86437 >
Date:21:11, 19 April 2011
Author:nimishg
Status:resolved (Comments)
Tags:
Comment:
Created more sensible way to add campaigns, now working in ie6
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)

Diff [purge]

Index: trunk/extensions/ClickTracking/ClickTracking.hooks.php
@@ -91,6 +91,26 @@
9292 return true;
9393 }
9494
 95+
 96+ //adds a bucket-testing campaign to the active campaigns
 97+ public static function addCampaign($localBasePath, $remoteExtPath, $name ){
 98+ global $wgResourceModules;
 99+
 100+ $cusResourceTemplate = array(
 101+ 'localBasePath' => $localBasePath,
 102+ 'remoteExtPath' => $remoteExtPath,
 103+ );
 104+ $wgResourceModules["ext.UserBuckets.$name"] = array(
 105+ 'scripts' => "$name.js",
 106+ 'dependencies' => 'jquery.clickTracking',
 107+ ) + $cusResourceTemplate;
 108+ $wgResourceModules['ext.UserBuckets']['dependencies'] = array_merge(
 109+ ( array ) $wgResourceModules['ext.UserBuckets']['dependencies'],
 110+ array("ext.UserBuckets.$name"));
 111+ }
 112+
 113+
 114+
95115 /**
96116 * Get event ID from name
97117 *
@@ -188,10 +208,13 @@
189209 $db_status_buckets = true;
190210 $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ );
191211 $dbw->commit();
 212+
 213+
192214
193215
194216 if( $recordBucketInfo && $db_status ){
195217 $buckets = self::unpackBucketInfo();
 218+
196219 if( $buckets ){
197220 foreach( $buckets as $bucketName => $bucketValue ){
198221 $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties',
Index: trunk/extensions/ClickTracking/modules/ext.UserBuckets.js
@@ -1,16 +1,41 @@
22
 3+var JSON;
 4+if (!JSON) {
 5+ JSON = {};
36
4 -if( !JSON || !JSON.stringify ){
5 - //include OpenSource JSON stringify from json.org
 7+ if(!JSON.stringify){
 8+ /* Very limited JSON encoder */
 9+ JSON.stringify = function( js_obj ) {
 10+ var returnstr = "{ ";
 11+
 12+ // trailing commas and json don't mix
 13+ var propertynum = 0;
 14+ for ( property in js_obj ) {
 15+ if ( propertynum > 0 ) {
 16+ returnstr += ", ";
 17+ }
 18+ returnstr += "\"" + property + "\"" + " : ";
 19+ if ( typeof js_obj[property] == 'object' ) {
 20+ returnstr += JSON.stringify( js_obj[property] );
 21+ } else {
 22+ returnstr += "\"" + js_obj[property] + "\" ";
 23+ }
 24+ propertynum++;
 25+ }
 26+
 27+ returnstr += " }";
 28+ return returnstr;
 29+ };
 30+ }
631 }
732
833 ( function( $ ) {
934 //lazy-load
1035 $.getBuckets = function (force){
11 - if (typeof($.userBuckets) == 'undefined' || force ){
12 - $.userBuckets = $.parseJSON( $.cookie('userbuckets') );
 36+ if (typeof($j.userBuckets) == 'undefined' || force ){
 37+ $j.userBuckets = $.parseJSON( $.cookie('userbuckets') );
1338 }
14 - return $.userBuckets;
 39+ return $j.userBuckets;
1540 };
1641
1742 $.setBucket = function ( bucketName, bucketValue, bucketVersion ){
Index: trunk/extensions/ClickTracking/ClickTracking.php
@@ -89,13 +89,9 @@
9090 ) + $ctResourceTemplate;
9191 $wgResourceModules['ext.UserBuckets'] = array(
9292 'scripts' => 'ext.UserBuckets.js',
93 - 'dependencies' => array('jquery.clickTracking', 'jquery.cookie', /*'ext.UserBuckets.sampleCampaign'*/),
 93+ 'dependencies' => array('jquery.clickTracking', 'jquery.cookie'),
9494 ) + $ctResourceTemplate;
9595
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 -*/
 96+//uncomment for sample campaign
 97+//ClickTrackingHooks::addCampaign($dir. 'modules', 'ClickTracking/modules', 'sampleCampaign' );
 98+

Comments

#Comment by Catrope (talk | contribs)   13:57, 20 August 2011
+    if(!JSON.stringify){
+    /* Very limited JSON encoder */

Use the jquery.json module instead. OK otherwise.

Status & tagging log