r91899 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91898‎ | r91899 | r91900 >
Date:18:47, 11 July 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: MFT r91664 (ClickTracking UDP), adapted a bit to apply
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/ClickTracking/ApiClickTracking.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/ClickTracking/ClickTracking.hooks.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/ClickTracking/ClickTracking.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/ClickTracking/ClickTracking.hooks.php
@@ -175,7 +175,7 @@
176176 * @param $sessionId String: unique session id for this editing sesion
177177 * @param $isLoggedIn Boolean: whether or not the user is logged in
178178 * @param $namespace Integer: namespace the user is editing
179 - * @param $eventId Integer: event type
 179+ * @param $eventName String: event type
180180 * @param $contribs Integer: contributions the user has made (or NULL if user not logged in)
181181 * @param $contribs_in_timespan1 Integer: number of contributions user has made in timespan of granularity 1
182182 * (defined by ClickTracking/$wgClickTrackContribGranularity1)
@@ -187,51 +187,74 @@
188188 * @param $relevantBucket String: name/index of the particular bucket we're concerned with for this event
189189 * @return Boolean: true if the event was stored in the DB
190190 */
191 - public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventId, $contribs = 0,
 191+ public static function trackEvent( $sessionId, $isLoggedIn, $namespace, $eventName, $contribs = 0,
192192 $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();
212216
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;
236259 }
237260
238261 public static function editPageShowEditFormFields( $editPage, $output ) {
Index: branches/wmf/1.17wmf1/extensions/ClickTracking/ApiClickTracking.php
@@ -33,9 +33,8 @@
3434 $additional = $params['additional'];
3535 }
3636
37 - // Event ID lookup table
3837 // FIXME: API should already have urldecode()d
39 - $eventId = ClickTrackingHooks::getEventIDFromName( urldecode( $eventid_to_lookup ) );
 38+ $eventName = urldecode( $eventid_to_lookup );
4039
4140 $isLoggedIn = $wgUser->isLoggedIn();
4241 $now = time();
@@ -52,7 +51,7 @@
5352 $sessionId, // randomly generated session ID
5453 $isLoggedIn, // is the user logged in?
5554 (int)$namespace, // what namespace are they editing?
56 - $eventId, // event ID passed in
 55+ $eventName, // event ID passed in
5756 ( $isLoggedIn ? $wgUser->getEditCount() : 0 ), // total edit count or 0 if anonymous
5857 $granularity1, // contributions made in granularity 1 time frame
5958 $granularity2, // contributions made in granularity 2 time frame
Index: branches/wmf/1.17wmf1/extensions/ClickTracking/ClickTracking.php
@@ -26,6 +26,11 @@
2727 $wgClickTrackContribGranularity2 = 60 * 60 * 24 * 365 / 4; // 3 months
2828 $wgClickTrackContribGranularity3 = 60 * 60 * 24 * 30; // 1 month
2929
 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+
3035 /* Setup */
3136
3237 $wgExtensionCredits['other'][] = array(

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91664ClickTracking: Add support for logging events to files or UDP through $wgClic...catrope18:30, 7 July 2011

Status & tagging log