r54530 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54529‎ | r54530 | r54531 >
Date:16:35, 6 August 2009
Author:dale
Status:deferred
Tags:
Comment:
adds support for start and end time of the ogg file if ( $wgEnableTemporalOggUrls ) is enabled.
* this results in an oggz_chop temporal url used for the source of the file
* will only work with oggz_chop installed and $wgEnableTemporalOggUrls turned on.
Modified paths:
  • /trunk/extensions/OggHandler/OggHandler.i18n.php (modified) (history)
  • /trunk/extensions/OggHandler/OggHandler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/OggHandler_body.php
@@ -23,11 +23,13 @@
2424 'ogg_noplayer' => 'noplayer',
2525 'ogg_noicon' => 'noicon',
2626 'ogg_thumbtime' => 'thumbtime',
 27+ 'ogg_starttime' => 'start',
 28+ 'ogg_endtime' => 'end',
2729 );
2830 }
2931
30 - function validateParam( $name, $value ) {
31 - if ( $name == 'thumbtime' ) {
 32+ function validateParam( $name, $value ) {
 33+ if ( $name == 'thumbtime' || $name == 'start' || $name == 'end' ) {
3234 if ( $this->parseTimeString( $value ) === false ) {
3335 return false;
3436 }
@@ -72,19 +74,28 @@
7375 }
7476 return array();
7577 }
76 -
77 - function normaliseParams( $image, &$params ) {
78 - if ( isset( $params['thumbtime'] ) ) {
79 - $length = $this->getLength( $image );
80 - $time = $this->parseTimeString( $params['thumbtime'] );
81 - if ( $time === false ) {
82 - return false;
83 - } elseif ( $time > $length - 1 ) {
84 - $params['thumbtime'] = $length - 1;
85 - } elseif ( $time <= 0 ) {
86 - $params['thumbtime'] = 0;
 78+
 79+ function normaliseParams( $image, &$params ) {
 80+ $timeParam = array('thumbtime', 'start', 'end');
 81+ //parse time values if endtime or thumbtime can't be more than length -1
 82+ foreach($timeParam as $pn){
 83+ if ( isset( $params[$pn] ) ) {
 84+ $length = $this->getLength( $image );
 85+ $time = $this->parseTimeString( $params[$pn] );
 86+ if ( $time === false ) {
 87+ return false;
 88+ } elseif ( $time > $length - 1 ) {
 89+ $params[$pn] = $length - 1;
 90+ } elseif ( $time <= 0 ) {
 91+ $params[$pn] = 0;
 92+ }
8793 }
8894 }
 95+ //make sure start time is not > than end time
 96+ if(isset($params['start']) && isset($params['end']) ){
 97+ if($params['start'] > $params['end'])
 98+ return false;
 99+ }
89100
90101 return true;
91102 }
@@ -171,7 +182,7 @@
172183 }
173184
174185 function doTransform( $file, $dstPath, $dstUrl, $params, $flags = 0 ) {
175 - global $wgFFmpegLocation;
 186+ global $wgFFmpegLocation, $wgEnableTemporalOggUrls;
176187
177188 $width = $params['width'];
178189 $srcWidth = $file->getWidth();
@@ -182,6 +193,14 @@
183194 $noPlayer = isset( $params['noplayer'] );
184195 $noIcon = isset( $params['noicon'] );
185196
 197+ $oggAppendReq = '';
 198+ //add temporal request parameter if $wgEnableTemporalOggUrls is on:
 199+ if($wgEnableTemporalOggUrls && isset( $params['start'] ) ){
 200+ $oggAppendReq .= '?t=' . seconds2npt( $params['start'] );
 201+ if(isset( $params['end'] ) && $params['end'] )
 202+ $oggAppendReq.='/'. seconds2npt( $params['end'] );
 203+ }
 204+
186205 if ( !$noPlayer ) {
187206 // Hack for miscellaneous callers
188207 global $wgOut;
@@ -207,7 +226,7 @@
208227 } else {
209228 $width = $params['width'];
210229 }
211 - return new OggAudioDisplay( $file, $file->getURL(), $width, $height, $length, $dstPath, $noIcon, $offset );
 230+ return new OggAudioDisplay( $file, $file->getURL().$oggAppendReq, $width, $height, $length, $dstPath, $noIcon, $offset );
212231 }
213232
214233 // Video thumbnail only
@@ -216,16 +235,16 @@
217236 }
218237
219238 if ( $flags & self::TRANSFORM_LATER ) {
220 - return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath, $noIcon, $offset);
 239+ return new OggVideoDisplay( $file, $file->getURL().$oggAppendReq, $dstUrl, $width, $height, $length, $dstPath, $noIcon, $offset);
221240 }
222241
223 - $thumbTime = false;
 242+ $thumbtime = false;
224243 if ( isset( $params['thumbtime'] ) ) {
225 - $thumbTime = $this->parseTimeString( $params['thumbtime'], $length );
 244+ $thumbtime = $this->parseTimeString( $params['thumbtime'], $length );
226245 }
227 - if ( $thumbTime === false ) {
 246+ if ( $thumbtime === false ) {
228247 # Seek to midpoint by default, it tends to be more interesting than the start
229 - $thumbTime = $length / 2;
 248+ $thumbtime = $length / 2;
230249 }
231250
232251 wfMkdirParents( dirname( $dstPath ) );
@@ -281,7 +300,7 @@
282301 return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) );
283302 }
284303 }
285 - return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath );
 304+ return new OggVideoDisplay( $file, $file->getURL() . $oggAppendReq, $dstUrl, $width, $height, $length, $dstPath );
