Index: trunk/extensions/VipsScaler/SpecialVipsTest.php |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | return; |
78 | 78 | } |
79 | 79 | $vipsUrlOptions = array( 'thumb' => $file->getName(), 'width' => $width ); |
80 | | - if ( $request->getBool( 'sharpen' ) ) { |
| 80 | + if ( $request->getInt( 'sharpen' ) ) { |
81 | 81 | $vipsUrlOptions['sharpen'] = $request->getVal( 'sharpen' ); |
82 | 82 | } |
83 | 83 | if ( $request->getCheck( 'bilinear' ) ) { |
— | — | @@ -143,6 +143,14 @@ |
144 | 144 | */ |
145 | 145 | protected function getFormFields() { |
146 | 146 | $fields = array( |
| 147 | + 'File' => array( |
| 148 | + 'name' => 'file', |
| 149 | + 'class' => 'HTMLTextField', |
| 150 | + 'required' => true, |
| 151 | + 'size' => '80', |
| 152 | + 'label-message' => 'vipsscaler-form-file', |
| 153 | + 'validation-callback' => array( __CLASS__, 'validateFileInput' ), |
| 154 | + ), |
147 | 155 | 'Width' => array( |
148 | 156 | 'name' => 'width', |
149 | 157 | 'class' => 'HTMLIntField', |
— | — | @@ -150,21 +158,15 @@ |
151 | 159 | 'size' => '5', |
152 | 160 | 'required' => true, |
153 | 161 | 'label-message' => 'vipsscaler-form-width', |
| 162 | + 'validation-callback' => array( __CLASS__, 'validateWidth' ), |
154 | 163 | ), |
155 | | - 'File' => array( |
156 | | - 'name' => 'file', |
157 | | - 'class' => 'HTMLTextField', |
158 | | - 'required' => true, |
159 | | - 'size' => '80', |
160 | | - 'label-message' => 'vipsscaler-form-file', |
161 | | - 'validation-callback' => array( __CLASS__, 'validateFileInput' ), |
162 | | - ), |
163 | 164 | 'SharpenRadius' => array( |
164 | 165 | 'name' => 'sharpen', |
165 | 166 | 'class' => 'HTMLFloatField', |
166 | 167 | 'default' => '0.0', |
167 | 168 | 'size' => '5', |
168 | 169 | 'label-message' => 'vipsscaler-form-sharpen-radius', |
| 170 | + 'validation-callback' => array( __CLASS__, 'validateSharpen' ), |
169 | 171 | ), |
170 | 172 | 'Bilinear' => array( |
171 | 173 | 'name' => 'bilinear', |
— | — | @@ -176,6 +178,12 @@ |
177 | 179 | } |
178 | 180 | |
179 | 181 | public static function validateFileInput( $input, $alldata ) { |
| 182 | + if ( !trim( $input ) ) { |
| 183 | + # Don't show an error if the file is not yet specified, |
| 184 | + # because it is annoying |
| 185 | + return true; |
| 186 | + } |
| 187 | + |
180 | 188 | $title = Title::makeTitleSafe( NS_FILE, $input ); |
181 | 189 | if( is_null( $title ) ) { |
182 | 190 | return wfMsg( 'vipsscaler-invalid-file' ); |
— | — | @@ -188,6 +196,25 @@ |
189 | 197 | // Looks sane enough. |
190 | 198 | return true; |
191 | 199 | } |
| 200 | + public static function validateWidth( $input, $allData ) { |
| 201 | + if ( self::validateFileInput( $allData['File'], $allData ) !== true ) { |
| 202 | + # Invalid file, error will already be shown at file field |
| 203 | + return true; |
| 204 | + } |
| 205 | + $title = Title::makeTitleSafe( NS_FILE, $allData['File'] ); |
| 206 | + $file = wfFindFile( $title ); |
| 207 | + if ( $input <= 0 || $input >= $file->getWidth() ) { |
| 208 | + return wfMsg( 'vipsscaler-invalid-width's ); |
| 209 | + } |
| 210 | + return true; |
| 211 | + } |
| 212 | + public static function validateSharpen( $input, $allData ) { |
| 213 | + if ( $input >= 5.0 || $input < 0.0 ) { |
| 214 | + return wfMsg( 'vipsscaler-invalid-sharpen' ); |
| 215 | + } |
| 216 | + return true; |
| 217 | + |
| 218 | + } |
192 | 219 | |
193 | 220 | /** |
194 | 221 | * Process data submitted by the form. |
— | — | @@ -261,7 +288,7 @@ |
262 | 289 | $options['bilinear'] = true; |
263 | 290 | wfDebug( __METHOD__ . ": using bilinear scaling\n" ); |
264 | 291 | } |
265 | | - if ( $request->getBool( 'sharpen' ) && $request->getInt( 'sharpen' ) < 5 ) { |
| 292 | + if ( $request->getInt( 'sharpen' ) && $request->getInt( 'sharpen' ) < 5 ) { |
266 | 293 | # Limit sharpen sigma to 5, otherwise we have to write huge convolution matrices |
267 | 294 | $options['sharpen'] = array( 'sigma' => floatval( $request->getVal( 'sharpen' ) ) ); |
268 | 295 | wfDebug( __METHOD__ . ": sharpening with radius {$options['sharpen']}\n" ); |
Index: trunk/extensions/VipsScaler/VipsScaler.i18n.php |
— | — | @@ -13,7 +13,8 @@ |
14 | 14 | |
15 | 15 | 'vipsscaler-desc' => 'Create thumbnails using VIPS', |
16 | 16 | 'vipsscaler-invalid-file' => 'Could not process requested file. Check that it exists on this wiki.', |
17 | | - 'vipsscaler-invalid-width' => 'You must specify a width (integer > 0).', |
| 17 | + 'vipsscaler-invalid-width' => 'Thumbnail width should be larger than zero and not larger than file width.', |
| 18 | + 'vipsscaler-invalid-sharpen' => 'Sharpening amount should be a number larger than zero and smaller than five.', |
18 | 19 | 'vipsscaler-thumb-error' => 'VIPS could not generate a thumbnail with given parameters.', |
19 | 20 | |
20 | 21 | # Vipscaler test form: |