r61970 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61969‎ | r61970 | r61971 >
Date:08:31, 4 February 2010
Author:dale
Status:deferred
Tags:
Comment:
* finished basic play tracking support
* updated play tracking schema
* updated javascript to support "rate" based play tracking
Modified paths:
  • /trunk/extensions/OggHandler/ApiPlayTracking/ApiPlayTracking.php (modified) (history)
  • /trunk/extensions/OggHandler/ApiPlayTracking/ApiPlayTracking.sql (modified) (history)
  • /trunk/extensions/OggHandler/OggHandler.php (modified) (history)
  • /trunk/extensions/OggHandler/OggPlayer.js (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/ApiPlayTracking/ApiPlayTracking.sql
@@ -5,18 +5,18 @@
66 CREATE TABLE IF NOT EXISTS /*_*/play_tracking (
77
88 -- Unique id of play tracking event
9 - track_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT
 9+ track_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
1010
1111 -- Filename of resource played
1212 track_filename varchar(255) binary NOT NULL,
1313
1414 -- Anonymous hash of client
15 - track_client_hash varbinary(16) NOT NULL,
 15+ track_client_id varbinary(32) NOT NULL,
1616
1717 -- Browser and playback system dump.
1818 track_clientplayer tinyblob NOT NULL,
1919
20 - -- Rate we are tracking ( ie 10 means 1 in 10 tracked )
 20+ -- Rate we are tracking ( a value of 10 means 1 in 10 tracked )
2121 track_rate integer
2222
2323 ) /*$wgDBTableOptions*/;
Index: trunk/extensions/OggHandler/ApiPlayTracking/ApiPlayTracking.php
@@ -15,14 +15,28 @@
1616 * @see includes/api/ApiBase#execute()
1717 */
1818 public function execute() {
19 - global $wgEnablePlayTracking;
 19+ global $wgEnablePlayTracking, $wgSecretKey, $wgUser, $wgPlayTrackingRate;
2020 if( ! $wgEnablePlayTracking ){
2121 $this->dieUsageMsg( array( 'unknownerror', 'Play tracking is not enabled' ) );
2222 }
2323 $params = $this->extractRequestParams();
2424 $this->validateParams( $params );
2525
26 - // insert into the play_tracking table
 26+ // Salt the user id with $wgSecretKey to get a unique key per user
 27+ $clientId = md5( $wgUser->getName() . $wgSecretKey );
 28+
 29+ // Insert into the play_tracking table
 30+ $dbw = & wfGetDB( DB_WRITE );
 31+ $dbw->insert(
 32+ 'play_tracking',
 33+ array(
 34+ 'track_filename' => $params[ 'filename' ],
 35+ 'track_client_id' => $clientId,
 36+ 'track_clientplayer' => $params[ 'client' ],
 37+ 'track_rate' => $wgPlayTrackingRate
 38+ ),
 39+ __METHOD__
 40+ );
2741 }
2842
2943 /**
Index: trunk/extensions/OggHandler/OggHandler.php
@@ -24,7 +24,7 @@
2525 ini_get( 'include_path' ) );
2626
2727 // Bump this when updating OggPlayer.js to help update caches
28 -$wgOggScriptVersion = '10';
 28+$wgOggScriptVersion = '11';
2929
3030 $wgExtensionMessagesFiles['OggHandler'] = "$oggDir/OggHandler.i18n.php";
3131 $wgExtensionMessagesFiles['OggHandlerMagic'] = "$oggDir/OggHandler.i18n.magic.php";
@@ -105,7 +105,7 @@
106106 );
107107
108108 // If play requests should be tracked.
109 -$wgEnablePlayTracking = false;
 109+$wgEnablePlayTracking = true;
110110
111111 // One out of how many requests should be tracked:
112112 $wgPlayTrackingRate = 10;
@@ -132,7 +132,7 @@
133133 // initial config time
134134
135135 // Alternatively we could have top level php files that include the
136 -// following pieces of code, but that would distribute configuration
 136+// following pieces of code.
137137
138138 // Enable play tracking
139139 if( $wgEnablePlayTracking ){
@@ -141,7 +141,7 @@
142142 $wgHooks['LoadExtensionSchemaUpdates'][] = 'ApiPlayTracking::schema';
143143
144144 //Add the api entry point:
145 - $wgAPIModules['playtracking'] = 'ApiPlayTracking';
 145+ $wgAPIModules[ 'playtracking' ] = 'ApiPlayTracking';
146146 }
147147
148148 // Enable timed text
Index: trunk/extensions/OggHandler/OggPlayer.js
@@ -84,6 +84,32 @@
8585 }
8686 }
8787
 88+ // Do player tracking if enabled
 89+ if( this.playTracking ){
 90+
 91+ if( Math.floor( Math.random()* wgOggPlayer.playTrackingRate ) == 0 ){
 92+
 93+ var url = wgScript.replace( 'index.php', 'api.php');
 94+ var filename = params.linkUrl.replace(/.*File\:/, '');
 95+ var playerList = '';
 96+ var coma = '';
 97+ for(var i = 0 ; i < this.clientSupports.length ; i ++ ){
 98+ playerList+= i;
 99+ coma = ',';
 100+ }
 101+ url+= '?action=playtracking&filename=' + escape( filename );
 102+ url+= '&client=' + escape( player + '|' + playerList + '|' + navigator.userAgent );
 103+ url+= '&format=json&callback=wgOggPlayer.playTrackingDone';
 104+
 105+ // Issue the request by including the script ( far fewer lines than robust ajax call )
 106+ // (jQuery included by default would let us do clean jQuery.get calls )
 107+ var s = document.createElement('script');
 108+ s.setAttribute('src',url);
 109+ s.setAttribute('type','text/javascript');
 110+ document.getElementsByTagName('head')[0].appendChild(s);
 111+ }
 112+ }
 113+
88114 elt.innerHTML = '';
89115 switch ( player ) {
90116 case 'videoElement':
@@ -134,7 +160,9 @@
135161 elt.appendChild( div );
136162 }
137163 },
138 -
 164+ 'playTrackingDone' : function( data ){
 165+ // play tracking done
 166+ },
139167 'debug': function( s ) {
140168 //alert(s);
141169 },

Status & tagging log