r103572 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103571‎ | r103572 | r103573 >
Date:05:46, 18 November 2011
Author:tstarling
Status:ok
Tags:
Comment:
* Split Special:VipsTest out into its own extension registration file so that we don't always have to have it enabled
* Don't try to convert "sharpen" to integer since it is typically a floating point number less than 1
* Make the default sharpen parameter equal to the one used by ImageMagick
* Don't put two dots in the output filename.
* Show detailed error message when VIPS hits an error
* Remove the shadow from the comparison line, so that both images look equally bright when comparing fine detail.
Modified paths:
  • /trunk/extensions/VipsScaler/SpecialVipsTest.php (modified) (history)
  • /trunk/extensions/VipsScaler/VipsScaler.php (modified) (history)
  • /trunk/extensions/VipsScaler/VipsTest.php (added) (history)
  • /trunk/extensions/VipsScaler/modules/ext.vipsScaler/ext.vipsScaler.css (modified) (history)

Diff [purge]

Index: trunk/extensions/VipsScaler/VipsScaler.php
@@ -33,16 +33,9 @@
3434 $wgAutoloadClasses['VipsScaler'] = "$dir/VipsScaler_body.php";
3535 $wgAutoloadClasses['VipsCommand'] = "$dir/VipsScaler_body.php";
3636 $wgAutoloadClasses['VipsConvolution'] = "$dir/VipsScaler_body.php";
37 -$wgAutoloadClasses['SpecialVipsTest'] = "$dir/SpecialVipsTest.php";
3837
39 -
40 -$wgSpecialPages['VipsTest'] = 'SpecialVipsTest';
41 -$wgExtensionAliasesFiles['VipsTest'] = "$dir/VipsScaler.alias.php";
4238 $wgExtensionMessagesFiles['VipsScaler'] = "$dir/VipsScaler.i18n.php";
4339
44 -$wgAvailableRights[] = 'vipsscaler-test';
45 -$wgGroupPermissions['*']['vipsscaler-test'] = true;
46 -
4740 $wgHooks['BitmapHandlerTransform'][] = 'VipsScaler::onTransform';
4841 $wgHooks['BitmapHandlerCheckImageArea'][] = 'VipsScaler::onBitmapHandlerCheckImageArea';
4942
Index: trunk/extensions/VipsScaler/VipsTest.php
@@ -0,0 +1,33 @@
 2+<?php
 3+
 4+/**
 5+ * Extension registration file for Special:VipsTest. The VipsScaler extension
 6+ * must be enabled.
 7+ */
 8+
 9+if ( !defined( 'MEDIAWIKI' ) ) exit( 1 );
 10+
 11+/**
 12+ * The remote URL which will do the scaling. Use this to send scaling to an
 13+ * isolated set of servers. Set this to null to do the scaling locally.
 14+ */
 15+$wgVipsThumbnailerUrl = null;
 16+
 17+/**
 18+ * The host to send the request to when doing the scaling remotely.
 19+ */
 20+$wgVipsThumbnailerProxy = null;
 21+
 22+/** Registration */
 23+$wgAutoloadClasses['SpecialVipsTest'] = "$dir/SpecialVipsTest.php";
 24+$wgExtensionAliasesFiles['VipsTest'] = "$dir/VipsScaler.alias.php";
 25+$wgAvailableRights[] = 'vipsscaler-test';
 26+$wgGroupPermissions['*']['vipsscaler-test'] = true;
 27+$wgSpecialPages['VipsTest'] = 'SpecialVipsTest';
 28+
 29+/**
 30+ * Disable VipsScaler for ordinary image scaling so that the test has something
 31+ * to compare against.
 32+ */
 33+$wgVipsOptions = array();
 34+
