r102863 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102862‎ | r102863 | r102864 >
Date:15:41, 12 November 2011
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
VipsScaler:
* Fix readme typo
* Add sharpen and bilinear options to Special:VipsTest and add corresponding messages
* Remove params option from form and remove corresponding message
* Tweak message from r101811
Modified paths:
  • /trunk/extensions/VipsScaler/README (modified) (history)
  • /trunk/extensions/VipsScaler/SpecialVipsTest.php (modified) (history)
  • /trunk/extensions/VipsScaler/VipsScaler.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/VipsScaler/VipsScaler.i18n.php
@@ -12,7 +12,7 @@
1313 'vipstest' => 'VIPS scaling test page',
1414
1515 'vipsscaler-desc' => 'Create thumbnails using VIPS',
16 - 'vipsscaler-invalid-file' => 'Invalid file: Could not process requested file. Does it exist on this wiki?',
 16+ 'vipsscaler-invalid-file' => 'Could not process requested file. Check that it exists on this wiki.',
1717 'vipsscaler-invalid-width' => 'You must specify a width (integer > 0).',
1818 'vipsscaler-thumb-error' => 'VIPS could not generate a thumbnail with given parameters.',
1919
@@ -20,8 +20,12 @@
2121 'vipsscaler-form-legend' => 'VIPS scaling',
2222 'vipsscaler-form-width' => 'Thumbnail width:',
2323 'vipsscaler-form-file' => 'File on this wiki:',
24 - 'vipsscaler-form-params' => 'VIPS parameters:',
 24+ 'vipsscaler-form-sharpen-radius' => 'Amount of sharpening:',
 25+ 'vipsscaler-form-bilinear' => 'Bilinear scaling',
2526 'vipsscaler-form-submit' => 'Generate thumbnail',
 27+
 28+ 'vipsscaler-default-thumb' => 'Thumbnail generated with default scaler',
 29+ 'vipsscaler-vips-thumb' => 'Thumbnail generated with VIPS',
2630
2731 # User rights
2832 'right-vipsscaler-test' => 'Use the VIPS scaling test interface [[Special:VipsTest]]',
@@ -39,8 +43,11 @@
4044 'vipsscaler-form-legend' => 'Special:VipsTest form: legend at top of the form',
4145 'vipsscaler-form-width' => 'Special:VipsTest form: label for the width input box',
4246 'vipsscaler-form-file' => 'Special:VipsTest form: label for the file input box',
43 - 'vipsscaler-form-params' => 'Special:VipsTest form: label for the VIPS parameters box',
4447 'vipsscaler-form-submit' => 'Special:VipsTest form: submit button text. The page will then attempt to generate a thumbnail with the given parameters.',
 48+ 'vipsscaler-form-bilinear' => 'Special:VipsTest form: Checkbox label to determine whether to enable bilinear scaling',
 49+ 'vipsscaler-form-sharpen-radius' => 'Special:VipsTest form: label for the sharpening amount input box',
 50+ 'vipsscaler-default-thumb' => 'Special:VipsTest: caption of the default thumbnail',
 51+ 'vipsscaler-vips-thumb' => 'Special:VipsTest: caption of the vips thumbnail',
