r55732 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55731‎ | r55732 | r55733 >
Date:21:12, 1 September 2009
Author:nimishg
Status:deferred (Comments)
Tags:
Comment:
Moved a few things to JS, which may be handy if we ever do this on a non-edit page
Modified paths:
  • /trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php
@@ -38,14 +38,16 @@
3939
4040
4141 /*
42 - * Gives the user clicktrack JS if they're in the threshhold
 42+ * check to see if user is throttled
4343 */
44 - public static function addJSThrottle(){
 44+ public static function isUserThrottled(){
4545 global $wgClickTrackThrottle;
4646 if(rand() % $wgClickTrackThrottle == 0){
47 - ClickTrackingHooks::addJS();
 47+ return 'false';
4848 }
49 - return true;
 49+ else {
 50+ return 'true';
 51+ }
5052 }
5153
5254
@@ -53,11 +55,14 @@
5456 * Adds JavaScript
5557 */
5658 public static function addJS(){
57 - UsabilityInitiativeHooks::initialize();
58 - UsabilityInitiativeHooks::addScript( 'ClickTracking/ClickTracking.js' );
59 - UsabilityInitiativeHooks::addVariables(
60 - array( 'wgTrackingToken' => ClickTrackingHooks::get_session_id() )
61 - );
 59+ UsabilityInitiativeHooks::initialize();
 60+ UsabilityInitiativeHooks::addScript( 'ClickTracking/ClickTracking.js' );
 61+ UsabilityInitiativeHooks::addVariables(
 62+ array(
 63+ 'wgTrackingToken' => ClickTrackingHooks::get_session_id(),
 64+ 'wgClickTrackingIsThrottled' => ClickTrackingHooks::isUserThrottled()
 65+ )
 66+ );
6267
6368 return true;
6469
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.js
@@ -1,9 +1,11 @@
22 (function($) {
33
4 - // creates 'track action' function to call the clicktracking API and send the ID
5 -$.trackAction = function ( id ){
6 - $j.post( wgScriptPath + '/api.php', { 'action': 'clicktracking', 'eventid': id, 'token': wgTrackingToken } );
7 -};
 4+ if(wgClickTrackingIsThrottled == 'false'){
 5+ // creates 'track action' function to call the clicktracking API and send the ID
 6+ $.trackAction = function ( id ){
 7+ $j.post( wgScriptPath + '/api.php', { 'action': 'clicktracking', 'eventid': id, 'token': wgTrackingToken } );
 8+ };
 9+ }
810
911 return $(this);
1012
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php
@@ -51,7 +51,7 @@
5252 // Hooked functions
5353 $wgHooks['LoadExtensionSchemaUpdates'][] = 'ClickTrackingHooks::schema';
5454 $wgHooks['ArticleSaveComplete'][] = 'ClickTrackingHooks::storeNewContrib';
55 -$wgHooks['EditPage::showEditForm:initial'][] = 'ClickTrackingHooks::addJSThrottle';
 55+$wgHooks['EditPage::showEditForm:initial'][] = 'ClickTrackingHooks::addJS';
5656
5757 // Set up the new API module
5858 $wgAPIModules['clicktracking'] = 'ApiClickTracking';
\ No newline at end of file

Comments

#Comment by Catrope (talk | contribs)   09:18, 2 September 2009

Please don't write functions that return stings 'true' or 'false', that's just ugly. Instead, fix the code that outputs JS vars to handle booleans properly.

#Comment by Nimish Gautam (talk | contribs)   17:55, 2 September 2009

Good call, fixed that in r55758

Status & tagging log