Property changes on: trunk/extensions/VipsScaler/VipsTest.php
___________________________________________________________________
Added: svn:eol-style
135 + native
Index: trunk/extensions/VipsScaler/SpecialVipsTest.php
@@ -21,7 +21,7 @@
2222 */
2323
2424 /**
25 - * A Special page intended to test the Vipscaler.
 25+ * A Special page intended to test the VipsScaler.
2626 * @author Bryan Tong Minh
2727 */
2828 class SpecialVipsTest extends SpecialPage {
@@ -73,8 +73,8 @@
7474 return;
7575 }
7676 $vipsUrlOptions = array( 'thumb' => $file->getName(), 'width' => $width );
77 - if ( $request->getInt( 'sharpen' ) ) {
78 - $vipsUrlOptions['sharpen'] = $request->getVal( 'sharpen' );
 77+ if ( $request->getVal( 'sharpen' ) ) {
 78+ $vipsUrlOptions['sharpen'] = floatval( $request->getVal( 'sharpen' ) );
7979 }
8080 if ( $request->getCheck( 'bilinear' ) ) {
8181 $vipsUrlOptions['bilinear'] = 1;
@@ -173,6 +173,14 @@
174174 'label-message' => 'vipsscaler-form-bilinear',
175175 ),
176176 );
 177+
 178+ /**
 179+ * Match ImageMagick by default
 180+ */
 181+ global $wgSharpenParameter;
 182+ if ( preg_match( '/^[0-9.]+x([0-9.]+)$/', $wgSharpenParameter, $m ) ) {
 183+ $fields['SharpenRadius']['default'] = $m[1];
 184+ }
177185 return $fields;
178186 }
179187
@@ -227,7 +235,7 @@
228236 *
229237 */
230238 protected function streamThumbnail() {
231 - global $wgVipsThumbnailerUrl;
 239+ global $wgVipsThumbnailerUrl, $wgVipsThumbnailerProxy;
232240
233241 $request = $this->getRequest();
234242
@@ -259,7 +267,7 @@
260268 # No remote scaler, need to do it ourselves.
261269 # Emulate the BitmapHandlerTransform hook
262270
263 - $dstPath = VipsCommand::makeTemp( strrchr( $file->getName(), '.' ) );
 271+ $dstPath = VipsCommand::makeTemp( $file->getExtension() );
264272 $dstUrl = '';
265273 wfDebug( __METHOD__ . ": Creating vips thumbnail at $dstPath\n" );
266274
@@ -288,7 +296,7 @@
289297 $options['bilinear'] = true;
290298 wfDebug( __METHOD__ . ": using bilinear scaling\n" );
291299 }
292 - if ( $request->getInt( 'sharpen' ) && $request->getInt( 'sharpen' ) < 5 ) {
 300+ if ( $request->getVal( 'sharpen' ) && $request->getVal( 'sharpen' ) < 5 ) {
293301 # Limit sharpen sigma to 5, otherwise we have to write huge convolution matrices
294302 $options['sharpen'] = array( 'sigma' => floatval( $request->getVal( 'sharpen' ) ) );
295303 wfDebug( __METHOD__ . ": sharpening with radius {$options['sharpen']}\n" );
@@ -305,7 +313,7 @@
306314 header( "Content-Type: {$scalerParams['mimeType']}" );
307315 readfile( $dstPath );
308316 } else {
309 - $this->streamError( 500 );
 317+ $this->streamError( 500, $mto->getHtmlMsg() );
310318 }
311319
312320 # Cleanup the temporary file
@@ -315,8 +323,6 @@
316324
317325 } else {
318326 # Request the thumbnail at a remote scaler
319 - global $wgVipsThumbnailerProxy;
320 -
321327 $url = wfAppendQuery( $wgVipsThumbnailerUrl, array(
322328 'file' => $file->getName(),
323329 'thumb' => $handler->makeParamString( $params ) . '-' . $file->getName()
@@ -350,9 +356,10 @@
351357 *
352358 * @param $code Integer: HTTP error either 404 or 500
353359 */
354 - protected function streamError( $code ) {
 360+ protected function streamError( $code, $error = '' ) {
355361 $this->getOutput()->setStatusCode( $code );
356362 $this->getOutput()->setArticleBodyOnly( true );
 363+ $this->getOutput()->addHTML( $error );
357364 }
358365
359366 }
Index: trunk/extensions/VipsScaler/modules/ext.vipsScaler/ext.vipsScaler.css
@@ -8,3 +8,10 @@
99 top:10px;
1010 bottom:auto;
1111 }
 12+.uc-mask {
 13+ /* Remove annoying shadow */
 14+ box-shadow: none;
 15+ box-shadow: none;
 16+ -webkit-box-shadow: none;
 17+ -moz-box-shadow: none;
 18+}

Sign-offs

UserFlagDate
Bryaninspected08:43, 18 November 2011

Status & tagging log