r41767 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41766‎ | r41767 | r41768 >
Date:17:23, 6 October 2008
Author:dale
Status:old
Tags:
Comment:
Player Stats Grabber extension stub
Modified paths:
  • /trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber.i18n.php (added) (history)
  • /trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber.php (added) (history)
  • /trunk/extensions/PlayerStatsGrabber/SpecialPlayerStatsPage.php (added) (history)
  • /trunk/extensions/PlayerStatsGrabber/playerStats.js (added) (history)

Diff [purge]

Index: trunk/extensions/PlayerStatsGrabber/SpecialPlayerStatsPage.php
@@ -0,0 +1,7 @@
 2+<?php
 3+/* hanndles acutal output of special stats page */
 4+
 5+class SpecialPlayerStatsPage extends SpecialPage {
 6+
 7+}
 8+?>
\ No newline at end of file
Index: trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber.i18n.php
@@ -0,0 +1,3 @@
 2+<?php
 3+
 4+?>
\ No newline at end of file
Index: trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber.php
@@ -0,0 +1,39 @@
 2+<?php
 3+/*
 4+ * simple stats output and gather for oggPlay and a "sample page"
 5+ */
 6+
 7+//add SpecialPlayerStats Output page:
 8+$wgSpecialPages['PlayerStats'] = array('SpecialPlayerStatsPage',
 9+ 'PlayerStats',
 10+ 'mwExecutePlayerStats',
 11+ dirname( __FILE__ ) . '/specials/Statistics/SMW_SpecialStatistics.php', true, '');
 12+$wgSpecialPageGroups['PlayerStats'] = 'wiki'; // like Special:Statistics
 13+
 14+//add ajax hook to accept the status input:
 15+$wgAjaxExportList[] = 'mw_push_player_stats';
 16+
 17+$wgExtensionCredits['media'][] = array(
 18+ 'name' => 'PlayerStats',
 19+ 'author' => 'Michael Dale',
 20+ 'svn-date' => '$LastChangedDate: 2008-08-06 07:18:43 -0700 (Wed, 06 Aug 2008) $',
 21+ 'svn-revision' => '$LastChangedRevision: 38715 $',
 22+ 'url' => 'http://www.mediawiki.org/wiki/Extension:PlayerStats',
 23+ 'description' => 'PlayerStats and survey for monitoring theora support relative to flash'
 24+);
 25+
 26+
 27+/*
 28+ * does a player stats request.. returns the "db key"
 29+ * (lets people fill out survay after playing clip)
 30+ * or
 31+ * (ties survay page data to detection)
 32+ */
 33+function mw_push_player_stats(){
 34+ global $wgRequest;
 35+ //do the insert into the userPlayerStats table:
 36+ $dbw =& wfGetDB( DB_WRITE );
 37+ //print_r($wgRequest);
 38+
 39+}
 40+?>
