r41835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41834‎ | r41835 | r41836 >
Date:08:45, 8 October 2008
Author:siebrand
Status:old
Tags:
Comment:
Updating indentation, run stylize.php, removing whitespace
Modified paths:
  • /trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber.i18n.php (modified) (history)
  • /trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber.php (modified) (history)
  • /trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber_body.php (modified) (history)
  • /trunk/extensions/PlayerStatsGrabber/playerStats.js (modified) (history)
  • /trunk/extensions/PlayerStatsGrabber/playerStats.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber_body.php
@@ -3,183 +3,188 @@
44 if ( !defined( 'MEDIAWIKI' ) ) die();
55
66 class SpecialPlayerStatsGrabber extends SpecialPage {
7 - var $action='';
8 - function SpecialPlayerStatsGrabber() {
9 - SpecialPage::SpecialPage("PlayerStatsGrabber");
10 - wfLoadExtensionMessages('PlayerStatsGrabber');
11 - }
12 - //used for page title
13 - function getDescription(){
14 - switch($this->req_param){
15 - case 'Survey':
16 - return wfMsg('ps_take_video_survey');
17 - break;
18 - case '':
19 - default:
20 - return wfMsg('playerstatsgrabber');
21 - break;
22 - }
23 - }
24 - function execute( $par ) {
25 - global $wgRequest, $wgOut;
26 - $this->req_param = $par;
27 - print $wgRequest->getText('param');
28 - //set the header:
29 - $this->setHeaders();
30 -
31 - //do the page:
32 - switch($this->req_param){
33 - case 'Survey':
34 - //check if
35 - $this->do_survey_forum();
36 - break;
37 - case '':default:
38 - if($wgRequest->getVal('action')=='submit'){
39 - $this->do_submit();
40 - }else{
41 - $this->do_stats_page();
42 - }
43 - break;
44 - }
45 - }
46 - function do_stats_page(){
47 - global $wgOut, $wgRequest;
48 - $wgOut->addHTML( " $this->req_param stats output will go here, with a link to a full report once its available");
49 - }
50 - function do_survey_forum(){
51 - global $wgOut, $psEmbedAry, $wgTitle, $wgUser,$wgEnableParserCache, $wgParser, $wgScript;
52 - $wgOut->addHTML ( wfMsg('ps_survey_description'));
53 -
54 - //select the embed ary element:
55 - $tw=0;
56 - foreach($psEmbedAry as $embed){
57 - $tw+=$embed['weight'];
58 - }
59 - $selected_val = rand(1, $tw);
60 - $tw=0;
61 - foreach($psEmbedAry as $embed){
62 - $tw+=$embed['weight'];
63 - if($tw>=$selected_val){
64 - break;
65 - }
66 - }
67 - $embed_code='';
68 - if(isset($embed['html_code'])){
69 - //run the stats (if not internal oggPlay)
70 - $this->runJS_Stats();
71 - $embed_code=$embed['html_code'];
72 - }else if(isset($embed['wiki_code'])){
73 - $popts = new ParserOptions;
74 - $parserOutput = $wgParser->parse( $embed['wiki_code'], $wgTitle, $popts);
75 - $embed_code = $parserOutput->getText();
76 - }
77 - //print "EMBED C: $embed_code \n";
78 - //$q = 'action='.$this->action;
79 - #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
80 - //$action = $wgScript.'?title='.$wgTitle->getDBKey() . '/Thanks';
81 - $action = $wgTitle->getLocalURL('action=submit');
82 - $jsUserHash = sha1( $wgUser->getName() . $wgProxyKey);
83 - $enUserHash = Xml::encodeJsVar( $jsUserHash );
84 - //work with "embed"
85 -
86 -
87 - //output table with flash and or video embed:
88 - $wgOut->addHTML( <<<EOT
 7+ var $action = '';
 8+ function SpecialPlayerStatsGrabber() {
 9+ SpecialPage::SpecialPage( "PlayerStatsGrabber" );
 10+ wfLoadExtensionMessages( 'PlayerStatsGrabber' );
 11+ }
 12+ // used for page title
 13+ function getDescription() {
 14+ switch( $this->req_param ) {
 15+ case 'Survey':
 16+ return wfMsg( 'ps_take_video_survey' );
 17+ break;
 18+ case '':
 19+ default:
 20+ return wfMsg( 'playerstatsgrabber' );
 21+ break;
 22+ }
 23+ }
 24+
 25+ function execute( $par ) {
 26+ global $wgRequest, $wgOut;
 27+ $this->req_param = $par;
 28+ print $wgRequest->getText( 'param' );
 29+ // set the header:
 30+ $this->setHeaders();
 31+
 32+ // do the page:
 33+ switch( $this->req_param ) {
 34+ case 'Survey':
 35+ // check if
 36+ $this->do_survey_forum();
 37+ break;
 38+ case '':default:
 39+ if ( $wgRequest->getVal( 'action' ) == 'submit' ) {
 40+ $this->do_submit();
 41+ } else {
 42+ $this->do_stats_page();
 43+ }
 44+ break;
 45+ }
 46+ }
 47+
 48+ function do_stats_page() {
 49+ global $wgOut, $wgRequest;
 50+ $wgOut->addHTML( " $this->req_param stats output will go here, with a link to a full report once its available" );
 51+ }
 52+
 53+ function do_survey_forum() {
 54+ global $wgOut, $psEmbedAry, $wgTitle, $wgUser, $wgEnableParserCache, $wgParser, $wgScript;
 55+ $wgOut->addHTML ( wfMsg( 'ps_survey_description' ) );
 56+
 57+ // select the embed ary element:
 58+ $tw = 0;
 59+ foreach ( $psEmbedAry as $embed ) {
 60+ $tw += $embed['weight'];
 61+ }
 62+ $selected_val = rand( 1, $tw );
 63+ $tw = 0;
 64+ foreach ( $psEmbedAry as $embed ) {
 65+ $tw += $embed['weight'];
 66+ if ( $tw >= $selected_val ) {
 67+ break;
 68+ }
 69+ }
 70+
 71+ $embed_code = '';
 72+
 73+ if ( isset( $embed['html_code'] ) ) {
 74+ // run the stats (if not internal oggPlay)
 75+ $this->runJS_Stats();
 76+ $embed_code = $embed['html_code'];
 77+ } else if ( isset( $embed['wiki_code'] ) ) {
 78+ $popts = new ParserOptions;
 79+ $parserOutput = $wgParser->parse( $embed['wiki_code'], $wgTitle, $popts );
 80+ $embed_code = $parserOutput->getText();
 81+ }
 82+ // print "EMBED C: $embed_code \n";
 83+ // $q = 'action='.$this->action;
 84+ # if ( "no" == $redirect ) { $q .= "&redirect=no"; }
 85+ // $action = $wgScript.'?title='.$wgTitle->getDBKey() . '/Thanks';
 86+ $action = $wgTitle->getLocalURL( 'action=submit' );
 87+ $jsUserHash = sha1( $wgUser->getName() . $wgProxyKey );
 88+ $enUserHash = Xml::encodeJsVar( $jsUserHash );
 89+ // work with "embed"
 90+
 91+
 92+ // output table with flash and or video embed:
 93+ $wgOut->addHTML( <<<EOT
8994 <p>
9095 <table>
9196 <tr>
9297 <td valign="top">
9398 $embed_code
94 - </td>
 99+ </td>
95100 <td valign="top">
96 - <form id="ps_editform" name="ps_editform" method="post" action="{$action}" enctype="multipart/form-data">
 101+ <form id="ps_editform" name="ps_editform" method="post" action="{$action}" enctype="multipart/form-data">
97102 <input type="hidden" name="uh" value={$enUserHash}>
98103 EOT
99104 );
100 - //output questions:
101 - $wgOut->addHTML( wfMsg('ps_could_play') );
102 - //yes no with expand
 105+ // output questions:
 106+ $wgOut->addHTML( wfMsg( 'ps_could_play' ) );
 107+ // yes no with expand
103108 $wgOut->addHTML( '<br><input type="radio" name="ps_could_play" value="yes"
104 - onclick="document.getElementById(\'ps_could_not_play\').style.display = \'none\';">'.
105 - wfMsg('ps_play_yes') .'<br>
106 - <input type="radio" name="ps_could_play" value="no"
107 - onclick="document.getElementById(\'ps_could_not_play\').style.display = \'inline\';">'.
108 - wfMsg('ps_play_no').'<p>
 109+ onclick="document.getElementById(\'ps_could_not_play\').style.display = \'none\';">' .
 110+ wfMsg( 'ps_play_yes' ) . '<br>
 111+ <input type="radio" name="ps_could_play" value="no"
 112+ onclick="document.getElementById(\'ps_could_not_play\').style.display = \'inline\';">' .
 113+ wfMsg( 'ps_play_no' ) . '<p>
109114 <div id="ps_could_not_play" style="display:none;">
110 - '.wfMsg('ps_problem_checkoff').'
 115+ ' . wfMsg( 'ps_problem_checkoff' ) . '
111116 <table border="0" cellspacing="0" cellpadding="0">
112117 <tr>
113118 <td><input type="checkbox" name="ps_no_video" value="1"></td>
114 - <td>'.wfMsg('ps_no_video').' </td>
 119+ <td>' . wfMsg( 'ps_no_video' ) . ' </td>
115120 </tr>
116121 <tr>
117122 <tr>
118123 <td><input type="checkbox" name="ps_jumpy_playback" value="1"></td>
119 - <td>'.wfMsg('ps_jumpy_playback').' </td>
 124+ <td>' . wfMsg( 'ps_jumpy_playback' ) . ' </td>
120125 </tr>
121 - <tr>
 126+ <tr>
122127 <td><input type="checkbox" name="ps_bad_sync" value="1"></td>
123 - <td>'.wfMsg('ps_bad_sync').' </td>
124 - </tr>
 128+ <td>' . wfMsg( 'ps_bad_sync' ) . ' </td>
 129+ </tr>
125130 <tr>
126131 <td><input type="checkbox" name="ps_no_sound" value="1"></td>
127 - <td>'.wfMsg('ps_no_sound').'</td>
 132+ <td>' . wfMsg( 'ps_no_sound' ) . '</td>
128133 </tr>
129 - </table>
130 - '.wfMsg('ps_problems_desc').'<br><textarea name="ps_problems_desc" rows="2" cols="40" MAXLENGTH="300"></textarea><br>
 134+ </table>
 135+ ' . wfMsg( 'ps_problems_desc' ) . '<br><textarea name="ps_problems_desc" rows="2" cols="40" MAXLENGTH="300"></textarea><br>
131136 </div>
132 - '.wfMsg('ps_would_install') . '<br>'.
133 - '<input type="radio" name="ps_would_install" value="yes">'.wfMsg('ps_yes_install').'<br>'.
134 - '<input type="radio" name="ps_would_install" value="no">'.wfMsg('ps_no_install').'<br>'
135 -);
136 - //if ie output switch check:
137 - if (preg_match('|MSIE ([0-9].[0-9]{1,2})|',$_SERVER['HTTP_USER_AGENT'],$matched)) {
138 - $wgOut->addHTML( '<br>'.
139 - wfMsg('ps_would_switch') .'<br>'.
140 - '<input type="radio" name="ps_would_switch" value="yes">'.wfMsg('ps_yes_switch').'<br>'.
141 - '<input type="radio" name="ps_would_switch" value="no">'.wfMsg('ps_no_install').'<br>'
142 - );
143 - }
144 - $wgOut->addHTML( '<br>'. wfMsg('ps_your_email').'<br>'.
145 - '<input type="text" name="ps_your_email" size="30" maxlength="200"><p>'.
146 - wfMsg('ps_privacy'). '<br>'.
147 - '<input type="submit" value="'.wfMsg('ps_submit_survey').'">'
 137+ ' . wfMsg( 'ps_would_install' ) . '<br>' .
 138+ '<input type="radio" name="ps_would_install" value="yes">' . wfMsg( 'ps_yes_install' ) . '<br>' .
 139+ '<input type="radio" name="ps_would_install" value="no">' . wfMsg( 'ps_no_install' ) . '<br>'
 140+);
 141+ // if ie output switch check:
 142+ if ( preg_match( '|MSIE ([0-9].[0-9]{1,2})|', $_SERVER['HTTP_USER_AGENT'], $matched ) ) {
 143+ $wgOut->addHTML( '<br>' .
 144+ wfMsg( 'ps_would_switch' ) . '<br>' .
 145+ '<input type="radio" name="ps_would_switch" value="yes">' . wfMsg( 'ps_yes_switch' ) . '<br>' .
 146+ '<input type="radio" name="ps_would_switch" value="no">' . wfMsg( 'ps_no_install' ) . '<br>'
 147+ );
 148+ }
 149+ $wgOut->addHTML( '<br>' . wfMsg( 'ps_your_email' ) . '<br>' .
 150+ '<input type="text" name="ps_your_email" size="30" maxlength="200"><p>' .
 151+ wfMsg( 'ps_privacy' ) . '<br>' .
 152+ '<input type="submit" value="' . wfMsg( 'ps_submit_survey' ) . '">'
148153 );
149 -
150 - $wgOut->addHTML('
 154+
 155+ $wgOut->addHTML( '
151156 </form>
152157 </td>
153158 </tr>
154 -</table>');
 159+</table>' );
155160 }
156 - function do_submit(){
 161+ function do_submit() {
157162 global $wgRequest;
158 - print_r($wgRequest);
159 - //print "NO VIDEO: "
160 - $insAry = array(
161 - 'user_hash' => $wgRequest->getVal('uh'),
162 -
163 - 'ps_could_play' => ( $wgRequest->getVal('ps_could_play')=='' )?0:1,
164 - 'ps_jumpy_playback' => ( $wgRequest->getVal('ps_jumpy_playback')=='' )?0:1,
165 - 'ps_no_video' => ( $wgRequest->getVal('ps_no_video')=='' )?0:1,
166 - 'ps_bad_sync' => ( $wgRequest->getVal('ps_bad_sync')=='' )?0:1,
167 - 'ps_no_sound' => ( $wgRequest->getVal('ps_no_sound')=='' )?0:1,
168 -
169 - 'ps_would_install' => ( $wgRequest->getVal('ps_would_install')=='no' )?0:1,
170 -
171 - 'ps_your_email' => htmlspecialchars( $wgRequest->getVal('ps_your_email' ) ),
172 - 'ps_problems_desc' => htmlspecialchars( $wgRequest->getVal('ps_problems_desc' ) )
 163+ print_r( $wgRequest );
 164+ // print "NO VIDEO: "
 165+ $insAry = array(
 166+ 'user_hash' => $wgRequest->getVal( 'uh' ),
 167+
 168+ 'ps_could_play' => ( $wgRequest->getVal( 'ps_could_play' ) == '' ) ? 0:1,
 169+ 'ps_jumpy_playback' => ( $wgRequest->getVal( 'ps_jumpy_playback' ) == '' ) ? 0:1,
 170+ 'ps_no_video' => ( $wgRequest->getVal( 'ps_no_video' ) == '' ) ? 0:1,
 171+ 'ps_bad_sync' => ( $wgRequest->getVal( 'ps_bad_sync' ) == '' ) ? 0:1,
 172+ 'ps_no_sound' => ( $wgRequest->getVal( 'ps_no_sound' ) == '' ) ? 0:1,
 173+
 174+ 'ps_would_install' => ( $wgRequest->getVal( 'ps_would_install' ) == 'no' ) ? 0:1,
 175+
 176+ 'ps_your_email' => htmlspecialchars( $wgRequest->getVal( 'ps_your_email' ) ),
 177+ 'ps_problems_desc' => htmlspecialchars( $wgRequest->getVal( 'ps_problems_desc' ) )
173178 );
174 - if( $wgRequest->getVal('ps_would_switch')!='')
175 - $insAry['ps_would_switch'] = ( $wgRequest->getVal('ps_would_switch')=='yes')?1:0;
176 -
177 - print_r($insAry);
 179+ if ( $wgRequest->getVal( 'ps_would_switch' ) != '' )
 180+ $insAry['ps_would_switch'] = ( $wgRequest->getVal( 'ps_would_switch' ) == 'yes' ) ? 1:0;
 181+
 182+ print_r( $insAry );
178183 }
179184 /* to run the stats in cases where we are not using oggHanndler to play*/
180 - function runJS_Stats(){
 185+ function runJS_Stats() {
181186 global $wgOut, $wgScriptPath;
182187 $scriptPath = OggHandler::getMyScriptPath();
183 - //include the javascript and do the stats
 188+ // include the javascript and do the stats
184189 $wgOut->addHTML( <<<EOT
185190 <script type="text/javascript" src="$scriptPath/OggPlayer.js"></script>
186191 <script type="text/javascript" src="$wgScriptPath/extensions/PlayerStatsGrabber/playerStats.js"></script>
@@ -188,7 +193,5 @@
189194 </script>
190195 EOT
191196 );
192 - }
 197+ }
193198 }
194 -
195 -?>
\ No newline at end of file
Index: trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber.i18n.php
@@ -3,33 +3,33 @@
44
55 $messages['en'] = array(
66 'playerstatsgrabber' => 'Player stats survey',
7 - 'ps_take_video_survey'=> 'Video playback survey',
8 - 'ps_survey_description'=> 'This survey will help improve support for rich media.
 7+ 'ps_take_video_survey' => 'Video playback survey',
 8+ 'ps_survey_description' => 'This survey will help improve support for rich media.
99 Please answer the following questions:',
10 - 'ps_could_play'=>'When you clicked "play", did the video playback perfectly with audio?',
11 - 'ps_play_yes' =>'Yes, the clip played perfectly',
12 - 'ps_play_no' =>'No, there were issues or it did not play',
 10+ 'ps_could_play' => 'When you clicked "play", did the video playback perfectly with audio?',
 11+ 'ps_play_yes' => 'Yes, the clip played perfectly',
 12+ 'ps_play_no' => 'No, there were issues or it did not play',
1313
1414 'ps_problem_checkoff' => 'Please mark any of the following problems if they occurred:',
1515
1616 'ps_no_video' => 'No video played back at all',
17 - 'ps_jumpy_playback' =>' Jumping playback (the video played,, then paused then played)',
 17+ 'ps_jumpy_playback' => ' Jumping playback (the video played,, then paused then played)',
1818 'ps_no_sound' => 'No audio, (my computer volume is on, but I hear no audio for this video)',
1919 'ps_bad_sync' => 'Audio was out of sync with the video',
2020
2121 'ps_problems_desc' => 'Please describe any additional issues below (optional):',
2222
23 - 'ps_would_install' =>'Would you install an additional plug-in to view videos on this wiki?',
24 - 'ps_no_install' =>'No, I would not install an additional plug-in',
25 - 'ps_yes_install' =>'Yes, I would install an additional plug-in',
 23+ 'ps_would_install' => 'Would you install an additional plug-in to view videos on this wiki?',
 24+ 'ps_no_install' => 'No, I would not install an additional plug-in',
 25+ 'ps_yes_install' => 'Yes, I would install an additional plug-in',
2626
27 - 'ps_would_switch' =>'You appear to be running Internet Explorer.
 27+ 'ps_would_switch' => 'You appear to be running Internet Explorer.
2828 Would you consider installing a different browser to improve your media experience on this wiki?',
29 - 'ps_yes_switch' =>'Yes, I would switch browsers',
30 - 'ps_no_switch' =>'No, I would switch browsers',
 29+ 'ps_yes_switch' => 'Yes, I would switch browsers',
 30+ 'ps_no_switch' => 'No, I would switch browsers',
3131
32 - 'ps_your_email' =>'Your email address (optional)',
33 - 'ps_submit_survey' =>'Submit survey',
34 - 'ps_privacy' =>'Privacy link or note goes here',
35 - 'ps_thanks' =>'Thank you for participating in this video survey',
 32+ 'ps_your_email' => 'Your email address (optional)',
 33+ 'ps_submit_survey' => 'Submit survey',
 34+ 'ps_privacy' => 'Privacy link or note goes here',
 35+ 'ps_thanks' => 'Thank you for participating in this video survey',
3636 );
Index: trunk/extensions/PlayerStatsGrabber/PlayerStatsGrabber.php
@@ -1,121 +1,120 @@
22 <?php
33 /*
4 - * simple stats output and gather for oggPlay and a "sample page"
5 - */
 4+ * simple stats output and gather for oggPlay and a "sample page"
 5+ */
66
77 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
8 -if (!defined('MEDIAWIKI')) {
9 - echo <<<EOT
 8+if ( !defined( 'MEDIAWIKI' ) ) {
 9+ echo <<<EOT
1010 To install my extension, put the following line in LocalSettings.php:
1111 require_once( "\$IP/extensions/MyExtension/MyExtension.php" );
1212 EOT;
13 - exit( 1 );
 13+ exit( 1 );
1414 }
1515 /*
1616 * config values
1717 */
1818
19 -//embed code and "weight" (ie weight of 3 is 3x more likely than weight of 1)
20 -//flash embed coode (the raw html that gets outputed to the browers)
 19+// embed code and "weight" (ie weight of 3 is 3x more likely than weight of 1)
 20+// flash embed coode (the raw html that gets outputed to the browers)
2121 $psEmbedAry = array(
22 - array( 'embed_type'=>'flash',
23 - 'source_type'=>'youtube',
24 - 'name'=>'Sample Youtube Embed',
25 - 'weight'=>1,
26 - 'html_code'=>'<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/eaADQTeZRCY&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/eaADQTeZRCY&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>'
 22+ array(
 23+ 'embed_type' => 'flash',
 24+ 'source_type' => 'youtube',
 25+ 'name' => 'Sample Youtube Embed',
 26+ 'weight' => 1,
 27+ 'html_code' => '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/eaADQTeZRCY&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/eaADQTeZRCY&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>'
2728 ),
28 - array( 'embed_type' =>'ogg',
29 - 'name'=>'Sample oggPlay Embed',
30 - 'weight'=>1,
31 - 'wiki_code' =>'[[Image:Sample_fish.ogg]]'
 29+ array(
 30+ 'embed_type' => 'ogg',
 31+ 'name' => 'Sample oggPlay Embed',
 32+ 'weight' => 1,
 33+ 'wiki_code' => '[[Image:Sample_fish.ogg]]'
3234 )
3335 );
3436
35 -
36 -
3737 /*
3838 * end config
3939 */
4040
41 -$wgExtensionMessagesFiles['PlayerStatsGrabber'] = dirname( __FILE__ ) . '/PlayerStatsGrabber.i18n.php';
42 -$wgAutoloadClasses['SpecialPlayerStatsGrabber'] = dirname( __FILE__ ) . '/PlayerStatsGrabber_body.php';
43 -$wgSpecialPages['PlayerStatsGrabber'] = array( 'SpecialPlayerStatsGrabber' );
44 -
 41+$wgExtensionMessagesFiles['PlayerStatsGrabber'] = dirname( __FILE__ ) . '/PlayerStatsGrabber.i18n.php';
 42+$wgAutoloadClasses['SpecialPlayerStatsGrabber'] = dirname( __FILE__ ) . '/PlayerStatsGrabber_body.php';
 43+$wgSpecialPages['PlayerStatsGrabber'] = array( 'SpecialPlayerStatsGrabber' );
 44+
4545 $wgSpecialPageGroups['PlayerStatsGrabber'] = 'wiki'; // like Special:Statistics
4646
47 -//add ajax hook to accept the status input:
 47+// add ajax hook to accept the status input:
4848 $wgAjaxExportList[] = 'mw_push_player_stats';
4949
5050 $wgExtensionCredits['media'][] = array(
5151 'name' => 'PlayerStats',
5252 'author' => 'Michael Dale',
53 - 'svn-date' => '$LastChangedDate: 2008-08-06 07:18:43 -0700 (Wed, 06 Aug 2008) $',
 53+ 'svn-date' => '$LastChangedDate: 2008-08-06 07:18:43 -0700 (Wed, 06 Aug 2008) $',
5454 'svn-revision' => '$LastChangedRevision: 38715 $',
5555 'url' => 'http://www.mediawiki.org/wiki/Extension:PlayerStats',
56 - 'description' => 'PlayerStats and survey for monitoring theora support relative to flash'
 56+ 'description' => 'PlayerStats and survey for monitoring theora support relative to flash'
5757 );
5858
59 -
6059 /*
6160 * does a player stats request.. returns the "db key"
62 - * (lets people fill out survay after playing clip)
63 - * or
64 - * (ties survay page data to detection)
 61+ * (lets people fill out survay after playing clip)
 62+ * or
 63+ * (ties survay page data to detection)
6564 */
66 -function mw_push_player_stats(){
67 - global $wgRequest;
68 - //do the insert into the userPlayerStats table:
 65+function mw_push_player_stats() {
 66+ global $wgRequest;
 67+ // do the insert into the userPlayerStats table:
6968 $dbr =& wfGetDB( DB_READ );
70 - if( $wgRequest->getVal('cb')==''
71 - || $wgRequest->getVal('cb_inx')==''
72 - || $wgRequest->getVal('uh')==''){
73 - //output error:
 69+ if ( $wgRequest->getVal( 'cb' ) == ''
 70+ || $wgRequest->getVal( 'cb_inx' ) == ''
 71+ || $wgRequest->getVal( 'uh' ) == '' ) {
 72+ // output error:
7473 return 'error: missing param for json callback';
75 - }
76 - if(!isset($wgRequest->data['cs'])|| !is_array($wgRequest->data['cs'])){
77 - $wgRequest->data['cs']=array();
7874 }
79 - //set up insert array:
 75+ if ( !isset( $wgRequest->data['cs'] ) || !is_array( $wgRequest->data['cs'] ) ) {
 76+ $wgRequest->data['cs'] = array();
 77+ }
 78+ // set up insert array:
8079 $insAry = array(
81 - 'user_hash' => $wgRequest->getVal('uh'),
82 - 'b_user_agent' => $wgRequest->getVal('b_user_agent'),
83 - 'b_name' => $wgRequest->getVal('b_name'),
84 - 'b_version' => $wgRequest->getVal('b_version'),
85 - 'b_os' => $wgRequest->getVal('b_os'),
86 - 'flash_version' => $wgRequest->getVal('fv'),
87 - 'java_version' => $wgRequest->getVal('jv'),
88 - 'html5_video_enabled'=>(in_array('videoElement', $wgRequest->data['cs'] ))?true:false,
89 - 'java_enabled' => ( in_array('cortado', $wgRequest->data['cs'] ) )?true:false,
90 - 'totem_enabled' => ( in_array('totem', $wgRequest->data['cs'] ) )?true:false,
91 - 'flash_enabled' =>( in_array('flash', $wgRequest->data['cs'] ) )?true:false,
92 - 'quicktime_enabled' =>( in_array( array('quicktime-mozilla','quicktime-activex'),
93 - $wgRequest->data['cs'] )
94 - )?true:false,
95 - 'vlc_enabled' =>( in_array( array('vlc-mozilla', 'vlc-activex'),
96 - $wgRequest->data['cs'] )
97 - )?true:false,
98 - 'mplayer_enabled' =>( in_array( 'mplayerplug-in',
99 - $wgRequest->data['cs'] )
100 - )?true:false
101 - );
102 - //check for user hash (don't collect multiple times for the same user)
103 - //$user_hash =
104 - $insert_id = $dbr->selectField('player_stats_log', 'id',
105 - array( 'user_hash'=>$wgRequest->getVal('uh') ),
106 - 'mw_push_player_stats::Select User Hash');
107 - //last_insert_id
108 - if( $insert_id ){
109 - //for now don't insert repeates
110 - }else{
 80+ 'user_hash' => $wgRequest->getVal( 'uh' ),
 81+ 'b_user_agent' => $wgRequest->getVal( 'b_user_agent' ),
 82+ 'b_name' => $wgRequest->getVal( 'b_name' ),
 83+ 'b_version' => $wgRequest->getVal( 'b_version' ),
 84+ 'b_os' => $wgRequest->getVal( 'b_os' ),
 85+ 'flash_version' => $wgRequest->getVal( 'fv' ),
 86+ 'java_version' => $wgRequest->getVal( 'jv' ),
 87+ 'html5_video_enabled' => ( in_array( 'videoElement', $wgRequest->data['cs'] ) ) ? true:false,
 88+ 'java_enabled' => ( in_array( 'cortado', $wgRequest->data['cs'] ) ) ? true:false,
 89+ 'totem_enabled' => ( in_array( 'totem', $wgRequest->data['cs'] ) ) ? true:false,
 90+ 'flash_enabled' => ( in_array( 'flash', $wgRequest->data['cs'] ) ) ? true:false,
 91+ 'quicktime_enabled' => ( in_array( array( 'quicktime-mozilla', 'quicktime-activex' ),
 92+ $wgRequest->data['cs'] )
 93+ ) ? true:false,
 94+ 'vlc_enabled' => ( in_array( array( 'vlc-mozilla', 'vlc-activex' ),
 95+ $wgRequest->data['cs'] )
 96+ ) ? true:false,
 97+ 'mplayer_enabled' => ( in_array( 'mplayerplug-in',
 98+ $wgRequest->data['cs'] )
 99+ ) ? true:false
 100+ );
 101+ // check for user hash (don't collect multiple times for the same user)
 102+ // $user_hash =
 103+ $insert_id = $dbr->selectField( 'player_stats_log', 'id',
 104+ array( 'user_hash' => $wgRequest->getVal( 'uh' ) ),
 105+ 'mw_push_player_stats::Select User Hash' );
 106+ // last_insert_id
 107+ if ( $insert_id ) {
 108+ // for now don't insert repeates
 109+ } else {
111110 $dbw =& wfGetDB( DB_WRITE );
112 - $dbw->insert( 'player_stats_log', $insAry, 'mw_push_player_stats:Insert');
 111+ $dbw->insert( 'player_stats_log', $insAry, 'mw_push_player_stats:Insert' );
113112 $insert_id = $dbw->insertId();
114113 $dbw->commit();
115114 }
116115 header( 'Content-Type: text/javascript' );
117 - return htmlspecialchars( $wgRequest->getVal('cb') ). '(' .PhpArrayToJsObject_Recurse(
118 - array(
119 - 'cb_inx' => htmlspecialchars( $wgRequest->getVal('cb_inx') ),
 116+ return htmlspecialchars( $wgRequest->getVal( 'cb' ) ) . '(' . PhpArrayToJsObject_Recurse(
 117+ array(
 118+ 'cb_inx' => htmlspecialchars( $wgRequest->getVal( 'cb_inx' ) ),
120119 'id' => $insert_id
121120 )
122121 ) . ');';
@@ -123,47 +122,48 @@
124123
125124 /*
126125 * @@todo should use API json output wrappers
127 - */
128 -if( ! function_exists('php2jsObj') ){
 126+ */
 127+if ( ! function_exists( 'php2jsObj' ) ) {
129128 function php2jsObj( $array, $objName = 'mv_result' )
130129 {
131130 return $objName . ' = ' . phpArrayToJsObject_Recurse( $array ) . ";\n";
132131 }
133132 }
134 -if( ! function_exists('PhpArrayToJsObject_Recurse') ){
 133+if ( ! function_exists( 'PhpArrayToJsObject_Recurse' ) ) {
135134 function PhpArrayToJsObject_Recurse( $array ) {
136 - // Base case of recursion: when the passed value is not a PHP array, just output it (in quotes).
137 - if ( ! is_array( $array ) && !is_object( $array ) ) {
138 - // Handle null specially: otherwise it becomes "".
139 - if ( $array === null )
140 - {
141 - return 'null';
142 - }
143 - return '"' . javascript_escape( $array ) . '"';
144 - }
145 - // Open this JS object.
146 - $retVal = "{";
147 - // Output all key/value pairs as "$key" : $value
148 - // * Output a JS object (using recursion), if $value is a PHP array.
149 - // * Output the value in quotes, if $value is not an array (see above).
150 - $first = true;
151 - foreach ( $array as $key => $value ) {
152 - // Add a comma before all but the first pair.
153 - if ( ! $first ) {
154 - $retVal .= ', ';
155 - }
156 - $first = false;
157 - // Quote $key if it's a string.
158 - if ( is_string( $key ) ) {
159 - $key = '"' . $key . '"';
160 - }
161 - $retVal .= $key . ' : ' . PhpArrayToJsObject_Recurse( $value );
162 - }
163 - // Close and return the JS object.
164 - return $retVal . "}";
 135+ // Base case of recursion: when the passed value is not a PHP array, just output it (in quotes).
 136+ if ( ! is_array( $array ) && !is_object( $array ) ) {
 137+ // Handle null specially: otherwise it becomes "".
 138+ if ( $array === null )
 139+ {
 140+ return 'null';
 141+ }
 142+ return '"' . javascript_escape( $array ) . '"';
 143+ }
 144+ // Open this JS object.
 145+ $retVal = "{";
 146+ // Output all key/value pairs as "$key" : $value
 147+ // * Output a JS object (using recursion), if $value is a PHP array.
 148+ // * Output the value in quotes, if $value is not an array (see above).
 149+ $first = true;
 150+ foreach ( $array as $key => $value ) {
 151+ // Add a comma before all but the first pair.
 152+ if ( ! $first ) {
 153+ $retVal .= ', ';
 154+ }
 155+ $first = false;
 156+ // Quote $key if it's a string.
 157+ if ( is_string( $key ) ) {
 158+ $key = '"' . $key . '"';
 159+ }
 160+ $retVal .= $key . ' : ' . PhpArrayToJsObject_Recurse( $value );
 161+ }
 162+ // Close and return the JS object.
 163+ return $retVal . "}";
165164 }
166165 }
167 -if( ! function_exists('javascript_escape')){
 166+
 167+if ( ! function_exists( 'javascript_escape' ) ) {
168168 function javascript_escape( $val ) {
169169 // first strip /r
170170 $val = str_replace( "\r", '', $val );
@@ -172,5 +172,3 @@
173173 $val );
174174 }
175175 }
176 -
177 -?>
\ No newline at end of file
Index: trunk/extensions/PlayerStatsGrabber/playerStats.js
@@ -1,6 +1,6 @@
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 = "";
 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 = "";
55 var global_req_cb = new Array();//the global request callback array
66
77 /*parseUri class:*/
@@ -13,59 +13,59 @@
1414 this.doStats();
1515 },
1616 doStats:function() {
17 - //make sure we ran detect:
 17+ //make sure we ran detect:
1818 if (!this.detectionDone) {
1919 this.detect();
2020 }
21 -
22 - //build our request url:
 21+
 22+ //build our request url:
2323 if( wgServerOveride!="" ){
2424 url= wgServerOveride;
2525 }else{
2626 url = wgServer +((wgScript == null) ? (wgScriptPath + "/index.php") : wgScript);
2727 }
28 - url += "?action=ajax&rs=mw_push_player_stats";
29 -
30 - //detect windows media player ( direct show filters could be installed)
31 - if ( navigator.mimeTypes && navigator.mimeTypes["video/x-ms-wm"] &&
 28+ url += "?action=ajax&rs=mw_push_player_stats";
 29+
 30+ //detect windows media player ( direct show filters could be installed)
 31+ if ( navigator.mimeTypes && navigator.mimeTypes["video/x-ms-wm"] &&
3232 navigator.mimeTypes["video/x-ms-wm"].enabledPlugin){
3333 this.clientSupports['ms_video'];
3434 }
3535 //@@todo research if we can detect if MS video support a given codec
36 -
 36+
3737 //detect flash support
3838 if( FlashDetect.installed )
39 - this.clientSupports['flash']=true;
40 -
 39+ this.clientSupports['flash']=true;
 40+
4141 var j=0;
4242 for(var i in this.clientSupports){
4343 url+='&cs[]='+encodeURIComponent(i);
4444 j++;
4545 }
46 -
 46+
4747 //get the flash version:
4848 url+='&fv='+ encodeURIComponent( FlashDetect.raw );
49 -
50 -
51 - //detect java version if possible: (ie not IE with default security)
 49+
 50+
 51+ //detect java version if possible: (ie not IE with default security)
5252 if( javaDetect.version ){
5353 url+= '&jv='+ encodeURIComponent ( javaDetect.version );
5454 }
55 -
56 - //add some additional params seperated out to enum keys:
57 - url+= '&b_user_agent=' +encodeURIComponent( navigator.userAgent );
 55+
 56+ //add some additional params seperated out to enum keys:
 57+ url+= '&b_user_agent=' +encodeURIComponent( navigator.userAgent );
5858 url+= '&b_name=' + encodeURIComponent( BrowserDetect.browser ) ;
5959 url+= '&b_version=' + encodeURIComponent( BrowserDetect.version );
60 - url+= '&b_os=' + encodeURIComponent( BrowserDetect.OS ) ;
61 -
 60+ url+= '&b_os=' + encodeURIComponent( BrowserDetect.OS ) ;
 61+
6262 //and finaly add the user hash:
6363 url+='&uh=' + encodeURIComponent ( wgOggPlayer.userHash );
64 -
65 - //now send out our stats update (run via javascript include to support remote servers:
 64+
 65+ //now send out our stats update (run via javascript include to support remote servers:
6666 do_request ( url, function( responseObj ){
6767 wg_ran_stats( responseObj );
68 - });
69 - }
 68+ });
 69+ }
7070 }
7171 //extend the OggHandler object for stats collection
7272 for(i in wgOggPlayer){
@@ -77,9 +77,9 @@
7878 function wg_ran_stats(responseObj){
7979 js_log('did stats with id:' + responseObj['id']);
8080 }
81 -/*
 81+/*
8282 * a few utily functions
83 - * to enable cross site requests via json:
 83+ * to enable cross site requests via json:
8484 */
8585 function loadExternalJs(url){
8686 js_log('load js: '+ url);
@@ -104,7 +104,7 @@
105105 }
106106 function js_log(string){
107107 if( window.console ){
108 - console.log(string);
 108+ console.log(string);
109109 }else{
110110 /*
111111 * IE and non-firebug debug:
@@ -127,20 +127,20 @@
128128 javaEnabled: false,
129129 version: false,
130130 init:function(){
131 - if (typeof navigator != 'undefined' && typeof navigator.javaEnabled != 'undefined'){
 131+ if (typeof navigator != 'undefined' && typeof navigator.javaEnabled != 'undefined'){
132132 this.javaEnabled = navigator.javaEnabled();
133133 }else{
134134 this.javaEnabled = 'unknown';
135135 }
136136 if (navigator.javaEnabled() && typeof java != 'undefined')
137 - this.version = java.lang.System.getProperty("java.version");
138 - //try to get the IE version of java (not likely to work with default security setting)
 137+ this.version = java.lang.System.getProperty("java.version");
 138+ //try to get the IE version of java (not likely to work with default security setting)
139139 if( wgOggPlayer.msie ){
140140 var shell;
141141 try {
142142 // Create WSH(WindowsScriptHost) shell, available on Windows only
143143 shell = new ActiveXObject("WScript.Shell");
144 -
 144+
145145 if (shell != null) {
146146 // Read JRE version from Window Registry
147147 try {
Index: trunk/extensions/PlayerStatsGrabber/playerStats.sql
@@ -35,4 +35,3 @@
3636 PRIMARY KEY (`id`),
3737 KEY `user_hash` (`user_hash`)
3838 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;
39 -

Status & tagging log