Index: trunk/extensions/ClickTracking/ClickTracking.hooks.php |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | //adds a bucket-testing campaign to the active campaigns |
96 | 96 | public static function addCampaign($localBasePath, $remoteExtPath, $name ){ |
97 | 97 | global $wgResourceModules; |
98 | | - |
| 98 | + |
99 | 99 | $cusResourceTemplate = array( |
100 | 100 | 'localBasePath' => $localBasePath, |
101 | 101 | 'remoteExtPath' => $remoteExtPath, |
— | — | @@ -103,7 +103,7 @@ |
104 | 104 | 'scripts' => "$name.js", |
105 | 105 | 'dependencies' => 'jquery.clickTracking', |
106 | 106 | ) + $cusResourceTemplate; |
107 | | - $wgResourceModules['ext.UserBuckets']['dependencies'] = array_merge( |
| 107 | + $wgResourceModules['ext.UserBuckets']['dependencies'] = array_merge( |
108 | 108 | ( array ) $wgResourceModules['ext.UserBuckets']['dependencies'], |
109 | 109 | array("ext.UserBuckets.$name")); |
110 | 110 | } |
— | — | @@ -143,11 +143,11 @@ |
144 | 144 | */ |
145 | 145 | public static function unpackBucketInfo(){ |
146 | 146 | global $wgRequest; |
147 | | - |
| 147 | + |
148 | 148 | //JSON-encoded because it's simple, can be replaced with any other encoding scheme |
149 | 149 | return FormatJson::decode( $wgRequest->getCookie( 'userbuckets', "" ), true ); |
150 | 150 | } |
151 | | - |
| 151 | + |
152 | 152 | /** |
153 | 153 | * Takes in an array of buckets |
154 | 154 | * @param unknown_type $buckets |
— | — | @@ -157,12 +157,12 @@ |
158 | 158 | global $wgRequest; |
159 | 159 | //Can be another encoding scheme, just needs to match unpackBucketInfo |
160 | 160 | $packedBuckets = FormatJson::encode( $buckets ); |
161 | | - |
| 161 | + |
162 | 162 | //NOTE: $wgRequest->response setCookie sets it with a prefix and httponly by default |
163 | | - setcookie( 'userbuckets' , $packedBuckets , |
| 163 | + setcookie( 'userbuckets' , $packedBuckets , |
164 | 164 | time() + 60 * 60 * 24 * 90 , '/' ); //expire in 90 days |
165 | 165 | } |
166 | | - |
| 166 | + |
167 | 167 | /** |
168 | 168 | * Track particular event |
169 | 169 | * |
— | — | @@ -177,13 +177,13 @@ |
178 | 178 | * (defined by ClickTracking/$wgClickTrackContribGranularity2) |
179 | 179 | * @param $contribs_in_timespan3 Integer: number of contributions user has made in timespan of granularity 3 |
180 | 180 | * (defined by ClickTracking/$wgClickTrackContribGranularity3) |
181 | | - * @param $additional String: catch-all for any additional information we want to record about this click |
| 181 | + * @param $additional String: catch-all for any additional information we want to record about this click |
182 | 182 | * @param $relevantBucket String: name/index of the particular bucket we're concerned with for this event |
183 | 183 | * @return Boolean: true if the event was stored in the DB |
184 | 184 | */ |
185 | 185 | public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventName, $contribs = 0, |
186 | 186 | $contribs_in_timespan1 = 0, $contribs_in_timespan2 = 0, $contribs_in_timespan3 = 0, $additional = null, $recordBucketInfo = true ) { |
187 | | - |
| 187 | + |
188 | 188 | global $wgClickTrackingDatabase, $wgClickTrackingLog; |
189 | 189 | $retval = true; |
190 | 190 | if ( $wgClickTrackingDatabase ) { |
— | — | @@ -207,11 +207,12 @@ |
208 | 208 | $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ ); |
209 | 209 | $dbw->commit(); |
210 | 210 | |
211 | | - if( $recordBucketInfo && $db_status ){ |
| 211 | + if( $recordBucketInfo && $db_status ) { |
212 | 212 | $buckets = self::unpackBucketInfo(); |
213 | | - if( $buckets ){ |
| 213 | + $dbw->begin(); |
| 214 | + if( $buckets ) { |
214 | 215 | foreach( $buckets as $bucketName => $bucketValue ){ |
215 | | - $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties', |
| 216 | + $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties', |
216 | 217 | array( |
217 | 218 | 'session_id' => (string) $sessionId, |
218 | 219 | 'property_name' => (string) $bucketName, |
— | — | @@ -225,7 +226,7 @@ |
226 | 227 | } |
227 | 228 | }//ifbuckets |
228 | 229 | }//ifrecord |
229 | | - |
| 230 | + |
230 | 231 | $dbw->commit(); |
231 | 232 | $retval = $db_status && $db_status_buckets; |
232 | 233 | } |
— | — | @@ -244,16 +245,16 @@ |
245 | 246 | str_replace( "\t", ' ', $additional ), |
246 | 247 | ) ); |
247 | 248 | wfErrorLog( $msg, $wgClickTrackingLog ); |
248 | | - |
| 249 | + |
249 | 250 | // No need to mess with $retval here, doing |
250 | 251 | // $retval == $retval && true is useless |
251 | 252 | } |
252 | 253 | return $retval; |
253 | 254 | } |
254 | | - |
| 255 | + |
255 | 256 | public static function editPageShowEditFormFields( $editPage, $output ) { |
256 | 257 | global $wgRequest; |
257 | | - |
| 258 | + |
258 | 259 | // Add clicktracking fields to form, if given |
259 | 260 | $session = $wgRequest->getVal( 'clicktrackingsession' ); |
260 | 261 | $event = $wgRequest->getVal( 'clicktrackingevent' ); |
— | — | @@ -263,24 +264,24 @@ |
264 | 265 | $editPage->editFormTextAfterContent .= Html::hidden( 'clicktrackingevent', $event ); |
265 | 266 | $editPage->editFormTextAfterContent .= Html::hidden( 'clicktrackinginfo', $info ); |
266 | 267 | } |
267 | | - |
| 268 | + |
268 | 269 | return true; |
269 | 270 | } |
270 | | - |
| 271 | + |
271 | 272 | public static function articleSave( $editpage ) { |
272 | 273 | self::trackRequest( '-save-attempt' ); |
273 | 274 | return true; |
274 | 275 | } |
275 | | - |
| 276 | + |
276 | 277 | public static function articleSaveComplete( $article, $user, $text, $summary, $minoredit, |
277 | 278 | $watchthis, $sectionanchor, $flags, $revision, $baseRevId ) { |
278 | 279 | self::trackRequest( '-save-complete' ); |
279 | 280 | return true; |
280 | 281 | } |
281 | | - |
| 282 | + |
282 | 283 | protected static function trackRequest( $suffix ) { |
283 | 284 | global $wgRequest, $wgTitle; |
284 | | - |
| 285 | + |
285 | 286 | $session = $wgRequest->getVal( 'clicktrackingsession' ); |
286 | 287 | $event = $wgRequest->getVal( 'clicktrackingevent' ); |
287 | 288 | $info = $wgRequest->getVal( 'clicktrackinginfo' ); |
— | — | @@ -295,7 +296,7 @@ |
296 | 297 | $api = new ApiMain( $params, true ); |
297 | 298 | $api->execute(); |
298 | 299 | } |
299 | | - |
| 300 | + |
300 | 301 | return true; |
301 | 302 | } |
302 | 303 | } |