4552 );
4653
4754 /** Afrikaans (Afrikaans)
Index: trunk/extensions/VipsScaler/SpecialVipsTest.php
@@ -42,7 +42,7 @@
4343 return;
4444 }
4545
46 - if ( $request->getText( 'thumb' ) && $request->getText( 'file' ) ) {
 46+ if ( $request->getText( 'thumb' ) ) {
4747 $this->streamThumbnail();
4848 } elseif ( $par || $request->getText( 'file' ) ) {
4949 $this->showForm();
@@ -57,6 +57,7 @@
5858 protected function showThumbnails() {
5959 $request = $this->getRequest();
6060
 61+ # Check if valid file was provided
6162 $title = Title::makeTitleSafe( NS_FILE, $request->getText( 'file' ) );
6263 if ( is_null( $title ) ) {
6364 $this->getOutput()->addWikiMsg( 'vipsscaler-invalid-file' );
@@ -68,12 +69,22 @@
6970 return;
7071 }
7172
 73+ # Create options
7274 $width = $request->getInt( 'width' );
7375 if ( !$width ) {
7476 $this->getOutput()->addWikiMsg( 'vipsscaler-invalid-width' );
7577 return;
7678 }
77 -
 79+ $vipsUrlOptions = array( 'thumb' => $file->getName(), 'width' => $width );
 80+ if ( $request->getBool( 'sharpen' ) ) {
 81+ $vipsUrlOptions['sharpen'] = $request->getVal( 'sharpen' );
 82+ }
 83+ if ( $request->getCheck( 'bilinear' ) ) {
 84+ $vipsUrlOptions['bilinear'] = 1;
 85+ }
 86+
 87+
 88+ # Generate normal thumbnail
7889 $params = array( 'width' => $width );
7990 $thumb = $file->transform( $params );
8091 if ( !$thumb || $thumb->isError() ) {
@@ -81,21 +92,29 @@
8293 return;
8394 }
8495
85 - $this->getOutput()->addHTML(
86 - $thumb->toHtml( array(
87 - # Options for the thumbnail. See ThumbnailImage::toHtml()
88 - 'desc-link' => true,
89 - ) )
 96+ # Check if we actually scaled the file
 97+ $normalThumbUrl = $thumb->getUrl();
 98+ if ( wfExpandUrl( $normalThumbUrl ) == $file->getFullUrl() ) {
 99+ // TODO: message
 100+ }
 101+
 102+ # Make url to the vips thumbnail
 103+ $vipsThumbUrl = $this->getTitle()->getLocalUrl( $vipsUrlOptions );
 104+
 105+ # Add to output
 106+ $html = Html::rawElement( 'div', array( 'id' => 'mw-vipstest-thumbnails' ),
 107+ Html::rawElement( 'div', array( 'id' => 'mw-vipstest-default-thumb' ),
 108+ Html::element( 'img', array( 'src' => $normalThumbUrl ) ) . ' ' .
 109+ wfMessage( 'vipsscaler-default-thumb' )->parseAsBlock()
 110+ )
 111+ . ' ' .
 112+ Html::rawElement( 'div', array( 'id' => 'mw-vipstest-vips-thumb' ),
 113+ Html::element( 'img', array( 'src' => $vipsThumbUrl ) ) . ' ' .
 114+ wfMessage( 'vipsscaler-vips-thumb' )->parseAsBlock()
 115+ )
90116 );
91117
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 - );
 118+ $this->getOutput()->addHTML( $html );
100119 }
101120
102121 /**
@@ -135,14 +154,22 @@
136155 'name' => 'file',
137156 'class' => 'HTMLTextField',
138157 'required' => true,
 158+ 'size' => '80',
139159 'label-message' => 'vipsscaler-form-file',
140160 'validation-callback' => array( __CLASS__, 'validateFileInput' ),
141161 ),
142 - 'Params' => array(
143 - 'name' => 'params',
144 - 'class' => 'HTMLTextField',
145 - 'label-message' => 'vipsscaler-form-params',
 162+ 'SharpenRadius' => array(
 163+ 'name' => 'sharpen',
 164+ 'class' => 'HTMLFloatField',
 165+ 'default' => '0.0',
 166+ 'size' => '5',
 167+ 'label-message' => 'vipsscaler-form-sharpen-radius',
146168 ),
 169+ 'Bilinear' => array(
 170+ 'name' => 'bilinear',
 171+ 'class' => 'HTMLCheckField',
 172+ 'label-message' => 'vipsscaler-form-bilinear',
 173+ ),
147174 );
148175 return $fields;
149176 }
@@ -177,7 +204,7 @@
178205 $request = $this->getRequest();
179206
180207 # Validate title and file existance
181 - $title = Title::makeTitleSafe( NS_FILE, $request->getText( 'file' ) );
 208+ $title = Title::makeTitleSafe( NS_FILE, $request->getText( 'thumb' ) );
182209 if ( is_null( $title ) ) {
183210 return $this->streamError( 404 );
184211 }
@@ -193,7 +220,7 @@
194221
195222 # Validate param string
196223 $handler = $file->getHandler();
197 - $params = $handler->parseParamString( $request->getText( 'thumb' ) );
 224+ $params = array( 'width' => $request->getInt( 'width' ) );
198225 if ( !$handler->normaliseParams( $file, $params ) ) {
199226 return $this->streamError( 500 );
200227 }
@@ -227,11 +254,22 @@
228255 'dstPath' => $dstPath,
229256 'dstUrl' => $dstUrl,
230257 );
 258+
 259+ $options = array();
 260+ if ( $request->getBool( 'bilinear' ) ) {
 261+ $options['bilinear'] = true;
 262+ wfDebug( __METHOD__ . ": using bilinear scaling\n" );
 263+ }
 264+ if ( $request->getBool( 'sharpen' ) && $request->getInt( 'sharpen' ) < 5 ) {
 265+ # Limit sharpen sigma to 5, otherwise we have to write huge convolution matrices
 266+ $options['sharpen'] = array( 'sigma' => floatval( $request->getVal( 'sharpen' ) ) );
 267+ wfDebug( __METHOD__ . ": sharpening with radius {$options['sharpen']}\n" );
 268+ }
231269
232270
233271 # Call the hook
234272 $mto = null;
235 - VipsScaler::doTransform( $handler, $file, $scalerParams, array(), $mto );
 273+ VipsScaler::doTransform( $handler, $file, $scalerParams, $options, $mto );
236274 if ( $mto && !$mto->isError() ) {
237275 wfDebug( __METHOD__ . ": streaming thumbnail...\n" );
238276
Index: trunk/extensions/VipsScaler/README
@@ -23,5 +23,5 @@
2424
2525 $wgVipsCommand : path to the vips command (default: vips).
2626
27 -By default everything is scalled using vips. To disable scaling, set
 27+By default everything is scaled using vips. To disable scaling, set
2828 $wgVipsOptions = array();

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101811prefix i18n msg with "vipsscaler-"...hashar14:32, 3 November 2011

Comments

#Comment by Hashar (talk | contribs)   17:22, 16 November 2011

Maybe make the sharpen factor <= 5 ?

Inputs are way better than the freeform parameters input :D

Status & tagging log