Index: trunk/extensions/OggHandler/ApiPlayTracking/ApiPlayTracking.sql |
— | — | @@ -5,18 +5,18 @@ |
6 | 6 | CREATE TABLE IF NOT EXISTS /*_*/play_tracking ( |
7 | 7 | |
8 | 8 | -- 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, |
10 | 10 | |
11 | 11 | -- Filename of resource played |
12 | 12 | track_filename varchar(255) binary NOT NULL, |
13 | 13 | |
14 | 14 | -- Anonymous hash of client |
15 | | - track_client_hash varbinary(16) NOT NULL, |
| 15 | + track_client_id varbinary(32) NOT NULL, |
16 | 16 | |
17 | 17 | -- Browser and playback system dump. |
18 | 18 | track_clientplayer tinyblob NOT NULL, |
19 | 19 | |
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 ) |
21 | 21 | track_rate integer |
22 | 22 | |
23 | 23 | ) /*$wgDBTableOptions*/; |
Index: trunk/extensions/OggHandler/ApiPlayTracking/ApiPlayTracking.php |
— | — | @@ -15,14 +15,28 @@ |
16 | 16 | * @see includes/api/ApiBase#execute() |
17 | 17 | */ |
18 | 18 | public function execute() { |
19 | | - global $wgEnablePlayTracking; |
| 19 | + global $wgEnablePlayTracking, $wgSecretKey, $wgUser, $wgPlayTrackingRate; |
20 | 20 | if( ! $wgEnablePlayTracking ){ |
21 | 21 | $this->dieUsageMsg( array( 'unknownerror', 'Play tracking is not enabled' ) ); |
22 | 22 | } |
23 | 23 | $params = $this->extractRequestParams(); |
24 | 24 | $this->validateParams( $params ); |
25 | 25 | |
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 | + ); |
27 | 41 | } |
28 | 42 | |
29 | 43 | /** |
Index: trunk/extensions/OggHandler/OggHandler.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | ini_get( 'include_path' ) ); |
26 | 26 | |
27 | 27 | // Bump this when updating OggPlayer.js to help update caches |
28 | | -$wgOggScriptVersion = '10'; |
| 28 | +$wgOggScriptVersion = '11'; |
29 | 29 | |
30 | 30 | $wgExtensionMessagesFiles['OggHandler'] = "$oggDir/OggHandler.i18n.php"; |
31 | 31 | $wgExtensionMessagesFiles['OggHandlerMagic'] = "$oggDir/OggHandler.i18n.magic.php"; |
— | — | @@ -105,7 +105,7 @@ |
106 | 106 | ); |
107 | 107 | |
108 | 108 | // If play requests should be tracked. |
109 | | -$wgEnablePlayTracking = false; |
| 109 | +$wgEnablePlayTracking = true; |
110 | 110 | |
111 | 111 | // One out of how many requests should be tracked: |
112 | 112 | $wgPlayTrackingRate = 10; |
— | — | @@ -132,7 +132,7 @@ |
133 | 133 | // initial config time |
134 | 134 | |
135 | 135 | // 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. |
137 | 137 | |
138 | 138 | // Enable play tracking |
139 | 139 | if( $wgEnablePlayTracking ){ |
— | — | @@ -141,7 +141,7 @@ |
142 | 142 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'ApiPlayTracking::schema'; |
143 | 143 | |
144 | 144 | //Add the api entry point: |
145 | | - $wgAPIModules['playtracking'] = 'ApiPlayTracking'; |
| 145 | + $wgAPIModules[ 'playtracking' ] = 'ApiPlayTracking'; |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Enable timed text |
Index: trunk/extensions/OggHandler/OggPlayer.js |
— | — | @@ -84,6 +84,32 @@ |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
| 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 | + |
88 | 114 | elt.innerHTML = ''; |
89 | 115 | switch ( player ) { |
90 | 116 | case 'videoElement': |
— | — | @@ -134,7 +160,9 @@ |
135 | 161 | elt.appendChild( div ); |
136 | 162 | } |
137 | 163 | }, |
138 | | - |
| 164 | + 'playTrackingDone' : function( data ){ |
| 165 | + // play tracking done |
| 166 | + }, |
139 | 167 | 'debug': function( s ) { |
140 | 168 | //alert(s); |
141 | 169 | }, |