r38747 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38746‎ | r38747 | r38748 >
Date:01:21, 7 August 2008
Author:dale
Status:old
Tags:
Comment:
improved basic flash support
Modified paths:
  • /branches/MetavidWiki-exp/MetavidWiki/includes/MV_DefaultSettings.php (modified) (history)
  • /branches/MetavidWiki-exp/MetavidWiki/includes/MV_StreamFile.php (modified) (history)
  • /branches/MetavidWiki-exp/MetavidWiki/includes/MV_Title.php (modified) (history)
  • /branches/MetavidWiki-exp/MetavidWiki/maintenance/download_from_archive_org.php (modified) (history)
  • /branches/MetavidWiki-exp/MetavidWiki/skins/mv_embed/flvServer/mvFlvServer.php (modified) (history)

Diff [purge]

Index: branches/MetavidWiki-exp/MetavidWiki/maintenance/download_from_archive_org.php
@@ -34,25 +34,31 @@
3535 while($stream = $dbr->fetchObject($result) ){
3636 $local_fl = MV_DOWNLOAD_DIR . $stream->name.'.flv';
3737 $remote_fl = MV_ARCHIVE_ORG_DL . $stream->name.'/'.$stream->name.'.flv';
 38+ //lets just skip local files for now and try to remove incomplete mannually
3839
39 - if(remotefsize($remote_fl)<100000){
40 - print "remote file: $remote_fl < 100k (skipping) \n";
41 - continue;
42 - }
 40+
4341 //senate_proceeding_08-01-07/senate_proceeding_08-01-07.flv
4442 //check local file size matches remote:
4543 if(is_file($local_fl)){
46 - print "file $local_fl present";
47 - if( filesize($local_fl)!=remotefsize($remote_fl)){
48 - echo ' local:'. formatbytes(filesize($local_fl)).
49 - ' != remote:' . formatbytes(remotefsize($remote_fl))."\n";
50 - echo 'attempting to resume: ' . "\n";
51 - curldownload($remote_fl, $local_fl);
 44+ print "file $local_fl present (skipping size check)\n";
 45+ /*if( filesize($local_fl)!=remotefsize($remote_fl)){
 46+ echo ' local:'. hr_bytes(filesize($local_fl)).
 47+ ' != remote:' . hr_bytes(remotefsize($remote_fl))."\n";
 48+ echo '(skipping): ' . "\n";
 49+ //curldownload($remote_fl, $local_fl);
5250 }else{
53 - echo ' sizes match: ' . formatbytes(filesize($local_fl)) .'='.
54 - formatbytes(remotefsize($remote_fl))."\n";
55 - }
 51+ echo ' sizes match: ' . hr_bytes(filesize($local_fl)) .'='.
 52+ hr_bytes(remotefsize($remote_fl))."\n";
 53+ }*/
5654 }else{
 55+ //check if flash file exists:
 56+ //$sql ="SELECT * FROM `mv_stream_files` WHERE `stream_id`=" .$stream->id
 57+ //ao_file_flash_flv
 58+
 59+ if(remotefsize($remote_fl)<100000){
 60+ print "remote file: $remote_fl < 100k (skipping) \n";
 61+ continue;
 62+ }
5763 echo "DL it: $remote_fl \n";
5864 if(curldownload($remote_fl, $local_fl)){
5965 echo 'succesfully grabed '.$remote_fl."\n";
@@ -100,7 +106,7 @@
101107 if($i==2000){
102108 $i=0;
103109 $lfs = filesize($file_target);
104 - print formatbytes($lfs) .' of '. formatbytes($remote_size)." of $sn \n";
 110+ print hr_bytes($lfs) .' of '. hr_bytes($remote_size)." of $sn \n";
105111 clearstatcache();
106112 }
107113 $i++;
@@ -115,64 +121,45 @@
116122 fclose($wh);
117123 return true;
118124 }
119 -function formatbytes($val, $digits = 4, $mode = "SI", $bB = "B"){ //$mode == "SI"|"IEC", $bB == "b"|"B"
120 - $si = array("", "k", "M", "G", "T", "P", "E", "Z", "Y");
121 - $iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi");
122 - switch(strtoupper($mode)) {
123 - case "SI" : $factor = 1000; $symbols = $si; break;
124 - case "IEC" : $factor = 1024; $symbols = $iec; break;
125 - default : $factor = 1000; $symbols = $si; break;
126 - }
127 - switch($bB) {
128 - case "b" : $val *= 8; break;
129 - default : $bB = "B"; break;
130 - }
131 - for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
132 - $val /= $factor;
133 - $p = strpos($val, ".");
134 - if($p !== false && $p > $digits) $val = round($val);
135 - elseif($p !== false) $val = round($val, $digits-$p);
136 - return round($val, $digits) . " " . $symbols[$i] . $bB;
137 - }
138125
139 - function remotefsize($url) {
140 - //$sch = parse_url($url, PHP_URL_SCHEME);
141 - //if (($sch != "http") && ($sch != "https") && ($sch != "ftp") && ($sch != "ftps")) {
142 - // return false;
143 - //}
144 - $sch='http';
145 - if (($sch == "http") || ($sch == "https")) {
146 - $headers = get_headers($url, 1);
147 - if ((!array_key_exists("Content-Length", $headers))) { return false; }
148 - return $headers["Content-Length"];
 126+function remotefsize($url) {
 127+ //$sch = parse_url($url, PHP_URL_SCHEME);
 128+ //if (($sch != "http") && ($sch != "https") && ($sch != "ftp") && ($sch != "ftps")) {
 129+ // return false;
 130+ //}
 131+ $sch='http';
 132+ if (($sch == "http") || ($sch == "https")) {
 133+ $headers = get_headers($url, 1);
 134+ if ((!array_key_exists("Content-Length", $headers))) { return false; }
 135+ return $headers["Content-Length"];
 136+ }
 137+ if (($sch == "ftp") || ($sch == "ftps")) {
 138+ $server = parse_url($url, PHP_URL_HOST);
 139+ $port = parse_url($url, PHP_URL_PORT);
 140+ $path = parse_url($url, PHP_URL_PATH);
 141+ $user = parse_url($url, PHP_URL_USER);
 142+ $pass = parse_url($url, PHP_URL_PASS);
 143+ if ((!$server) || (!$path)) { return false; }
 144+ if (!$port) { $port = 21; }
 145+ if (!$user) { $user = "anonymous"; }
 146+ if (!$pass) { $pass = "phpos@"; }
 147+ switch ($sch) {
 148+ case "ftp":
 149+ $ftpid = ftp_connect($server, $port);
 150+ break;
 151+ case "ftps":
 152+ $ftpid = ftp_ssl_connect($server, $port);
 153+ break;
149154 }
150 - if (($sch == "ftp") || ($sch == "ftps")) {
151 - $server = parse_url($url, PHP_URL_HOST);
152 - $port = parse_url($url, PHP_URL_PORT);
153 - $path = parse_url($url, PHP_URL_PATH);
154 - $user = parse_url($url, PHP_URL_USER);
155 - $pass = parse_url($url, PHP_URL_PASS);
156 - if ((!$server) || (!$path)) { return false; }
157 - if (!$port) { $port = 21; }
158 - if (!$user) { $user = "anonymous"; }
159 - if (!$pass) { $pass = "phpos@"; }
160 - switch ($sch) {
161 - case "ftp":
162 - $ftpid = ftp_connect($server, $port);
163 - break;
164 - case "ftps":
165 - $ftpid = ftp_ssl_connect($server, $port);
166 - break;
167 - }
168 - if (!$ftpid) { return false; }
169 - $login = ftp_login($ftpid, $user, $pass);
170 - if (!$login) { return false; }
171 - $ftpsize = ftp_size($ftpid, $path);
172 - ftp_close($ftpid);
173 - if ($ftpsize == -1) { return false; }
174 - return $ftpsize;
175 - }
176 - }
 155+ if (!$ftpid) { return false; }
 156+ $login = ftp_login($ftpid, $user, $pass);
 157+ if (!$login) { return false; }
 158+ $ftpsize = ftp_size($ftpid, $path);
 159+ ftp_close($ftpid);
 160+ if ($ftpsize == -1) { return false; }
 161+ return $ftpsize;
 162+ }
 163+}
177164 function simple_run_background($command){
178165 $PID = shell_exec("nohup $command > /dev/null & echo $!");
179166 return $PID;
@@ -184,6 +171,7 @@
185172 return(count($ProcessState) >= 2);
186173 }
187174 function hr_bytes($size) {
 175+ $size = (int)$size;
188176 $a = array("B", "KB", "MB", "GB", "TB", "PB");
189177 $pos = 0;
190178 while ($size >= 1024) {
@@ -192,5 +180,4 @@
193181 }
194182 return round($size,2)." ".$a[$pos];
195183 }
196 -
197184 ?>
\ No newline at end of file
Index: branches/MetavidWiki-exp/MetavidWiki/includes/MV_StreamFile.php
@@ -9,8 +9,7 @@
1010 * @email dale@ucsc.edu
1111 * @url http://metavid.ucsc.edu
1212 */
13 - if ( !defined( 'MEDIAWIKI' ) ) die( 1 );
14 -
 13+ if ( !defined( 'MEDIAWIKI' ) ) die( 1 );
1514 /*
1615 * MvStreamFile handles the mapping of path types to urls &
1716 * active record style management of the mv_stream_files table
@@ -27,15 +26,11 @@
2827 var $_parent_stream=null;
2928
3029 //@@todo this should not be hard coded... read the header of the file? or extend path_type
31 - var $msg_content_type_lookup = array(
32 - 'ao_file_256Kb_MPEG4' =>'video/mp4',
33 - 'ao_file_64Kb_MPEG4' =>'video/mp4',
34 - 'ao_file_flash_flv' =>'video/x-flv',
35 - 'ao_file_MPEG1' =>'video/mpeg',
36 - 'ao_file_MPEG2' =>'video/mpeg-2',
37 - 'mv_ogg_high_quality' =>'video/ogg',
38 - 'mv_ogg_low_quality' =>'video/ogg'
39 - );
 30+ function getTypeForQK($key){
 31+ global $mvMsgContentTypeLookup;
 32+ if(isset($mvMsgContentTypeLookup[$key]))
 33+ return $mvMsgContentTypeLookup[$key];
 34+ }
4035 function __construct(&$parent_stream, $initRow=''){
4136 $this->_parent_stream =& $parent_stream;
4237 //no init val.. populate from db
@@ -54,8 +49,9 @@
5550 return $this->file_desc_msg;
5651 }
5752 function getContentType(){
58 - if(isset($this->msg_content_type_lookup[$this->file_desc_msg])){
59 - return $this->msg_content_type_lookup[$this->file_desc_msg];
 53+ global $mvMsgContentTypeLookup;
 54+ if(isset($mvMsgContentTypeLookup[$this->file_desc_msg])){
 55+ return $mvMsgContentTypeLookup[$this->file_desc_msg];
6056 }
6157 //default content type?
6258 return 'application/octet-stream';
Index: branches/MetavidWiki-exp/MetavidWiki/includes/MV_DefaultSettings.php
@@ -92,6 +92,7 @@
9393 $mvVideoArchivePaths['cap1'] = 'http://128.114.20.64/media/';
9494
9595 $mvDefaultVideoQualityKey = 'mv_ogg_low_quality';
 96+$mvDefaultFlashQualityKey = 'mv_flash_low_quality';
9697
9798 #local path to video archive (if hosted locally)
9899 $mvLocalVideoLoc = '/metavid/video_archive';
@@ -179,6 +180,18 @@
180181 $wgGroupPermissions['bot']['mv_edit_stream']=true;
181182 $wgAvailableRights[] = 'mv_delete_mvd';
182183 $wgAvailableRights[] = 'mv_edit_stream';
 184+
 185+$mvMsgContentTypeLookup = array(
 186+ 'ao_file_256Kb_MPEG4' =>'video/mp4',
 187+ 'ao_file_64Kb_MPEG4' =>'video/mp4',
 188+ 'ao_file_flash_flv' =>'video/x-flv',
 189+ 'ao_file_MPEG1' =>'video/mpeg',
 190+ 'ao_file_MPEG2' =>'video/mpeg-2',
 191+ 'mv_flash_low_quality' =>'video/x-flv',
 192+ 'mv_ogg_high_quality' =>'video/ogg',
 193+ 'mv_ogg_low_quality' =>'video/ogg'
 194+ );
 195+
183196 ###
184197 # If you already have custom namespaces on your site, insert
185198 # $mvNamespaceIndex = ???; in your config before including the settings
Index: branches/MetavidWiki-exp/MetavidWiki/includes/MV_Title.php
@@ -287,9 +287,9 @@
288288 'stream_id' => $this->mvStream->id,
289289 'file_desc_msg'=>$quality
290290 ));
291 - $streamFile =$dbr->fetchObject($result);
 291+ $streamFile =$dbr->fetchObject($result);
292292 //make sure we have streamFiles (used to generate the link)
293 - $mvStreamFile = new MV_StreamFile($this->mvStream);
 293+ $mvStreamFile = new MV_StreamFile($this->mvStream, $streamFile);
294294 //if link empty return false:
295295 if($mvStreamFile->getFullURL()=='')return false;
296296 return $mvStreamFile->getFullURL() . $anx_req;
@@ -305,6 +305,7 @@
306306 return $roeTitle->getFullURL($query) ;
307307 }
308308 function getEmbedVideoHtml($vid_id='', $size='', $force_server='', $autoplay=false){
 309+ global $mvDefaultFlashQualityKey, $mvDefaultVideoQualityKey;
309310 $tag='video';
310311 if($size==''){
311312 global $mvDefaultVideoPlaybackRes;
@@ -314,7 +315,9 @@
315316 list($vWidth, $vHeight, $na) = MV_StreamImage::getSizeType($size);
316317 }
317318 $vid_id=($vid_id=='')?'':'id="'.$vid_id.'"';
318 - $stream_web_url = $this->getWebStreamURL();
 319+ $stream_web_url = $this->getWebStreamURL($mvDefaultVideoQualityKey);
 320+ //print "lookign for q: $mvDefaultFlashQualityKey ";
 321+ $flash_stream_url = $this->getWebStreamURL($mvDefaultFlashQualityKey);
319322 $roe_url = $this->getROEURL();
320323 if($stream_web_url){
321324 $o='';
@@ -324,12 +327,19 @@
325328 '</span>';
326329 }
327330 $auto_play_attr=($autoplay)?' autoplay="true" ':'';
328 - $o.='<'.$tag.' '.$vid_id.' thumbnail="'.$this->getStreamImageURL($size, null, $force_server).'" '.
329 - 'src="'.$stream_web_url .'" ' .
 331+ $o.='<'.$tag.' '.$vid_id.' thumbnail="'.$this->getStreamImageURL($size, null, $force_server).'" '.
330332 'roe="'.$roe_url.'" '.
331333 'show_meta_link="false" ' . $auto_play_attr .
332334 'style="width:'.$vWidth.'px;height:'.$vHeight.'px" '.
333 - 'controls="true" embed_link="true" />';
 335+ 'controls="true" embed_link="true" >';
 336+
 337+ if($stream_web_url!='')
 338+ $o.='<source type="'.MV_StreamFile::getTypeForQK($mvDefaultVideoQualityKey).'" src="'.$stream_web_url .'"/>';
 339+
 340+ if($flash_stream_url!='')
 341+ $o.='<source type="'.MV_StreamFile::getTypeForQK($mvDefaultFlashQualityKey).'" src="'.$flash_stream_url .'"/>';
 342+
 343+ $o.='</video>';
334344 return $o;
335345 }else{
336346 return wfMsg('mv_error_stream_missing');
Index: branches/MetavidWiki-exp/MetavidWiki/skins/mv_embed/flvServer/mvFlvServer.php
@@ -33,6 +33,7 @@
3434 $file_req = $pathparts[count($pathparts)-1];
3535 }
3636 }
 37+//print $file_req;
3738
3839 //additional filtering to avoid directory traversing:
3940 $file_req = str_replace(array('../','./'), '', $file_req);

Status & tagging log