r102029 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102028‎ | r102029 | r102030 >
Date:18:55, 4 November 2011
Author:btongminh
Status:ok
Tags:
Comment:
Follow-up r101835, basic functionality in SpecialVipsTest. Needs some polishing
Modified paths:
  • /trunk/extensions/VipsScaler/SpecialVipsTest.php (modified) (history)
  • /trunk/extensions/VipsScaler/VipsScaler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/VipsScaler/SpecialVipsTest.php
@@ -75,8 +75,7 @@
7676 }
7777
7878 $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 );
8180 if ( !$thumb || $thumb->isError() ) {
8281 $this->getOutput()->addWikiMsg( 'vipsscaler-thumb-error' );
8382 return;
@@ -88,6 +87,15 @@
8988 'desc-link' => true,
9089 ) )
9190 );
 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+ );
92100 }
93101
94102 /**
@@ -98,6 +106,7 @@
99107 $form->setWrapperLegend( wfMsg( 'vipsscaler-form-legend' ) );
100108 $form->setSubmitText( wfMsg( 'vipsscaler-form-submit' ) );
101109 $form->setSubmitCallback( array( __CLASS__, 'processForm' ) );
 110+ $form->setMethod( 'get' );
102111
103112 // Looks like HTMLForm does not actually show the form if submission
104113 // was correct. So we have to show it again.
@@ -188,6 +197,7 @@
189198 if ( !$handler->normaliseParams( $file, $params ) ) {
190199 return $this->streamError( 500 );
191200 }
 201+
192202
193203 # Get the thumbnail
194204 if ( is_null( $wgVipsThumbnailerUrl ) ) {
@@ -196,6 +206,7 @@
197207
198208 $dstPath = VipsCommand::makeTemp( strrchr( $file->getName(), '.' ) );
199209 $dstUrl = '';
 210+ wfDebug( __METHOD__ . ": Creating vips thumbnail at $dstPath\n" );
200211
201212 $scalerParams = array(
202213 # The size to which the image will be resized
@@ -220,8 +231,13 @@
221232
222233 # Call the hook
223234 $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 );
226242 } else {
227243 $this->streamError( 500 );
228244 }
@@ -239,6 +255,8 @@
240256 'file' => $file->getName(),
241257 'thumb' => $handler->makeParamString( $params ) . '-' . $file->getName()
242258 ) );
 259+ wfDebug( __METHOD__ . ": Getting vips thumb from remove url $url\n" );
 260+
243261 $options = array( 'method' => 'GET' );
244262 if ( $wgVipsThumbnailerProxy ) {
245263 $options['proxy'] = $wgVipsThumbnailerProxy;
@@ -261,7 +279,16 @@
262280 }
263281
264282 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+
266293 }
267294
268295 }
Index: trunk/extensions/VipsScaler/VipsScaler_body.php
@@ -43,9 +43,26 @@
4444 # Check $wgVipsConditions
4545 $options = self::getHandlerOptions( $handler, $file, $params );
4646 if ( !$options ) {
 47+ wfDebug( "...\n" );
4748 return true;
4849 }
4950
 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 ) {
5067 wfDebug( __METHOD__ . ': scaling ' . $file->getName() . " using vips\n" );
5168
5269 $vipsCommands = self::makeCommands( $handler, $file, $params, $options );

Follow-up revisions

RevisionCommit summaryAuthorDate
r102275typo in debug message...hashar11:25, 7 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101835Force thumb rendering!...hashar17:08, 3 November 2011

Status & tagging log