r82103 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82102‎ | r82103 | r82104 >
Date:06:08, 14 February 2011
Author:dale
Status:deferred
Tags:
Comment:
some strict php cleanup
shift to passing $options instead of long list of arguments
Modified paths:
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/handlers/WebMHandler/WebMHandler.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/handlers/WebMHandler/WebMHandler.php
@@ -18,8 +18,9 @@
1919 $getID3->option_tags_process = false; // Copy tags to root key 'tags' and encode to $this->encoding
2020 $getID3->option_tags_html = false; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
2121
22 - // Analyze file and store returned data in $ThisFileInfo
 22+ // Analyze file to get metadata structure:
2323 $id3 = $getID3->analyze( $path );
 24+
2425 // Unset some parts of id3 that are too detailed and matroska specific:
2526 unset( $id3['matroska'] );
2627 // remove file paths
@@ -32,6 +33,7 @@
3334
3435 return serialize( $id3 );
3536 }
 37+
3638 /**
3739 * Get the "media size"
3840 */
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php
@@ -128,15 +128,19 @@
129129 'offset' => $this->getOffset( $file ),
130130 'width' => $params['width'],
131131 'height' => $srcWidth == 0 ? $srcHeight : $params['width']* $srcHeight / $srcWidth,
132 - 'isVideo' => ( $srcHeight != 0 && $srcWidth != 0 )
 132+ 'isVideo' => ( $srcHeight != 0 && $srcWidth != 0 ),
 133+ 'thumbtime' => ( isset( $params['thumbtime'] ) )? $params['thumbtime'] : false,
 134+ 'start' => ( isset( $params['start'] ) )? $params['start'] : false,
 135+ 'end' => ( isset( $params['end'] ) )? $params['end'] : false
133136 );
134137 // No thumbs for audio
135138 if( $baseConfig['isVideo'] === false ){
136139 return new TimedMediaTransformOutput( $baseConfig );
137140 }
138141
139 - // Setup pointer to thumb url:
 142+ // Setup pointer to thumb arguments
140143 $baseConfig['thumbUrl'] = $dstUrl;
 144+ $baseConfig['dstPath'] = $dstPath;
141145
142146 // Check if transform is deferred:
143147 if ( $flags & self::TRANSFORM_LATER ) {
@@ -144,7 +148,7 @@
145149 }
146150
147151 // Generate thumb:
148 - $thumbStatus = TimedMediaThumbnail::get( $file, $dstPath, $params, $width, $height );
 152+ $thumbStatus = TimedMediaThumbnail::get( $baseConfig );