286305 }
287306
288307 function canRender( $file ) { return true; }
@@ -710,5 +729,61 @@
711730 parent::__construct( $file, $videoUrl, false, $width, $height, $length, false, $path, $noIcon, $offset );
712731 }
713732 }
 733+/*utility functions*/
 734+/*
 735+ * takes seconds duration and return hh:mm:ss time
 736+ */
 737+if(!function_exists('seconds2npt')){
 738+ function seconds2npt( $seconds, $short = false ) {
 739+ $dur = time_duration_2array( $seconds );
 740+ if( ! $dur )
 741+ return null;
 742+ // be sure to output leading zeros (for min,sec):
 743+ if ( $dur['hours'] == 0 && $short == true ) {
 744+ return sprintf( "%2d:%02d", $dur['minutes'], $dur['seconds'] );
 745+ } else {
 746+ return sprintf( "%d:%02d:%02d", $dur['hours'], $dur['minutes'], $dur['seconds'] );
 747+ }
 748+ }
 749+}
 750+/*
 751+ * converts seconds to time unit array
 752+ */
 753+if(!function_exists('time_duration_2array')){
 754+ function time_duration_2array ( $seconds, $periods = null ) {
 755+ // Define time periods
 756+ if ( !is_array( $periods ) ) {
 757+ $periods = array (
 758+ 'years' => 31556926,
 759+ 'months' => 2629743,
 760+ 'weeks' => 604800,
 761+ 'days' => 86400,
 762+ 'hours' => 3600,
 763+ 'minutes' => 60,
 764+ 'seconds' => 1
 765+ );
 766+ }
 767+
 768+ // Loop
 769+ $seconds = (float) $seconds;
 770+ foreach ( $periods as $period => $value ) {
 771+ $count = floor( $seconds / $value );
 772+ if ( $count == 0 ) {
 773+ // must include hours minutes and seconds even if they are 0
 774+ if ( $period == 'hours' || $period == 'minutes' || $period == 'seconds' ) {
 775+ $values[$period] = 0;
 776+ }
 777+ continue;
 778+ }
 779+ $values[$period] = sprintf( "%02d", $count );
 780+ $seconds = $seconds % $value;
 781+ }
 782+ // Return
 783+ if ( empty( $values ) ) {
 784+ $values = null;
 785+ }
 786+ return $values;
 787+ }
 788+}
714789
715790 ?>
Index: trunk/extensions/OggHandler/OggHandler.i18n.php
@@ -4,7 +4,9 @@
55 'en' => array(
66 'ogg_noplayer' => array( 0, 'noplayer' ),
77 'ogg_noicon' => array( 0, 'noicon' ),
8 - 'ogg_thumbtime' => array( 0, 'thumbtime=$1' ),
 8+ 'ogg_thumbtime' => array( 0, 'thumbtime=$1' ),
 9+ 'ogg_starttime' => array( 0, 'start=$1'),
 10+ 'ogg_endtime' => array( 0, 'end=$1'),
911 ),
1012 );
1113

Status & tagging log