Index: trunk/extensions/OggHandler/OggHandler_body.php |
— | — | @@ -19,18 +19,21 @@ |
20 | 20 | } |
21 | 21 | |
22 | 22 | function validateParam( $name, $value ) { |
23 | | - if ( isset( $params['thumbtime'] ) ) { |
| 23 | + if ( in_array( $name, array( 'width', 'height' ) ) ) { |
| 24 | + if ( $value <= 0 ) { |
| 25 | + return false; |
| 26 | + } |
| 27 | + return true; |
| 28 | + } |
| 29 | + if ( $name == 'thumbtime' ) { |
24 | 30 | $length = $this->getLength( $image ); |
25 | | - $time = $this->parseTimeString( $params['thumbtime'] ); |
26 | | - if ( $time === false ) { |
| 31 | + $time = $this->parseTimeString( $value ); |
| 32 | + if ( $time === false || $time <= 0 ) { |
27 | 33 | return false; |
28 | | - } elseif ( $time > $length - 1 ) { |
29 | | - $params['thumbtime'] = $length - 1; |
30 | | - } elseif ( $time <= 0 ) { |
31 | | - $params['thumbtime'] = 0; |
32 | 34 | } |
| 35 | + return true; |
33 | 36 | } |
34 | | - return true; |
| 37 | + return false; |
35 | 38 | } |
36 | 39 | |
37 | 40 | function parseTimeString( $seekString, $length = false ) { |
— | — | @@ -79,6 +82,32 @@ |
80 | 83 | } |
81 | 84 | |
82 | 85 | function normaliseParams( $image, &$params ) { |
| 86 | + $srcWidth = $image->getWidth(); |
| 87 | + $srcHeight = $image->getHeight(); |
| 88 | + $params['playertype'] = "video"; |
| 89 | + |
| 90 | + if( $srcWidth == 0 || $srcHeight == 0 ) { |
| 91 | + // We presume this is an audio clip |
| 92 | + $params['playertype'] = "audio"; |
| 93 | + $params['height'] = empty( $params['height'] ) ? 20 : $params['height']; |
| 94 | + $params['width'] = empty( $params['width'] ) ? 200 : $params['width']; |
| 95 | + } else { |
| 96 | + // Check for height param and adjust width accordingly |
| 97 | + if ( isset( $params['height'] ) && $params['height'] != -1 ) { |
| 98 | + if( $params['width'] * $srcHeight > $params['height'] * $srcWidth ) { |
| 99 | + $params['width'] = wfFitBoxWidth( $srcWidth, $srcHeight, $params['height'] ); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + // Make it no wider than the original |
| 104 | + //if( $params['width'] > $srcWidth ) { |
| 105 | + // $params['width'] = $srcWidth; |
| 106 | + //} |
| 107 | + |
| 108 | + // Calculate the corresponding height based on the adjusted width |
| 109 | + $params['height'] = File::scaleHeight( $srcWidth, $srcHeight, $params['width'] ); |
| 110 | + } |
| 111 | + |
83 | 112 | if ( isset( $params['thumbtime'] ) ) { |
84 | 113 | $length = $this->getLength( $image ); |
85 | 114 | $time = $this->parseTimeString( $params['thumbtime'] ); |
— | — | @@ -180,11 +209,13 @@ |
181 | 210 | } |
182 | 211 | |
183 | 212 | function doTransform( $file, $dstPath, $dstUrl, $params, $flags = 0 ) { |
| 213 | + if ( !$this->normaliseParams( $file, $params ) ) { |
| 214 | + return new TransformParameterError( $params ); |
| 215 | + } |
184 | 216 | |
185 | 217 | $width = $params['width']; |
186 | | - $srcWidth = $file->getWidth(); |
187 | | - $srcHeight = $file->getHeight(); |
188 | | - $height = $srcWidth == 0 ? $srcHeight : $width * $srcHeight / $srcWidth; |
| 218 | + $height = $params['height']; |
| 219 | + |
189 | 220 | $length = $this->getLength( $file ); |
190 | 221 | $noPlayer = isset( $params['noplayer'] ); |
191 | 222 | $noIcon = isset( $params['noicon'] ); |
— | — | @@ -196,9 +227,8 @@ |
197 | 228 | $this->setHeaders( $wgOut ); |
198 | 229 | } |
199 | 230 | |
200 | | - if ( $srcHeight == 0 || $srcWidth == 0 ) { |
| 231 | + if ( $params['playertype'] == "audio" ) { |
201 | 232 | // Make audio player |
202 | | - $height = empty( $params['height'] ) ? 20 : $params['height']; |
203 | 233 | if ( $noPlayer ) { |
204 | 234 | if ( $height > 100 ) { |
205 | 235 | global $wgStylePath; |
— | — | @@ -210,11 +240,6 @@ |
211 | 241 | return new ThumbnailImage( $file, $iconUrl, 22, 22 ); |
212 | 242 | } |
213 | 243 | } |
214 | | - if ( empty( $params['width'] ) ) { |
215 | | - $width = 200; |
216 | | - } else { |
217 | | - $width = $params['width']; |
218 | | - } |
219 | 244 | return new OggAudioDisplay( $file, $targetFileUrl, $width, $height, $length, $dstPath, $noIcon ); |
220 | 245 | } |
221 | 246 | |