149153 if( $thumbStatus !== true ){
150154 return $thumbStatus;
151155 }
@@ -171,21 +175,6 @@
172176 return $wgLang->formatTimePeriod( $this->getLength( $file ) );
173177 }
174178 }
175 -
176 - function parserTransformHook( $parser, $file ) {
177 - if ( isset( $parser->mOutput->hasOggTransform ) ) {
178 - return;
179 - }
180 - $parser->mOutput->hasOggTransform = true;
181 - $parser->mOutput->addOutputHook( 'TimedMediaHandler' );
182 - }
183 -
184 - static function outputHook( $outputPage, $parserOutput, $data ) {
185 - $instance = MediaHandler::getHandler( 'application/ogg' );
186 - if ( $instance ) {
187 - $instance->setHeaders( $outputPage );
188 - }
189 - }
190179 }
191180 // Setup named Timed Media handlers
192181 class TimedMediaHandlerOgg extends TimedMediaHandler {
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php
@@ -16,9 +16,6 @@
1717 $wgMediaHandlers['application/ogg'] = 'OggHandler';
1818 $wgMediaHandlers['video/webm'] = 'WebMHandler';
1919
20 - // Parser hook for TimedMediaHandler output
21 - $wgParserOutputHooks['TimedMediaHandler'] = array( 'TimedMediaHandler', 'outputHook' );
22 -
2320 // Setup a hook for iframe embed handling:
2421 $wgHooks['ArticleFromTitle'][] = 'TimedMediaIframeOutput::iframeHook';
2522
Index: trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php
@@ -1,34 +1,23 @@
22 <?php
33 class TimedMediaThumbnail {
44
5 - function get( $file, $dstPath, $params, $width, $height){
 5+ static function get( $options ){
66 global $wgFFmpegLocation, $wgOggThumbLocation;
7 - $thumbtime = self::getThumbTime($file, $params );
 7+ $thumbtime = self::getThumbTime( $options );
88
9 - wfMkdirParents( dirname( $dstPath ) );
 9+ // Set up lodal pointer to file
 10+ $file = $options['file'];
 11+
 12+ wfMkdirParents( dirname( $options['dstPath'] ) );
1013
11 - wfDebug( "Creating video thumbnail at $dstPath\n" );
 14+ wfDebug( "Creating video thumbnail at" . $options['dstPath'] . "\n" );
1215
13 - $width = ( isset( $params['width'] )
14 - &&
15 - $params['width'] > 0
16 - &&
17 - $params['width'] < $file->getWidth()
18 - ) ? $params['width'] : $file->getWidth();
19 -
20 - $height = ( isset( $params['height'] )
21 - &&
22 - $params['height'] > 0
23 - &&
24 - $params['height'] < $file->getHeight()
25 - ) ? $params['height'] : $file->getHeight();
26 -
2716 // If ogg try OggThumb:
28 - if( self::tryOggThumb($file, $dstPath, $width, $height, $thumbtime ) ){
 17+ if( self::tryOggThumb( $options) ){
2918 return true;
3019 }
3120 // Else try and return the ffmpeg thumbnail attempt:
32 - return self::tryFfmpegThumb($file, $dstPath, $width, $height, $thumbtime );
 21+ return self::tryFfmpegThumb( $options );
3322 }
3423 /**
3524 * Try to render a thumbnail using oggThumb:
@@ -37,11 +26,11 @@
3827 * @param $dstPath {string} Destination path for the rendered thumbnail
3928 * @param $dstPath {array} Thumb rendering parameters ( like size and time )
4029 */
41 - function tryOggThumb($file, $dstPath, $width, $height, $thumbtime ){
 30+ static function tryOggThumb( $options ){
4231 global $wgOggThumbLocation;
4332
4433 // Check for ogg format file and $wgOggThumbLocation
45 - if( !$file->getHandler()->getMetadataType() == 'ogg'
 34+ if( !$options['file']->getHandler()->getMetadataType() == 'ogg'
4635 || !$wgOggThumbLocation
4736 || !is_file( $wgOggThumbLocation )
4837 ){
@@ -49,37 +38,37 @@
5039 }
5140
5241 $cmd = wfEscapeShellArg( $wgOggThumbLocation ) .
53 - ' -t '. intval( $thumbtime ) . ' ' .
54 - ' -n ' . wfEscapeShellArg( $dstPath ) . ' ' .
55 - ' ' . wfEscapeShellArg( $file->getPath() ) . ' 2>&1';
 42+ ' -t '. intval( $options['thumbtime'] ) . ' ' .
 43+ ' -n ' . wfEscapeShellArg( $options['dstPath'] ) . ' ' .
 44+ ' ' . wfEscapeShellArg( $options['file']->getPath() ) . ' 2>&1';
5645 $returnText = wfShellExec( $cmd, $retval );
5746
5847 // Check if it was successful
59 - if ( !$file->getHandler()->removeBadFile( $dstPath, $retval ) ) {
 48+ if ( !$options['file']->getHandler()->removeBadFile( $options['dstPath'], $retval ) ) {
6049 return true;
6150 }
6251 return false;
6352 }
6453
65 - function tryFfmpegThumb($file, $dstPath, $width, $height, $thumbtime ){
 54+ static function tryFfmpegThumb( $options ){
6655 global $wgFFmpegLocation;
6756 if( !$wgFFmpegLocation || !is_file( $wgFFmpegLocation ) ){
6857 return false;
6958 }
7059
7160 $cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
72 - ' -ss ' . intval( $thumbtime ) . ' ' .
73 - ' -i ' . wfEscapeShellArg( $file->getPath() ) .
 61+ ' -ss ' . intval( $options['thumbtime'] ) . ' ' .
 62+ ' -i ' . wfEscapeShellArg( $options['file']->getPath() ) .
7463 # MJPEG, that's the same as JPEG except it's supported by the windows build of ffmpeg
7564 # No audio, one frame
7665 ' -f mjpeg -an -vframes 1 ' .
77 - wfEscapeShellArg( $dstPath ) . ' 2>&1';
 66+ wfEscapeShellArg( $options['dstPath'] ) . ' 2>&1';
7867
7968 $retval = 0;
8069 $returnText = wfShellExec( $cmd, $retval );
8170
8271 // Check if it was successful
83 - if ( !$file->getHandler()->removeBadFile( $dstPath, $retval ) ) {
 72+ if ( !$options['file']->getHandler()->removeBadFile( $options['dstPath'], $retval ) ) {
8473 return true;
8574 }
8675 // Filter nonsense
@@ -93,25 +82,21 @@
9483 $lines = array_slice( $lines, $i );
9584 }
9685 // Return error box
97 - return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) );
 86+ return new MediaTransformError( 'thumbnail_error', $options['width'], $options['height'], implode( "\n", $lines ) );
9887 }
9988
100 - function getThumbTime( $file, $params ){
101 -
102 - $length = $file->getLength();
 89+ static function getThumbTime( $options ){
 90+ $length = $options['file']->getLength();
10391 $thumbtime = false;
104 - if ( isset( $params['thumbtime'] ) ) {
105 - $thumbtime = TimedMediaHandler::parseTimeString( $params['thumbtime'], $length );
 92+ if ( $options['thumbtime'] ) {
 93+ return TimedMediaHandler::parseTimeString( $options['thumbtime'], $length );
10694 }
107 - if ( $thumbtime === false ) {
108 - // If start time param isset use that for the thumb:
109 - if( isset( $params['start'] ) ){
110 - $thumbtime = TimedMediaHandler::parseTimeString( $params['start'], $length );
111 - }else{
112 - # Seek to midpoint by default, it tends to be more interesting than the start
113 - $thumbtime = $length / 2;
114 - }
115 - }
116 - return $thumbtime;
 95+ // If start time param isset use that for the thumb:
 96+ if( $options['start'] ) {
 97+ return TimedMediaHandler::parseTimeString( $options['start'], $length );
 98+ }else{
 99+ // Seek to midpoint by default, it tends to be more interesting than the start
 100+ return $length / 2;
 101+ }
117102 }
118103 }
\ No newline at end of file

Status & tagging log