Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php |
— | — | @@ -36,42 +36,34 @@ |
37 | 37 | * @return unknown_type |
38 | 38 | */ |
39 | 39 | public static function parserTestTables( &$tables ) { |
40 | | - $tables[] = 'click_tracking'; |
41 | | - $tables[] = 'click_tracking_events'; |
42 | | - return true; |
| 40 | + $tables[] = 'click_tracking'; |
| 41 | + $tables[] = 'click_tracking_events'; |
| 42 | + return true; |
43 | 43 | } |
44 | 44 | |
45 | 45 | /* |
46 | 46 | * check to see if user is throttled |
47 | 47 | */ |
48 | | - public static function isUserThrottled(){ |
| 48 | + public static function isUserThrottled() { |
49 | 49 | global $wgClickTrackThrottle; |
50 | | - if( ( $wgClickTrackThrottle >= 0 ) && ( rand() % $wgClickTrackThrottle == 0 ) ){ |
51 | | - return 'false'; |
52 | | - } |
53 | | - else { |
54 | | - return 'true'; |
55 | | - } |
| 50 | + return !( $wgClickTrackThrottle >= 0 && rand() % $wgClickTrackThrottle == 0 ); |
56 | 51 | } |
57 | 52 | |
58 | 53 | |
59 | 54 | /** |
60 | 55 | * Adds JavaScript |
61 | 56 | */ |
62 | | - public static function addJS(){ |
| 57 | + public static function addJS() { |
63 | 58 | global $wgOut; |
64 | 59 | |
65 | 60 | UsabilityInitiativeHooks::initialize(); |
66 | 61 | UsabilityInitiativeHooks::addScript( 'ClickTracking/ClickTracking.js' ); |
67 | 62 | UsabilityInitiativeHooks::addVariables( |
68 | | - array( |
| 63 | + array( |
69 | 64 | 'wgTrackingToken' => ClickTrackingHooks::get_session_id() |
| 65 | + 'wgClickTrackingIsThrottled' => ClickTrackingHooks::isUserThrottled() |
70 | 66 | ) |
71 | 67 | ); |
72 | | - //need a literal false, not "false" to be output, to work prperly |
73 | | - $userThrottle = ClickTrackingHooks::isUserThrottled(); |
74 | | - $wgOut->addScript("<script> var wgClickTrackingIsThrottled = $userThrottle; </script>"); |
75 | | - |
76 | 68 | return true; |
77 | 69 | |
78 | 70 | } |
— | — | @@ -80,7 +72,7 @@ |
81 | 73 | * Gets the session ID...we just want a unique random ID for the page load |
82 | 74 | * @return session ID |
83 | 75 | */ |
84 | | - public static function get_session_id(){ |
| 76 | + public static function get_session_id() { |
85 | 77 | global $wgUser; |
86 | 78 | return wfGenerateToken( array( $wgUser->getName(), time() ) ); |
87 | 79 | } |
— | — | @@ -90,7 +82,7 @@ |
91 | 83 | * @param $ts beginning timestamp |
92 | 84 | * @return number of revsions this user has made |
93 | 85 | */ |
94 | | - public static function getEditCountSince( $ts ){ |
| 86 | + public static function getEditCountSince( $ts ) { |
95 | 87 | global $wgUser; |
96 | 88 | |
97 | 89 | // convert to just the day |
— | — | @@ -109,7 +101,7 @@ |
110 | 102 | ); |
111 | 103 | |
112 | 104 | // user hasn't made any edits in whatever amount of time |
113 | | - if( $edits == null ){ |
| 105 | + if ( $edits == null ) { |
114 | 106 | $edits = 0; |
115 | 107 | } |
116 | 108 | |
— | — | @@ -122,22 +114,23 @@ |
123 | 115 | * @param $event_name String: name of the event to get |
124 | 116 | * @return integer |
125 | 117 | */ |
126 | | - public static function getEventIDFromName( $event_name ){ |
| 118 | + public static function getEventIDFromName( $event_name ) { |
127 | 119 | $dbw = wfGetDB( DB_MASTER ); //replication lag means sometimes a new event will not exist in the table yet |
128 | 120 | |
129 | 121 | $id_num = $dbw->selectField( |
130 | 122 | 'click_tracking_events', |
131 | 123 | 'id', |
132 | | - array( |
| 124 | + array( |
133 | 125 | 'event_name' => $event_name |
134 | | - ), |
| 126 | + ), |
135 | 127 | __METHOD__ |
136 | 128 | ); |
137 | 129 | |
138 | 130 | // if this entry doesn't exist... |
139 | 131 | // this will be incredibly rare as the whole database will only have a few hundred entries in it at most |
140 | 132 | // and getting DB_MASTER up top would be wasteful |
141 | | - if( $id_num === false ){ |
| 133 | + // FIXME: Use replace() instead of this selectField --> insert or update logic |
| 134 | + if( $id_num === false ) { |
142 | 135 | $dbw->insert( |
143 | 136 | 'click_tracking_events', |
144 | 137 | array( 'event_name' => (string) $event_name ), |
— | — | @@ -165,8 +158,8 @@ |
166 | 159 | * @param $contribs_in_timespan3 Integer: number of contributions user has made in timespan of granularity 3 (defined by ClickTracking/$wgClickTrackContribGranularity3) |
167 | 160 | * @return true if the event was stored in the DB |
168 | 161 | */ |
169 | | - public static function trackEvent( $session_id, $is_logged_in, $namespace, $event_id, $contribs = 0, |
170 | | - $contribs_in_timespan1 = 0, $contribs_in_timespan2 = 0, $contribs_in_timespan3 = 0 ){ |
| 162 | + public static function trackEvent( $session_id, $is_logged_in, $namespace, $event_id, $contribs = 0, |
| 163 | + $contribs_in_timespan1 = 0, $contribs_in_timespan2 = 0, $contribs_in_timespan3 = 0 ) { |
171 | 164 | $dbw = wfGetDB( DB_MASTER ); |
172 | 165 | |
173 | 166 | $dbw->begin(); |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.js |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | if(!wgClickTrackingIsThrottled){ |
5 | 5 | // creates 'track action' function to call the clicktracking API and send the ID |
6 | | - $.trackAction = function ( id ){ |
| 6 | + $.trackAction = function ( id ) { |
7 | 7 | $j.post( wgScriptPath + '/api.php', { 'action': 'clicktracking', 'eventid': id, 'token': wgTrackingToken } ); |
8 | 8 | }; |
9 | 9 | } |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ApiClickTracking.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | * runs when the API is called with "clicktracking", takes in "eventid" and an edit token given to the user, "token" |
14 | 14 | * @see includes/api/ApiBase#execute() |
15 | 15 | */ |
16 | | - public function execute(){ |
| 16 | + public function execute() { |
17 | 17 | global $wgUser, $wgTitle, $wgClickTrackContribGranularity1, $wgClickTrackContribGranularity2, $wgClickTrackContribGranularity3; |
18 | 18 | |
19 | 19 | $params = $this->extractRequestParams(); |
— | — | @@ -25,17 +25,14 @@ |
26 | 26 | |
27 | 27 | $is_logged_in = $wgUser->isLoggedIn(); |
28 | 28 | $now = time(); |
29 | | - $granularity1 = $is_logged_in? |
30 | | - ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity1 ) |
31 | | - : 0; |
| 29 | + $granularity1 = $is_logged_in ? |
| 30 | + ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity1 ) : 0; |
32 | 31 | |
33 | | - $granularity2 = $is_logged_in? |
34 | | - ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity2 ) |
35 | | - : 0; |
| 32 | + $granularity2 = $is_logged_in ? |
| 33 | + ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity2 ) : 0; |
36 | 34 | |
37 | | - $granularity3 = $is_logged_in? |
38 | | - ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity3 ) |
39 | | - : 0; |
| 35 | + $granularity3 = $is_logged_in ? |
| 36 | + ClickTrackingHooks::getEditCountSince( $now - $wgClickTrackContribGranularity3 ) : 0; |
40 | 37 | |
41 | 38 | ClickTrackingHooks::trackEvent( |
42 | 39 | $session_id, // randomly generated session ID |
— | — | @@ -88,7 +85,7 @@ |
89 | 86 | |
90 | 87 | // TODO: create a more useful 'version number' |
91 | 88 | public function getVersion() { |
92 | | - return __CLASS__ . ': $Id: $'; |
| 89 | + return __CLASS__ . ': $Id$'; |
93 | 90 | } |
94 | 91 | |
95 | 92 | } |
\ No newline at end of file |
Property changes on: trunk/extensions/UsabilityInitiative/ClickTracking/ApiClickTracking.php |
___________________________________________________________________ |
Added: svn:keywords |
96 | 93 | + Id |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ApiSpecialClickTracking.php |
— | — | @@ -13,9 +13,7 @@ |
14 | 14 | * and "increment" as how many days to increment |
15 | 15 | * @see includes/api/ApiBase#execute() |
16 | 16 | */ |
17 | | - public function execute(){ |
18 | | - |
19 | | - |
| 17 | + public function execute() { |
20 | 18 | $params = $this->extractRequestParams(); |
21 | 19 | $this->validateParams( $params ); |
22 | 20 | $event_id = $params['eventid']; |
— | — | @@ -24,15 +22,10 @@ |
25 | 23 | $increment = $params['increment']; |
26 | 24 | $userDefString = $params['userdefs']; |
27 | 25 | |
28 | | - $click_data = array(); |
29 | | - try{ |
30 | | - $click_data = SpecialClickTracking::getChartData($event_id, $startdate, $enddate, $increment, $userDefString); |
31 | | - $this->getResult()->addValue(array('datapoints'), 'expert', $click_data['expert']); |
32 | | - $this->getResult()->addValue(array('datapoints'), 'basic', $click_data['basic']); |
33 | | - $this->getResult()->addValue(array('datapoints'), 'intermediate', $click_data['intermediate']); |
34 | | - } |
35 | | - catch(Exception $e){ /* no result */ } |
36 | | - |
| 26 | + try { |
| 27 | + $click_data = SpecialClickTracking::getChartData( $event_id, $startdate, $enddate, $increment, $userDefString ); |
| 28 | + $this->getResult()->addValue( null, 'datapoints', $click_data ); |
| 29 | + } catch ( Exception $e ) { /* no result */ } |
37 | 30 | } |
38 | 31 | |
39 | 32 | /** |
— | — | @@ -47,19 +40,6 @@ |
48 | 41 | } |
49 | 42 | } |
50 | 43 | |
51 | | - //check if event id parses to an int greater than zero |
52 | | - if( (int) $params['eventid'] <= 0){ |
53 | | - $this->dieUsage("Invalid event ID", "badeventid"); |
54 | | - } |
55 | | - |
56 | | - //check start and end date are of proper format |
57 | | - if($params['startdate'] != 0 && strptime( $this->space_out_date($params['startdate']), "%Y %m %d") === false){ |
58 | | - $this->dieUsage("startdate not in YYYYMMDD format: <<{$params['startdate']}>>", "badstartdate"); |
59 | | - } |
60 | | - if($params['enddate'] != 0 && strptime( $this->space_out_date($params['enddate']), "%Y %m %d") === false){ |
61 | | - $this->dieUsage("enddate not in YYYYMMDD format:<<{$params['enddate']}>>", "badenddate"); |
62 | | - } |
63 | | - |
64 | 44 | //check if increment is a positive int |
65 | 45 | if( (int) $params['increment'] <= 0){ |
66 | 46 | $this->dieUsage("Invalid increment", "badincrement"); |
— | — | @@ -102,10 +82,10 @@ |
103 | 83 | ApiBase::PARAM_MIN => 1 |
104 | 84 | ), |
105 | 85 | 'startdate' => array( |
106 | | - ApiBase::PARAM_TYPE => 'integer' |
| 86 | + ApiBase::PARAM_TYPE => 'timestamp' |
107 | 87 | ), |
108 | 88 | 'enddate' => array( |
109 | | - ApiBase::PARAM_TYPE => 'integer' |
| 89 | + ApiBase::PARAM_TYPE => 'timestamp' |
110 | 90 | ), |
111 | 91 | 'increment' => array( |
112 | 92 | ApiBase::PARAM_TYPE => 'integer', |
— | — | @@ -113,7 +93,8 @@ |
114 | 94 | ApiBase::PARAM_MAX => 365 //1 year |
115 | 95 | ), |
116 | 96 | 'userdefs' => array ( |
117 | | - ApiBase::PARAM_TYPE => 'string') |
| 97 | + ApiBase::PARAM_TYPE => 'string' |
| 98 | + ) |
118 | 99 | ); |
119 | 100 | } |
120 | 101 | |
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | // set the time window for what we consider 'recent' contributions, in days |
28 | 28 | $wgClickTrackContribGranularity1 = 60 * 60 * 24 * 365 / 2; // half a year |
29 | | -$wgClickTrackContribGranularity2 =60 * 60 * 24 * 365 / 4; // 1/4 a year (3 months approx) |
| 29 | +$wgClickTrackContribGranularity2 = 60 * 60 * 24 * 365 / 4; // 1/4 a year (3 months approx) |
30 | 30 | $wgClickTrackContribGranularity3 = 60 * 60 * 24 * 30; //30 days (1 month approx) |
31 | 31 | |
32 | 32 | // Credits |