Index: trunk/extensions/ClickTracking/ClickTracking.hooks.php |
— | — | @@ -169,7 +169,7 @@ |
170 | 170 | * @param $sessionId String: unique session id for this editing sesion |
171 | 171 | * @param $isLoggedIn Boolean: whether or not the user is logged in |
172 | 172 | * @param $namespace Integer: namespace the user is editing |
173 | | - * @param $eventId Integer: event type |
| 173 | + * @param $eventName String: event type |
174 | 174 | * @param $contribs Integer: contributions the user has made (or NULL if user not logged in) |
175 | 175 | * @param $contribs_in_timespan1 Integer: number of contributions user has made in timespan of granularity 1 |
176 | 176 | * (defined by ClickTracking/$wgClickTrackContribGranularity1) |
— | — | @@ -181,49 +181,74 @@ |
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 | | - public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventId, $contribs = 0, |
| 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 | | - |
188 | | - $dbw = wfGetDB( DB_MASTER ); |
189 | | - $dbw->begin(); |
190 | | - // Builds insert information |
191 | | - $data = array( |
192 | | - 'action_time' => $dbw->timestamp(), |
193 | | - 'session_id' => (string) $sessionId, |
194 | | - 'is_logged_in' => (bool) $isLoggedIn, |
195 | | - 'user_total_contribs' => ( $isLoggedIn ? (int) $contribs : null ), |
196 | | - 'user_contribs_span1' => ( $isLoggedIn ? (int) $contribs_in_timespan1 : null ), |
197 | | - 'user_contribs_span2' => ( $isLoggedIn ? (int) $contribs_in_timespan2 : null ), |
198 | | - 'user_contribs_span3' => ( $isLoggedIn ? (int) $contribs_in_timespan3 : null ), |
199 | | - 'namespace' => (int) $namespace, |
200 | | - 'event_id' => (int) $eventId, |
201 | | - 'additional_info' => ( isset( $additional ) ? (string) $additional : null ) |
202 | | - ); |
203 | | - $db_status_buckets = true; |
204 | | - $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ ); |
205 | | - $dbw->commit(); |
| 187 | + |
| 188 | + global $wgClickTrackingDatabase, $wgClickTrackingLog; |
| 189 | + $retval = true; |
| 190 | + if ( $wgClickTrackingDatabase ) { |
| 191 | + $eventId = self::getEventIDFromName( $eventName ); |
| 192 | + $dbw = wfGetDB( DB_MASTER ); |
| 193 | + $dbw->begin(); |
| 194 | + // Builds insert information |
| 195 | + $data = array( |
| 196 | + 'action_time' => $dbw->timestamp(), |
| 197 | + 'session_id' => (string) $sessionId, |
| 198 | + 'is_logged_in' => (bool) $isLoggedIn, |
| 199 | + 'user_total_contribs' => ( $isLoggedIn ? (int) $contribs : null ), |
| 200 | + 'user_contribs_span1' => ( $isLoggedIn ? (int) $contribs_in_timespan1 : null ), |
| 201 | + 'user_contribs_span2' => ( $isLoggedIn ? (int) $contribs_in_timespan2 : null ), |
| 202 | + 'user_contribs_span3' => ( $isLoggedIn ? (int) $contribs_in_timespan3 : null ), |
| 203 | + 'namespace' => (int) $namespace, |
| 204 | + 'event_id' => (int) $eventId, |
| 205 | + 'additional_info' => ( isset( $additional ) ? (string) $additional : null ) |
| 206 | + ); |
| 207 | + $db_status_buckets = true; |
| 208 | + $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ ); |
| 209 | + $dbw->commit(); |
206 | 210 | |
207 | | - if( $recordBucketInfo && $db_status ){ |
208 | | - $buckets = self::unpackBucketInfo(); |
209 | | - if( $buckets ){ |
210 | | - foreach( $buckets as $bucketName => $bucketValue ){ |
211 | | - $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties', |
212 | | - array( |
213 | | - 'session_id' => (string) $sessionId, |
214 | | - 'property_name' => (string) $bucketName, |
215 | | - 'property_value' => (string) $bucketValue[0], |
216 | | - 'property_version' => (int) $bucketValue[1] |
217 | | - ), |
218 | | - __METHOD__, |
219 | | - array( 'IGNORE' ) |
220 | | - ); |
221 | | - $db_status_buckets = $db_status_buckets && $db_current_bucket_insert; |
222 | | - } |
223 | | - }//ifbuckets |
224 | | - }//ifrecord |
225 | | - |
226 | | - $dbw->commit(); |
227 | | - return ($db_status && $db_status_buckets); |
| 211 | + if( $recordBucketInfo && $db_status ){ |
| 212 | + $buckets = self::unpackBucketInfo(); |
| 213 | + if( $buckets ){ |
| 214 | + foreach( $buckets as $bucketName => $bucketValue ){ |
| 215 | + $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties', |
| 216 | + array( |
| 217 | + 'session_id' => (string) $sessionId, |
| 218 | + 'property_name' => (string) $bucketName, |
| 219 | + 'property_value' => (string) $bucketValue[0], |
| 220 | + 'property_version' => (int) $bucketValue[1] |
| 221 | + ), |
| 222 | + __METHOD__, |
| 223 | + array( 'IGNORE' ) |
| 224 | + ); |
| 225 | + $db_status_buckets = $db_status_buckets && $db_current_bucket_insert; |
| 226 | + } |
| 227 | + }//ifbuckets |
| 228 | + }//ifrecord |
| 229 | + |
| 230 | + $dbw->commit(); |
| 231 | + $retval = $db_status && $db_status_buckets; |
| 232 | + } |
| 233 | + if ( $wgClickTrackingLog ) { |
| 234 | + $msg = implode( "\t", array( |
| 235 | + // Replace tabs with spaces in all strings |
| 236 | + str_replace( "\t", ' ', $eventName ), |
| 237 | + wfTimestampNow(), |
| 238 | + (bool)$isLoggedIn, |
| 239 | + str_replace( "\t", ' ', $sessionId ), |
| 240 | + (int)$namespace, |
| 241 | + (int)$contribs, |
| 242 | + (int)$contribs_in_timespan1, |
| 243 | + (int)$contribs_in_timespan2, |
| 244 | + (int)$contribs_in_timespan3, |
| 245 | + str_replace( "\t", ' ', $additional ), |
| 246 | + ) ); |
| 247 | + wfErrorLog( $msg, $wgClickTrackingLog ); |
| 248 | + |
| 249 | + // No need to mess with $retval here, doing |
| 250 | + // $retval == $retval && true is useless |
| 251 | + } |
| 252 | + return $retval; |
228 | 253 | } |
229 | 254 | |
230 | 255 | public static function editPageShowEditFormFields( $editPage, $output ) { |
Index: trunk/extensions/ClickTracking/ApiClickTracking.php |
— | — | @@ -32,9 +32,8 @@ |
33 | 33 | $additional = $params['additional']; |
34 | 34 | } |
35 | 35 | |
36 | | - // Event ID lookup table |
37 | 36 | // FIXME: API should already have urldecode()d |
38 | | - $eventId = ClickTrackingHooks::getEventIDFromName( urldecode( $eventid_to_lookup ) ); |
| 37 | + $eventName = urldecode( $eventid_to_lookup ); |
39 | 38 | |
40 | 39 | $isLoggedIn = $wgUser->isLoggedIn(); |
41 | 40 | $now = time(); |
— | — | @@ -51,7 +50,7 @@ |
52 | 51 | $sessionId, // randomly generated session ID |
53 | 52 | $isLoggedIn, // is the user logged in? |
54 | 53 | (int)$namespace, // what namespace are they editing? |
55 | | - $eventId, // event ID passed in |
| 54 | + $eventName, // event ID passed in |
56 | 55 | ( $isLoggedIn ? $wgUser->getEditCount() : 0 ), // total edit count or 0 if anonymous |
57 | 56 | $granularity1, // contributions made in granularity 1 time frame |
58 | 57 | $granularity2, // contributions made in granularity 2 time frame |
— | — | @@ -103,7 +102,7 @@ |
104 | 103 | ApiBase::PARAM_REQUIRED => true, |
105 | 104 | ), |
106 | 105 | 'namespacenumber' => array( |
107 | | - ApiBase::PARAM_TYPE => 'namespace', |
| 106 | + ApiBase::PARAM_TYPE => 'integer', // not 'namespace', we need to allow negative numbers |
108 | 107 | ApiBase::PARAM_REQUIRED => true, |
109 | 108 | ), |
110 | 109 | 'token' => array( |
Index: trunk/extensions/ClickTracking/ClickTracking.php |
— | — | @@ -26,6 +26,11 @@ |
27 | 27 | $wgClickTrackContribGranularity2 = 60 * 60 * 24 * 365 / 4; // 3 months |
28 | 28 | $wgClickTrackContribGranularity3 = 60 * 60 * 24 * 30; // 1 month |
29 | 29 | |
| 30 | +// If not false, log events to this file. May also be a UDP socket, denoted as udp://host:port/prefix |
| 31 | +$wgClickTrackingLog = false; |
| 32 | +// Whether to log clicks to the database. If this is enabled and a log file is configured, events will be logged to both |
| 33 | +$wgClickTrackingDatabase = true; |
| 34 | + |
30 | 35 | /* Setup */ |
31 | 36 | |
32 | 37 | $wgExtensionCredits['other'][] = array( |