\ No newline at end of file
Index: trunk/extensions/PlayerStatsGrabber/playerStats.js
@@ -0,0 +1,227 @@
 2+//wgServerOveride: leave empty to use the current server
 3+// (else provide the absolute url to index.php of the wiki you are recording stats to)
 4+var wgServerOveride = "";
 5+var global_req_cb = new Array();//the global request callback array
 6+
 7+/*parseUri class:*/
 8+var parseUri=function(d){var o=parseUri.options,value=o.parser[o.strictMode?"strict":"loose"].exec(d);for(var i=0,uri={};i<14;i++){uri[o.key[i]]=value[i]||""}uri[o.q.name]={};uri[o.key[12]].replace(o.q.parser,function(a,b,c){if(b)uri[o.q.name][b]=c});return uri};parseUri.options={strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};
 9+
 10+//extened version of OggHandler
 11+wgExtendedOggPlayerStats = {
 12+ init:function( player, params ) {
 13+ //call the parent function first
 14+ this.parent_init( player, params );
 15+ //build our request url:
 16+ if( wgServerOveride!="" ){
 17+ url= wgServerOveride;
 18+ }else{
 19+ url = wgServer +((wgScript == null) ? (wgScriptPath + "/index.php") : wgScript);
 20+ }
 21+ url += "?action=ajax&rs=mw_push_player_stats";
 22+
 23+ //detect windows media player ( direct show filters could be installed)
 24+ if ( navigator.mimeTypes && navigator.mimeTypes["video/x-ms-wm"] &&
 25+ navigator.mimeTypes["video/x-ms-wm"].enabledPlugin){
 26+ this.clientSupports['ms_video'];
 27+ }
 28+ //@@todo research if we can detect if MS video support a given codec
 29+
 30+ //detect flash support
 31+ if(FlashDetect.installed)
 32+ this.clientSupports['flash'];
 33+
 34+ for(i in this.clientSupports){
 35+ url+='&cs='+encodeURIComponent(i);
 36+ }
 37+ //get the flash version:
 38+ url+='&fv='+ encodeURIComponent( FlashDetect.raw );
 39+
 40+ //add some additional params seperated out to enum keys:
 41+ url+= '&b_user_agent=' +encodeURIComponent( navigator.userAgent );
 42+ url+= '&b_name=' + encodeURIComponent( BrowserDetect.browser ) ;
 43+ url+= '&b_version=' + encodeURIComponent( BrowserDetect.version );
 44+ url+= '&b_os=' + encodeURIComponent( BrowserDetect.OS ) ;
 45+
 46+
 47+ //now send out our stats update (run via javascript include to support remote servers:
 48+ do_request ( url, function( responseObj ){
 49+ wg_ran_stats( responseObj );
 50+ });
 51+ }
 52+}
 53+//extend the OggHandler object for stats collection
 54+for(i in wgOggPlayer){
 55+ if(typeof wgExtendedOggPlayerStats[i]!='undefined'){
 56+ wgOggPlayer['parent_'+i]= wgOggPlayer[i];
 57+ wgOggPlayer[i]=wgExtendedOggPlayerStats[i];
 58+ }
 59+}
 60+function wg_ran_stats(responseObj){
 61+ js_log('did stats with id:' + responseObj['id']);
 62+}
 63+/*
 64+ * a few utily functions
 65+ * to enable cross site requests via json:
 66+ */
 67+function loadExternalJs(url){
 68+ js_log('load js: '+ url);
 69+ var e = document.createElement("script");
 70+ e.setAttribute('src', url);
 71+ e.setAttribute('type',"text/javascript");
 72+ document.getElementsByTagName("head")[0].appendChild(e);
 73+}
 74+function do_request(req_url, callback, mv_json_response){
 75+ js_log('do request: ' + req_url);
 76+ global_req_cb.push(callback);
 77+ loadExternalJs(req_url+'&cb=mv_jsdata_cb&cb_inx='+(global_req_cb.length-1));
 78+}
 79+function mv_jsdata_cb(response){
 80+ js_log('f:mv_jsdata_cb:'+ response['cb_inx']);
 81+ //run the callback from the global req cb object:
 82+ if(!global_req_cb[response['cb_inx']]){
 83+ js_log('missing req cb index');
 84+ return false;
 85+ }
 86+ if(!response['pay_load']){
 87+ js_log("missing pay load");
 88+ return false;
 89+ }
 90+ global_req_cb[response['cb_inx']](response['pay_load']);
 91+}
 92+function js_log(string){
 93+ if( window.console ){
 94+ console.log(string);
 95+ }else{
 96+ /*
 97+ * IE and non-firebug debug:
 98+ */
 99+ /*var log_elm = document.getElementById('mv_js_log');
 100+ if(!log_elm){
 101+ document.write('<div style="position:absolute;z-index:500;top:0px;left:0px;right:0px;height:150px;"><textarea id="mv_js_log" cols="80" rows="6"></textarea></div>');
 102+ var log_elm = document.getElementById('mv_js_log');
 103+ }
 104+ if(log_elm){
 105+ log_elm.value+=string+"\n";
 106+ }*/
 107+ }
 108+ //in case of "throw error" type usage
 109+ return false;
 110+}
 111+
 112+//http://www.featureblend.com/license.txt
 113+var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
 114+return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
 115+return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){}
 116+return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(typeof obj=="object"){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.release="1.0.3";
 117+
 118+//http://www.quirksmode.org/js/detect.html
 119+var BrowserDetect = {
 120+ init: function () {
 121+ this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
 122+ this.version = this.searchVersion(navigator.userAgent)
 123+ || this.searchVersion(navigator.appVersion)
 124+ || "an unknown version";
 125+ this.OS = this.searchString(this.dataOS) || "an unknown OS";
 126+ },
 127+ searchString: function (data) {
 128+ for (var i=0;i<data.length;i++) {
 129+ var dataString = data[i].string;
 130+ var dataProp = data[i].prop;
 131+ this.versionSearchString = data[i].versionSearch || data[i].identity;
 132+ if (dataString) {
 133+ if (dataString.indexOf(data[i].subString) != -1)
 134+ return data[i].identity;
 135+ }
 136+ else if (dataProp)
 137+ return data[i].identity;
 138+ }
 139+ },
 140+ searchVersion: function (dataString) {
 141+ var index = dataString.indexOf(this.versionSearchString);
 142+ if (index == -1) return;
 143+ return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
 144+ },
 145+ dataBrowser: [
 146+ {
 147+ string: navigator.userAgent,
 148+ subString: "Chrome",
 149+ identity: "Chrome"
 150+ },
 151+ { string: navigator.userAgent,
 152+ subString: "OmniWeb",
 153+ versionSearch: "OmniWeb/",
 154+ identity: "OmniWeb"
 155+ },
 156+ {
 157+ string: navigator.vendor,
 158+ subString: "Apple",
 159+ identity: "Safari"
 160+ },
 161+ {
 162+ prop: window.opera,
 163+ identity: "Opera"
 164+ },
 165+ {
 166+ string: navigator.vendor,
 167+ subString: "iCab",
 168+ identity: "iCab"
 169+ },
 170+ {
 171+ string: navigator.vendor,
 172+ subString: "KDE",
 173+ identity: "Konqueror"
 174+ },
 175+ {
 176+ string: navigator.userAgent,
 177+ subString: "Firefox",
 178+ identity: "Firefox"
 179+ },
 180+ {
 181+ string: navigator.vendor,
 182+ subString: "Camino",
 183+ identity: "Camino"
 184+ },
 185+ { // for newer Netscapes (6+)
 186+ string: navigator.userAgent,
 187+ subString: "Netscape",
 188+ identity: "Netscape"
 189+ },
 190+ {
 191+ string: navigator.userAgent,
 192+ subString: "MSIE",
 193+ identity: "Explorer",
 194+ versionSearch: "MSIE"
 195+ },
 196+ {
 197+ string: navigator.userAgent,
 198+ subString: "Gecko",
 199+ identity: "Mozilla",
 200+ versionSearch: "rv"
 201+ },
 202+ { // for older Netscapes (4-)
 203+ string: navigator.userAgent,
 204+ subString: "Mozilla",
 205+ identity: "Netscape",
 206+ versionSearch: "Mozilla"
 207+ }
 208+ ],
 209+ dataOS : [
 210+ {
 211+ string: navigator.platform,
 212+ subString: "Win",
 213+ identity: "Windows"
 214+ },
 215+ {
 216+ string: navigator.platform,
 217+ subString: "Mac",
 218+ identity: "Mac"
 219+ },
 220+ {
 221+ string: navigator.platform,
 222+ subString: "Linux",
 223+ identity: "Linux"
 224+ }
 225+ ]
 226+
 227+};
 228+BrowserDetect.init();

Status & tagging log