r87923 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87922‎ | r87923 | r87924 >
Date:19:41, 12 May 2011
Author:hartman
Status:resolved (Comments)
Tags:media 
Comment:
Add support for the Height parameter for OggHandler. Fixes bug 28886

Also:
- fix the validateParams to actually do that
- Move parameter normalization from Thumb into normaliseParams
Modified paths:
  • /trunk/extensions/OggHandler/OggHandler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/OggHandler_body.php
@@ -19,18 +19,21 @@
2020 }
2121
2222 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' ) {
2430 $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 ) {
2733 return false;
28 - } elseif ( $time > $length - 1 ) {
29 - $params['thumbtime'] = $length - 1;
30 - } elseif ( $time <= 0 ) {
31 - $params['thumbtime'] = 0;
3234 }
 35+ return true;
3336 }
34 - return true;
 37+ return false;
3538 }
3639
3740 function parseTimeString( $seekString, $length = false ) {
@@ -79,6 +82,32 @@
8083 }
8184
8285 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+
83112 if ( isset( $params['thumbtime'] ) ) {
84113 $length = $this->getLength( $image );
85114 $time = $this->parseTimeString( $params['thumbtime'] );
@@ -180,11 +209,13 @@
181210 }
182211
183212 function doTransform( $file, $dstPath, $dstUrl, $params, $flags = 0 ) {
 213+ if ( !$this->normaliseParams( $file, $params ) ) {
 214+ return new TransformParameterError( $params );
 215+ }
184216
185217 $width = $params['width'];
186 - $srcWidth = $file->getWidth();
187 - $srcHeight = $file->getHeight();
188 - $height = $srcWidth == 0 ? $srcHeight : $width * $srcHeight / $srcWidth;
 218+ $height = $params['height'];
 219+
189220 $length = $this->getLength( $file );
190221 $noPlayer = isset( $params['noplayer'] );
191222 $noIcon = isset( $params['noicon'] );
@@ -196,9 +227,8 @@
197228 $this->setHeaders( $wgOut );
198229 }
199230
200 - if ( $srcHeight == 0 || $srcWidth == 0 ) {
 231+ if ( $params['playertype'] == "audio" ) {
201232 // Make audio player
202 - $height = empty( $params['height'] ) ? 20 : $params['height'];
203233 if ( $noPlayer ) {
204234 if ( $height > 100 ) {
205235 global $wgStylePath;
@@ -210,11 +240,6 @@
211241 return new ThumbnailImage( $file, $iconUrl, 22, 22 );
212242 }
213243 }
214 - if ( empty( $params['width'] ) ) {
215 - $width = 200;
216 - } else {
217 - $width = $params['width'];
218 - }
219244 return new OggAudioDisplay( $file, $targetFileUrl, $width, $height, $length, $dstPath, $noIcon );
220245 }
221246

Follow-up revisions

RevisionCommit summaryAuthorDate
r98208Fix for r87923, which made broken but harmless code from r62223 actually star...tstarling04:19, 27 September 2011
r99167* (bug 31415) Fix regression: 'noicon' works again for OggHandler...brion23:20, 6 October 2011

Comments

#Comment by TheDJ (talk | contribs)   19:43, 12 May 2011

Also fixes bug 28885

#Comment by TheDJ (talk | contribs)   20:02, 12 May 2011

Some parts of this probably need to be ported over to TimedMediaHandler_body.php

#Comment by Bryan (talk | contribs)   08:49, 14 May 2011

What's up with the outcommented code?

#Comment by Tim Starling (talk | contribs)   02:12, 27 September 2011

Why is this marked deferred? It caused a lot of articles on nlwiki to fail with fatal errors.

Status & tagging log