Index: branches/wmf/1.17wmf1/extensions/ClickTracking/ClickTracking.hooks.php |
— | — | @@ -175,7 +175,7 @@ |
176 | 176 | * @param $sessionId String: unique session id for this editing sesion |
177 | 177 | * @param $isLoggedIn Boolean: whether or not the user is logged in |
178 | 178 | * @param $namespace Integer: namespace the user is editing |
179 | | - * @param $eventId Integer: event type |
| 179 | + * @param $eventName String: event type |
180 | 180 | * @param $contribs Integer: contributions the user has made (or NULL if user not logged in) |
181 | 181 | * @param $contribs_in_timespan1 Integer: number of contributions user has made in timespan of granularity 1 |
182 | 182 | * (defined by ClickTracking/$wgClickTrackContribGranularity1) |
— | — | @@ -187,51 +187,74 @@ |
188 | 188 | * @param $relevantBucket String: name/index of the particular bucket we're concerned with for this event |
189 | 189 | * @return Boolean: true if the event was stored in the DB |
190 | 190 | */ |
191 | | - public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventId, $contribs = 0, |
| 191 | + public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventName, $contribs = 0, |
192 | 192 | $contribs_in_timespan1 = 0, $contribs_in_timespan2 = 0, $contribs_in_timespan3 = 0, $additional = null, $recordBucketInfo = true ) { |
193 | | - |
194 | | - $dbw = wfGetDB( DB_MASTER ); |
195 | | - $dbw->begin(); |
196 | | - // Builds insert information |
197 | | - $data = array( |
198 | | - 'action_time' => $dbw->timestamp(), |
199 | | - 'session_id' => (string) $sessionId, |
200 | | - 'is_logged_in' => (bool) $isLoggedIn, |
201 | | - 'user_total_contribs' => ( $isLoggedIn ? (int) $contribs : null ), |
202 | | - 'user_contribs_span1' => ( $isLoggedIn ? (int) $contribs_in_timespan1 : null ), |
203 | | - 'user_contribs_span2' => ( $isLoggedIn ? (int) $contribs_in_timespan2 : null ), |
204 | | - 'user_contribs_span3' => ( $isLoggedIn ? (int) $contribs_in_timespan3 : null ), |
205 | | - 'namespace' => (int) $namespace, |
206 | | - 'event_id' => (int) $eventId, |
207 | | - 'additional_info' => ( isset( $additional ) ? (string) $additional : null ) |
208 | | - ); |
209 | | - $db_status_buckets = true; |
210 | | - $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ ); |
211 | | - $dbw->commit(); |
| 193 | + |
| 194 | + global $wgClickTrackingDatabase, $wgClickTrackingLog; |
| 195 | + $retval = true; |
| 196 | + if ( $wgClickTrackingDatabase ) { |
| 197 | + $eventId = self::getEventIDFromName( $eventName ); |
| 198 | + $dbw = wfGetDB( DB_MASTER ); |
| 199 | + $dbw->begin(); |
| 200 | + // Builds insert information |
| 201 | + $data = array( |
| 202 | + 'action_time' => $dbw->timestamp(), |
| 203 | + 'session_id' => (string) $sessionId, |
| 204 | + 'is_logged_in' => (bool) $isLoggedIn, |
| 205 | + 'user_total_contribs' => ( $isLoggedIn ? (int) $contribs : null ), |
| 206 | + 'user_contribs_span1' => ( $isLoggedIn ? (int) $contribs_in_timespan1 : null ), |
| 207 | + 'user_contribs_span2' => ( $isLoggedIn ? (int) $contribs_in_timespan2 : null ), |
| 208 | + 'user_contribs_span3' => ( $isLoggedIn ? (int) $contribs_in_timespan3 : null ), |
| 209 | + 'namespace' => (int) $namespace, |
| 210 | + 'event_id' => (int) $eventId, |
| 211 | + 'additional_info' => ( isset( $additional ) ? (string) $additional : null ) |
| 212 | + ); |
| 213 | + $db_status_buckets = true; |
| 214 | + $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ ); |
| 215 | + $dbw->commit(); |
212 | 216 | |
213 | | - if( $recordBucketInfo && $db_status ){ |
214 | | - $buckets = self::unpackBucketInfo(); |
215 | | - if( $buckets ){ |
216 | | - foreach( $buckets as $bucketName => $bucketValue ){ |
217 | | - $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties', |
218 | | - array( |
219 | | - 'session_id' => (string) $sessionId, |
220 | | - 'property_name' => (string) $bucketName, |
221 | | - 'property_value' => (string) $bucketValue[0], |
222 | | - 'property_version' => (int) $bucketValue[1] |
223 | | - ), |
224 | | - __METHOD__, |
225 | | - array( 'IGNORE' ) |
226 | | - ); |
227 | | - $db_status_buckets = $db_status_buckets && $db_current_bucket_insert; |
228 | | - } |
229 | | - }//ifbuckets |
230 | | - }//ifrecord |
231 | | - |
232 | | - $dbw->commit(); |
233 | | - return ($db_status && $db_status_buckets); |
234 | | - |
235 | | - |
| 217 | + if( $recordBucketInfo && $db_status ){ |
| 218 | + $buckets = self::unpackBucketInfo(); |
| 219 | + if( $buckets ){ |
| 220 | + foreach( $buckets as $bucketName => $bucketValue ){ |
| 221 | + $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties', |
| 222 | + array( |
| 223 | + 'session_id' => (string) $sessionId, |
| 224 | + 'property_name' => (string) $bucketName, |
| 225 | + 'property_value' => (string) $bucketValue[0], |
| 226 | + 'property_version' => (int) $bucketValue[1] |
| 227 | + ), |
| 228 | + __METHOD__, |
| 229 | + array( 'IGNORE' ) |
| 230 | + ); |
| 231 | + $db_status_buckets = $db_status_buckets && $db_current_bucket_insert; |
| 232 | + } |
| 233 | + }//ifbuckets |
| 234 | + }//ifrecord |
| 235 | + |
| 236 | + $dbw->commit(); |
| 237 | + $retval = $db_status && $db_status_buckets; |
| 238 | + } |
| 239 | + if ( $wgClickTrackingLog ) { |
| 240 | + $msg = implode( "\t", array( |
| 241 | + // Replace tabs with spaces in all strings |
| 242 | + str_replace( "\t", ' ', $eventName ), |
| 243 | + wfTimestampNow(), |
| 244 | + (bool)$isLoggedIn, |
| 245 | + str_replace( "\t", ' ', $sessionId ), |
| 246 | + (int)$namespace, |
| 247 | + (int)$contribs, |
| 248 | + (int)$contribs_in_timespan1, |
| 249 | + (int)$contribs_in_timespan2, |
| 250 | + (int)$contribs_in_timespan3, |
| 251 | + str_replace( "\t", ' ', $additional ), |
| 252 | + ) ); |
| 253 | + wfErrorLog( $msg, $wgClickTrackingLog ); |
| 254 | + |
| 255 | + // No need to mess with $retval here, doing |
| 256 | + // $retval == $retval && true is useless |
| 257 | + } |
| 258 | + return $retval; |
236 | 259 | } |
237 | 260 | |
238 | 261 | public static function editPageShowEditFormFields( $editPage, $output ) { |
Index: branches/wmf/1.17wmf1/extensions/ClickTracking/ApiClickTracking.php |
— | — | @@ -33,9 +33,8 @@ |
34 | 34 | $additional = $params['additional']; |
35 | 35 | } |
36 | 36 | |
37 | | - // Event ID lookup table |
38 | 37 | // FIXME: API should already have urldecode()d |
39 | | - $eventId = ClickTrackingHooks::getEventIDFromName( urldecode( $eventid_to_lookup ) ); |
| 38 | + $eventName = urldecode( $eventid_to_lookup ); |
40 | 39 | |
41 | 40 | $isLoggedIn = $wgUser->isLoggedIn(); |
42 | 41 | $now = time(); |
— | — | @@ -52,7 +51,7 @@ |
53 | 52 | $sessionId, // randomly generated session ID |
54 | 53 | $isLoggedIn, // is the user logged in? |
55 | 54 | (int)$namespace, // what namespace are they editing? |
56 | | - $eventId, // event ID passed in |
| 55 | + $eventName, // event ID passed in |
57 | 56 | ( $isLoggedIn ? $wgUser->getEditCount() : 0 ), // total edit count or 0 if anonymous |
58 | 57 | $granularity1, // contributions made in granularity 1 time frame |
59 | 58 | $granularity2, // contributions made in granularity 2 time frame |
Index: branches/wmf/1.17wmf1/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( |