Index: trunk/extensions/VipsScaler/SpecialVipsTest.php |
— | — | @@ -75,8 +75,7 @@ |
76 | 76 | } |
77 | 77 | |
78 | 78 | $params = array( 'width' => $width ); |
79 | | - // RENDER_FORCE requires MediaWiki core r101833 |
80 | | - $thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE ); |
| 79 | + $thumb = $file->transform( $params ); |
81 | 80 | if ( !$thumb || $thumb->isError() ) { |
82 | 81 | $this->getOutput()->addWikiMsg( 'vipsscaler-thumb-error' ); |
83 | 82 | return; |
— | — | @@ -88,6 +87,15 @@ |
89 | 88 | 'desc-link' => true, |
90 | 89 | ) ) |
91 | 90 | ); |
| 91 | + |
| 92 | + $vipsThumbUrl = $this->getTitle()->getLocalUrl( array( |
| 93 | + 'file' => $file->getName(), |
| 94 | + 'thumb' => $file->getHandler()->makeParamString( $params ) |
| 95 | + ) ); |
| 96 | + |
| 97 | + $this->getOutput()->addHTML( |
| 98 | + Html::element( 'img', array( 'src' => $vipsThumbUrl ) ) |
| 99 | + ); |
92 | 100 | } |
93 | 101 | |
94 | 102 | /** |
— | — | @@ -98,6 +106,7 @@ |
99 | 107 | $form->setWrapperLegend( wfMsg( 'vipsscaler-form-legend' ) ); |
100 | 108 | $form->setSubmitText( wfMsg( 'vipsscaler-form-submit' ) ); |
101 | 109 | $form->setSubmitCallback( array( __CLASS__, 'processForm' ) ); |
| 110 | + $form->setMethod( 'get' ); |
102 | 111 | |
103 | 112 | // Looks like HTMLForm does not actually show the form if submission |
104 | 113 | // was correct. So we have to show it again. |
— | — | @@ -188,6 +197,7 @@ |
189 | 198 | if ( !$handler->normaliseParams( $file, $params ) ) { |
190 | 199 | return $this->streamError( 500 ); |
191 | 200 | } |
| 201 | + |
192 | 202 | |
193 | 203 | # Get the thumbnail |
194 | 204 | if ( is_null( $wgVipsThumbnailerUrl ) ) { |
— | — | @@ -196,6 +206,7 @@ |
197 | 207 | |
198 | 208 | $dstPath = VipsCommand::makeTemp( strrchr( $file->getName(), '.' ) ); |
199 | 209 | $dstUrl = ''; |
| 210 | + wfDebug( __METHOD__ . ": Creating vips thumbnail at $dstPath\n" ); |
200 | 211 | |
201 | 212 | $scalerParams = array( |
202 | 213 | # The size to which the image will be resized |
— | — | @@ -220,8 +231,13 @@ |
221 | 232 | |
222 | 233 | # Call the hook |
223 | 234 | $mto = null; |
224 | | - if ( VipsScaler::onTransform( $handler, $file, $params, $mto ) ) { |
225 | | - StreamFile::stream( $dstPath ); |
| 235 | + VipsScaler::doTransform( $handler, $file, $scalerParams, array(), $mto ); |
| 236 | + if ( $mto && !$mto->isError() ) { |
| 237 | + wfDebug( __METHOD__ . ": streaming thumbnail...\n" ); |
| 238 | + |
| 239 | + $this->getOutput()->disable(); |
| 240 | + header( "Content-Type: {$scalerParams['mimeType']}" ); |
| 241 | + readfile( $dstPath ); |
226 | 242 | } else { |
227 | 243 | $this->streamError( 500 ); |
228 | 244 | } |
— | — | @@ -239,6 +255,8 @@ |
240 | 256 | 'file' => $file->getName(), |
241 | 257 | 'thumb' => $handler->makeParamString( $params ) . '-' . $file->getName() |
242 | 258 | ) ); |
| 259 | + wfDebug( __METHOD__ . ": Getting vips thumb from remove url $url\n" ); |
| 260 | + |
243 | 261 | $options = array( 'method' => 'GET' ); |
244 | 262 | if ( $wgVipsThumbnailerProxy ) { |
245 | 263 | $options['proxy'] = $wgVipsThumbnailerProxy; |
— | — | @@ -261,7 +279,16 @@ |
262 | 280 | } |
263 | 281 | |
264 | 282 | protected function streamError( $code ) { |
265 | | - |
| 283 | + $this->getOutput()->disable(); |
| 284 | + |
| 285 | + if ( $code == 404 ) { |
| 286 | + $msg = 'Not Found'; |
| 287 | + } elseif ( $code == 500 ) { |
| 288 | + $msg = 'Internal Server Error'; |
| 289 | + } |
| 290 | + header( "HTTP/1.0 $code $msg" ); |
| 291 | + echo "<h1>$msg</h1>\r\n"; |
| 292 | + |
266 | 293 | } |
267 | 294 | |
268 | 295 | } |
Index: trunk/extensions/VipsScaler/VipsScaler_body.php |
— | — | @@ -43,9 +43,26 @@ |
44 | 44 | # Check $wgVipsConditions |
45 | 45 | $options = self::getHandlerOptions( $handler, $file, $params ); |
46 | 46 | if ( !$options ) { |
| 47 | + wfDebug( "...\n" ); |
47 | 48 | return true; |
48 | 49 | } |
49 | 50 | |
| 51 | + return self::doTransform( $handler, $file, $params, $options, $mto ); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Performs a transform with VIPS |
| 56 | + * |
| 57 | + * @see VipsScaler::onTransform |
| 58 | + * |
| 59 | + * @param BitmapHandler $handler |
| 60 | + * @param File $file |
| 61 | + * @param array $params |
| 62 | + * @param array $options |
| 63 | + * @param MediaTransformOutput &$mto |
| 64 | + * @return bool |
| 65 | + */ |
| 66 | + public static function doTransform( $handler, $file, $params, $options, &$mto ) { |
50 | 67 | wfDebug( __METHOD__ . ': scaling ' . $file->getName() . " using vips\n" ); |
51 | 68 | |
52 | 69 | $vipsCommands = self::makeCommands( $handler, $file, $params, $options ); |