Index: trunk/extensions/ClickTracking/ClickTracking.hooks.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | $updater->addExtensionUpdate( array( 'addTable', 'click_tracking_events', |
40 | 40 | $dir . 'patches/ClickTrackingEvents.sql', true ) ); |
41 | 41 | $updater->addExtensionUpdate( array( 'addTable', 'click_tracking_user_properties', |
42 | | - $dir . 'patches/ClickTrackingEvents.sql', true ) ); |
| 42 | + $dir . 'patches/ClickTrackingUserProperties.sql', true ) ); |
43 | 43 | $updater->addExtensionUpdate( array( 'addIndex', 'click_tracking', 'click_tracking_action_time', |
44 | 44 | $dir . 'patches/patch-action_time.sql', true ) ); |
45 | 45 | $updater->addExtensionUpdate( array( 'addField', 'click_tracking', 'additional_info', |
— | — | @@ -70,6 +70,7 @@ |
71 | 71 | */ |
72 | 72 | public static function beforePageDisplay( $out, $skin ) { |
73 | 73 | global $wgClickTrackThrottle; |
| 74 | + $out->addModules( 'ext.UserBuckets' ); |
74 | 75 | |
75 | 76 | if ( $wgClickTrackThrottle >= 0 && rand() % $wgClickTrackThrottle == 0 ) { |
76 | 77 | $out->addModules( 'ext.clickTracking' ); |
— | — | @@ -130,8 +131,7 @@ |
131 | 132 | global $wgRequest; |
132 | 133 | |
133 | 134 | //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); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
— | — | @@ -140,11 +140,13 @@ |
141 | 141 | * @return unknown_type |
142 | 142 | */ |
143 | 143 | public static function packBucketInfo( $buckets ){ |
| 144 | + global $wgRequest; |
144 | 145 | //Can be another encoding scheme, just needs to match unpackBucketInfo |
145 | 146 | $packedBuckets = json_encode( $buckets ); |
146 | 147 | |
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 |
149 | 151 | } |
150 | 152 | |
151 | 153 | /** |
— | — | @@ -167,7 +169,7 @@ |
168 | 170 | */ |
169 | 171 | public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventId, $contribs = 0, |
170 | 172 | $contribs_in_timespan1 = 0, $contribs_in_timespan2 = 0, $contribs_in_timespan3 = 0, $additional = null, $recordBucketInfo = true ) { |
171 | | - |
| 173 | + |
172 | 174 | $dbw = wfGetDB( DB_MASTER ); |
173 | 175 | $dbw->begin(); |
174 | 176 | // Builds insert information |
— | — | @@ -185,20 +187,22 @@ |
186 | 188 | ); |
187 | 189 | $db_status_buckets = true; |
188 | 190 | $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ ); |
| 191 | + $dbw->commit(); |
189 | 192 | |
| 193 | + |
190 | 194 | if( $recordBucketInfo && $db_status ){ |
191 | 195 | $buckets = self::unpackBucketInfo(); |
192 | 196 | if( $buckets ){ |
193 | 197 | 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', |
196 | 199 | array( |
197 | 200 | 'session_id' => (string) $sessionId, |
198 | | - 'property_id' => (string) $bucketName, |
| 201 | + 'property_name' => (string) $bucketName, |
199 | 202 | 'property_value' => (string) $bucketValue[0], |
200 | 203 | 'property_version' => (int) $bucketValue[1] |
201 | 204 | ), |
202 | 205 | __METHOD__); |
| 206 | + $db_status_buckets = $db_status_buckets && $db_current_bucket_insert; |
203 | 207 | } |
204 | 208 | }//ifbuckets |
205 | 209 | }//ifrecord |
— | — | @@ -206,6 +210,8 @@ |
207 | 211 | |
208 | 212 | $dbw->commit(); |
209 | 213 | return ($db_status && $db_status_buckets); |
| 214 | + |
| 215 | + |
210 | 216 | } |
211 | 217 | |
212 | 218 | public static function editPageShowEditFormFields( $editPage, $output ) { |
Index: trunk/extensions/ClickTracking/patches/ClickTrackingUserProperties.sql |
— | — | @@ -12,10 +12,9 @@ |
13 | 13 | |
14 | 14 | -- property value |
15 | 15 | property_value varbinary(255), |
16 | | - |
| 16 | + |
17 | 17 | -- property version |
18 | 18 | property_version INTEGER |
19 | | - |
20 | 19 | ) /*$wgDBTableOptions*/; |
21 | 20 | |
22 | 21 | 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 @@ |
5 | 5 | //include OpenSource JSON stringify from json.org |
6 | 6 | } |
7 | 7 | |
8 | | - |
| 8 | +( function( $ ) { |
9 | 9 | //lazy-load |
10 | 10 | $.getBuckets = function (force){ |
11 | 11 | if (typeof(this.userBuckets) == 'undefined' || force ){ |
— | — | @@ -14,9 +14,10 @@ |
15 | 15 | }; |
16 | 16 | |
17 | 17 | $.setBucket = function ( bucketName, bucketValue, bucketVersion ){ |
18 | | - var bucketCookies = $.getBuckets(); |
| 18 | + var bucketCookies = $.getBuckets(); |
| 19 | + if(!bucketCookies) { bucketCookies ={};} |
19 | 20 | bucketCookies[ bucketName ] = [ bucketValue, bucketVersion ]; |
20 | | - $.cookie('userbuckets', JSON.stringify( bucketCookies ) ); |
| 21 | + $.cookie('userbuckets', JSON.stringify( bucketCookies ) , { expires: 365 }); //expires in 1 year |
21 | 22 | bucketCookies = $.getBuckets(true); //force it to rerun and update |
22 | 23 | }; |
23 | 24 | |
— | — | @@ -27,7 +28,7 @@ |
28 | 29 | |
29 | 30 | // if bucket has been set, or bucket version is out of date, |
30 | 31 | // 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){ |
32 | 33 | //add up all rates |
33 | 34 | var bucketTotal = 0; |
34 | 35 | for ( var rate in campaign.rates ){ |
— | — | @@ -59,4 +60,12 @@ |
60 | 61 | |
61 | 62 | } |
62 | 63 | |
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 @@ |
2 | 2 | |
3 | 3 | //checks |
4 | | -if(!MW){ MW={};} |
| 4 | +if(typeof(MW) == "undefined"){ MW={};} |
5 | 5 | if(!MW.activeCampaigns){ MW.activeCampaigns ={}; } |
6 | 6 | |
7 | 7 | //define new active campaign |
— | — | @@ -46,6 +46,8 @@ |
47 | 47 | $j("#wpSave").click(function(){ $j.trackAction('save'); }); |
48 | 48 | //add click tracking to preview |
49 | 49 | $j("#wpPreview").click(function(){ $j.trackAction('preview'); }); |
| 50 | + $j("#editpage-copywarn").click(function(){ $j.trackAction('copywarn'); }); |
| 51 | + |
50 | 52 | } |
51 | 53 | |
52 | 54 | }; |
\ No newline at end of file |
Index: trunk/extensions/ClickTracking/ClickTracking.php |
— | — | @@ -87,4 +87,15 @@ |
88 | 88 | 'styles' => 'ext.clickTracking.special.css', |
89 | 89 | 'dependencies' => array( 'jquery.ui.datepicker', 'jquery.ui.dialog' ), |
90 | 90 | ) + $ctResourceTemplate; |
| 91 | +$wgResourceModules['ext.UserBuckets'] = array( |
| 92 | + 'scripts' => 'ext.UserBuckets.js', |
| 93 | + 'dependencies' => array('jquery.clickTracking', 'jquery.cookie', /*'ext.UserBuckets.sampleCampaign'*/), |
| 94 | +) + $ctResourceTemplate; |
91 | 95 | |
| 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 | +*/ |