Index: trunk/extensions/VipsScaler/SpecialVipsTest.php |
— | — | @@ -79,8 +79,7 @@ |
80 | 80 | if ( $request->getCheck( 'bilinear' ) ) { |
81 | 81 | $vipsUrlOptions['bilinear'] = 1; |
82 | 82 | } |
83 | | - |
84 | | - |
| 83 | + |
85 | 84 | # Generate normal thumbnail |
86 | 85 | $params = array( 'width' => $width ); |
87 | 86 | $thumb = $file->transform( $params ); |
— | — | @@ -97,7 +96,7 @@ |
98 | 97 | |
99 | 98 | # Make url to the vips thumbnail |
100 | 99 | $vipsThumbUrl = $this->getTitle()->getLocalUrl( $vipsUrlOptions ); |
101 | | - |
| 100 | + |
102 | 101 | # HTML for the thumbnails |
103 | 102 | $thumbs = Html::rawElement( 'div', array( 'id' => 'mw-vipstest-thumbnails' ), |
104 | 103 | Html::element( 'img', array( |
— | — | @@ -107,14 +106,14 @@ |
108 | 107 | Html::element( 'img', array( |
109 | 108 | 'src' => $vipsThumbUrl, |
110 | 109 | 'alt' => wfMessage( 'vipsscaler-vips-thumb' ), |
111 | | - ) ) |
| 110 | + ) ) |
112 | 111 | ); |
113 | 112 | |
114 | 113 | # Helper messages shown above the thumbnails rendering |
115 | 114 | $help = wfMessage( 'vipsscaler-thumbs-help' )->parseAsBlock(); |
116 | 115 | |
117 | 116 | # A checkbox to easily alternate between both views: |
118 | | - $checkbox = Xml::checkLabel( |
| 117 | + $checkbox = Xml::checkLabel( |
119 | 118 | wfMessage( 'vipsscaler-thumbs-switch-label' ), |
120 | 119 | 'mw-vipstest-thumbs-switch', |
121 | 120 | 'mw-vipstest-thumbs-switch' |
— | — | @@ -148,7 +147,7 @@ |
149 | 148 | // was correct. So we have to show it again. |
150 | 149 | // See HTMLForm::show() |
151 | 150 | $result = $form->show(); |
152 | | - if( $result === true or $result instanceof Status && $result->isGood() ) { |
| 151 | + if( $result === true || $result instanceof Status && $result->isGood() ) { |
153 | 152 | $form->displayForm( $result ); |
154 | 153 | $this->showThumbnails(); |
155 | 154 | } |
— | — | @@ -188,7 +187,7 @@ |
189 | 188 | 'Bilinear' => array( |
190 | 189 | 'name' => 'bilinear', |
191 | 190 | 'class' => 'HTMLCheckField', |
192 | | - 'label-message' => 'vipsscaler-form-bilinear', |
| 191 | + 'label-message' => 'vipsscaler-form-bilinear', |
193 | 192 | ), |
194 | 193 | ); |
195 | 194 | |
— | — | @@ -202,13 +201,18 @@ |
203 | 202 | return $fields; |
204 | 203 | } |
205 | 204 | |
| 205 | + /** |
| 206 | + * @param $input |
| 207 | + * @param $alldata |
| 208 | + * @return bool|String |
| 209 | + */ |
206 | 210 | public static function validateFileInput( $input, $alldata ) { |
207 | 211 | if ( !trim( $input ) ) { |
208 | | - # Don't show an error if the file is not yet specified, |
| 212 | + # Don't show an error if the file is not yet specified, |
209 | 213 | # because it is annoying |
210 | 214 | return true; |
211 | 215 | } |
212 | | - |
| 216 | + |
213 | 217 | $title = Title::makeTitleSafe( NS_FILE, $input ); |
214 | 218 | if( is_null( $title ) ) { |
215 | 219 | return wfMsg( 'vipsscaler-invalid-file' ); |
— | — | @@ -221,8 +225,14 @@ |
222 | 226 | // Looks sane enough. |
223 | 227 | return true; |
224 | 228 | } |
| 229 | + |
| 230 | + /** |
| 231 | + * @param $input |
| 232 | + * @param $allData |
| 233 | + * @return bool|String |
| 234 | + */ |
225 | 235 | public static function validateWidth( $input, $allData ) { |
226 | | - if ( self::validateFileInput( $allData['File'], $allData ) !== true |
| 236 | + if ( self::validateFileInput( $allData['File'], $allData ) !== true |
227 | 237 | || !trim( $allData['File'] ) ) { |
228 | 238 | # Invalid file, error will already be shown at file field |
229 | 239 | return true; |
— | — | @@ -234,16 +244,23 @@ |
235 | 245 | } |
236 | 246 | return true; |
237 | 247 | } |
| 248 | + |
| 249 | + /** |
| 250 | + * @param $input |
| 251 | + * @param $allData |
| 252 | + * @return bool|String |
| 253 | + */ |
238 | 254 | public static function validateSharpen( $input, $allData ) { |
239 | 255 | if ( $input >= 5.0 || $input < 0.0 ) { |
240 | 256 | return wfMsg( 'vipsscaler-invalid-sharpen' ); |
241 | 257 | } |
242 | 258 | return true; |
243 | | - |
244 | 259 | } |
245 | 260 | |
246 | 261 | /** |
247 | 262 | * Process data submitted by the form. |
| 263 | + * @param $data array |
| 264 | + * @return Status |
248 | 265 | */ |
249 | 266 | public static function processForm( array $data ) { |
250 | 267 | return Status::newGood(); |
— | — | @@ -278,7 +295,6 @@ |
279 | 296 | if ( !$handler->normaliseParams( $file, $params ) ) { |
280 | 297 | return $this->streamError( 500, "VipsScaler: invalid parameters\n" ); |
281 | 298 | } |
282 | | - |
283 | 299 | |
284 | 300 | # Get the thumbnail |
285 | 301 | if ( is_null( $wgVipsThumbnailerHost ) || $request->getBool( 'noproxy' ) ) { |
— | — | @@ -308,7 +324,7 @@ |
309 | 325 | 'dstPath' => $dstPath, |
310 | 326 | 'dstUrl' => $dstUrl, |
311 | 327 | ); |
312 | | - |
| 328 | + |
313 | 329 | $options = array(); |
314 | 330 | if ( $request->getBool( 'bilinear' ) ) { |
315 | 331 | $options['bilinear'] = true; |
— | — | @@ -345,7 +361,7 @@ |
346 | 362 | $url = wfExpandUrl( $request->getRequestURL(), PROTO_INTERNAL ); |
347 | 363 | $url = wfAppendQuery( $url, array( 'noproxy' => '1' ) ); |
348 | 364 | wfDebug( __METHOD__ . ": Getting vips thumb from remote url $url\n" ); |
349 | | - |
| 365 | + |
350 | 366 | $options = array( 'method' => 'GET' ); |
351 | 367 | |
352 | 368 | $req = MWHttpRequest::factory( $url, $options ); |
— | — | @@ -366,11 +382,11 @@ |
367 | 383 | } |
368 | 384 | } |
369 | 385 | |
370 | | - |
371 | 386 | /** |
372 | 387 | * Generates a blank page with given HTTP error code |
373 | 388 | * |
374 | | - * @param $code Integer: HTTP error either 404 or 500 |
| 389 | + * @param $code Integer HTTP error either 404 or 500 |
| 390 | + * @param $error string |
375 | 391 | */ |
376 | 392 | protected function streamError( $code, $error = '' ) { |
377 | 393 | $this->getOutput()->setStatusCode( $code ); |
Index: trunk/extensions/VipsScaler/VipsScaler_body.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | * @param File $file |
40 | 40 | * @param array $params |
41 | 41 | * @param MediaTransformOutput $mto |
| 42 | + * @return bool |
42 | 43 | */ |
43 | 44 | public static function onTransform( $handler, $file, &$params, &$mto ) { |
44 | 45 | # Check $wgVipsConditions |
— | — | @@ -46,15 +47,14 @@ |
47 | 48 | wfDebug( "...\n" ); |
48 | 49 | return true; |
49 | 50 | } |
50 | | - |
51 | 51 | return self::doTransform( $handler, $file, $params, $options, $mto ); |
52 | 52 | } |
53 | | - |
| 53 | + |
54 | 54 | /** |
55 | 55 | * Performs a transform with VIPS |
56 | | - * |
| 56 | + * |
57 | 57 | * @see VipsScaler::onTransform |
58 | | - * |
| 58 | + * |
59 | 59 | * @param BitmapHandler $handler |
60 | 60 | * @param File $file |
61 | 61 | * @param array $params |
— | — | @@ -108,10 +108,11 @@ |
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | | - * @param $handler |
113 | | - * @param $file |
114 | | - * @param $params |
115 | | - * @param $options |
| 112 | + * @param $handler BitmapHandler |
| 113 | + * @param $file File |
| 114 | + * @param $params array |
| 115 | + * @param $options array |
| 116 | + * @return array |
116 | 117 | */ |
117 | 118 | public static function makeCommands( $handler, $file, $params, $options ) { |
118 | 119 | global $wgVipsCommand; |
— | — | @@ -136,10 +137,10 @@ |
137 | 138 | # Calculate shrink factors. Offsetting by a small amount is required |
138 | 139 | # because of rounding down of the target size by VIPS. See 25990#c7 |
139 | 140 | # |
140 | | - # No need to invert source and physical dimensions. They already got |
| 141 | + # No need to invert source and physical dimensions. They already got |
141 | 142 | # switched if needed. |
142 | 143 | # |
143 | | - # Use sprintf() instead of plain string conversion so that we can |
| 144 | + # Use sprintf() instead of plain string conversion so that we can |
144 | 145 | # control the precision |
145 | 146 | $rx = sprintf( "%.18e", $params['srcWidth'] / ($params['physicalWidth'] + 0.125) ); |
146 | 147 | $ry = sprintf( "%.18e", $params['srcHeight'] / ($params['physicalHeight'] + 0.125) ); |
— | — | @@ -178,7 +179,7 @@ |
179 | 180 | } |
180 | 181 | |
181 | 182 | if ( !empty( $options['convolution'] ) ) { |
182 | | - $commands[] = new VipsConvolution( $wgVipsCommand, |
| 183 | + $commands[] = new VipsConvolution( $wgVipsCommand, |
183 | 184 | array( 'im_convf', $options['convolution'] ) ); |
184 | 185 | } |
185 | 186 | |
— | — | @@ -352,6 +353,7 @@ |
353 | 354 | $this->vips = $vips; |
354 | 355 | $this->args = $args; |
355 | 356 | } |
| 357 | + |
356 | 358 | /** |
357 | 359 | * Set the input and output file of this command |
358 | 360 | * |
— | — | @@ -374,6 +376,7 @@ |
375 | 377 | $this->output = $output; |
376 | 378 | } |
377 | 379 | } |
| 380 | + |
378 | 381 | /** |
379 | 382 | * Returns the output filename |
380 | 383 | * @return string |
— | — | @@ -381,6 +384,7 @@ |
382 | 385 | public function getOutput() { |
383 | 386 | return $this->output; |
384 | 387 | } |
| 388 | + |
385 | 389 | /** |
386 | 390 | * Return the output of the command |
387 | 391 | * @return string |
— | — | @@ -445,26 +449,30 @@ |
446 | 450 | * matrix file as its last argument |
447 | 451 | */ |
448 | 452 | class VipsConvolution extends VipsCommand { |
| 453 | + |
| 454 | + /** |
| 455 | + * @return int |
| 456 | + */ |
449 | 457 | public function execute() { |
450 | 458 | # Convert a 2D array into a space/newline separated matrix |
451 | 459 | $convolutionMatrix = array_pop( $this->args ); |
452 | 460 | $convolutionString = ''; |
453 | | - foreach ( $convolutionMatrix as $i=>$row ) { |
| 461 | + foreach ( $convolutionMatrix as $row ) { |
454 | 462 | $convolutionString .= implode( ' ', $row ) . "\n"; |
455 | 463 | } |
456 | 464 | # Save the matrix in a tempfile |
457 | 465 | $convolutionFile = self::makeTemp( 'conv' ); |
458 | 466 | file_put_contents( $convolutionFile, $convolutionString ); |
459 | 467 | array_push( $this->args, $convolutionFile ); |
460 | | - |
| 468 | + |
461 | 469 | wfDebug( __METHOD__ . ": Convolving image [\n" . $convolutionString . "] \n" ); |
462 | | - |
| 470 | + |
463 | 471 | # Call the parent to actually execute the command |
464 | 472 | $retval = parent::execute(); |
465 | | - |
| 473 | + |
466 | 474 | # Remove the temporary matrix file |
467 | 475 | unlink( $convolutionFile ); |
468 | | - |
| 476 | + |
469 | 477 | return $retval; |
470 | 478 | } |
471 | 479 | } |