r104608 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104607‎ | r104608 | r104609 >
Date:22:50, 29 November 2011
Author:reedy
Status:ok
Tags:
Comment:
Trim trailing whitespace

Comments
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
@@ -79,8 +79,7 @@
8080 if ( $request->getCheck( 'bilinear' ) ) {
8181 $vipsUrlOptions['bilinear'] = 1;
8282 }
83 -
84 -
 83+
8584 # Generate normal thumbnail
8685 $params = array( 'width' => $width );
8786 $thumb = $file->transform( $params );
@@ -97,7 +96,7 @@
9897
9998 # Make url to the vips thumbnail
10099 $vipsThumbUrl = $this->getTitle()->getLocalUrl( $vipsUrlOptions );
101 -
 100+
102101 # HTML for the thumbnails
103102 $thumbs = Html::rawElement( 'div', array( 'id' => 'mw-vipstest-thumbnails' ),
104103 Html::element( 'img', array(
@@ -107,14 +106,14 @@
108107 Html::element( 'img', array(
109108 'src' => $vipsThumbUrl,
110109 'alt' => wfMessage( 'vipsscaler-vips-thumb' ),
111 - ) )
 110+ ) )
112111 );
113112
114113 # Helper messages shown above the thumbnails rendering
115114 $help = wfMessage( 'vipsscaler-thumbs-help' )->parseAsBlock();
116115
117116 # A checkbox to easily alternate between both views:
118 - $checkbox = Xml::checkLabel(
 117+ $checkbox = Xml::checkLabel(
119118 wfMessage( 'vipsscaler-thumbs-switch-label' ),
120119 'mw-vipstest-thumbs-switch',
121120 'mw-vipstest-thumbs-switch'
@@ -148,7 +147,7 @@
149148 // was correct. So we have to show it again.
150149 // See HTMLForm::show()
151150 $result = $form->show();
152 - if( $result === true or $result instanceof Status && $result->isGood() ) {
 151+ if( $result === true || $result instanceof Status && $result->isGood() ) {
153152 $form->displayForm( $result );
154153 $this->showThumbnails();
155154 }
@@ -188,7 +187,7 @@
189188 'Bilinear' => array(
190189 'name' => 'bilinear',
191190 'class' => 'HTMLCheckField',
192 - 'label-message' => 'vipsscaler-form-bilinear',
 191+ 'label-message' => 'vipsscaler-form-bilinear',
193192 ),
194193 );
195194
@@ -202,13 +201,18 @@
203202 return $fields;
204203 }
205204
 205+ /**
 206+ * @param $input
 207+ * @param $alldata
 208+ * @return bool|String
 209+ */
206210 public static function validateFileInput( $input, $alldata ) {
207211 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,
209213 # because it is annoying
210214 return true;
211215 }
212 -
 216+
213217 $title = Title::makeTitleSafe( NS_FILE, $input );
214218 if( is_null( $title ) ) {
215219 return wfMsg( 'vipsscaler-invalid-file' );
@@ -221,8 +225,14 @@
222226 // Looks sane enough.
223227 return true;
224228 }
 229+
 230+ /**
 231+ * @param $input
 232+ * @param $allData
 233+ * @return bool|String
 234+ */
225235 public static function validateWidth( $input, $allData ) {
226 - if ( self::validateFileInput( $allData['File'], $allData ) !== true
 236+ if ( self::validateFileInput( $allData['File'], $allData ) !== true
227237 || !trim( $allData['File'] ) ) {
228238 # Invalid file, error will already be shown at file field
229239 return true;
@@ -234,16 +244,23 @@
235245 }
236246 return true;
237247 }
 248+
 249+ /**
 250+ * @param $input
 251+ * @param $allData
 252+ * @return bool|String
 253+ */
238254 public static function validateSharpen( $input, $allData ) {
239255 if ( $input >= 5.0 || $input < 0.0 ) {
240256 return wfMsg( 'vipsscaler-invalid-sharpen' );
241257 }
242258 return true;
243 -
244259 }
245260
246261 /**
247262 * Process data submitted by the form.
 263+ * @param $data array
 264+ * @return Status
248265 */
249266 public static function processForm( array $data ) {
250267 return Status::newGood();
@@ -278,7 +295,6 @@
279296 if ( !$handler->normaliseParams( $file, $params ) ) {
280297 return $this->streamError( 500, "VipsScaler: invalid parameters\n" );
281298 }
282 -
283299
284300 # Get the thumbnail
285301 if ( is_null( $wgVipsThumbnailerHost ) || $request->getBool( 'noproxy' ) ) {
@@ -308,7 +324,7 @@
309325 'dstPath' => $dstPath,
310326 'dstUrl' => $dstUrl,
311327 );
312 -
 328+
313329 $options = array();
314330 if ( $request->getBool( 'bilinear' ) ) {
315331 $options['bilinear'] = true;
@@ -345,7 +361,7 @@
346362 $url = wfExpandUrl( $request->getRequestURL(), PROTO_INTERNAL );
347363 $url = wfAppendQuery( $url, array( 'noproxy' => '1' ) );
348364 wfDebug( __METHOD__ . ": Getting vips thumb from remote url $url\n" );
349 -
 365+
350366 $options = array( 'method' => 'GET' );
351367
352368 $req = MWHttpRequest::factory( $url, $options );
@@ -366,11 +382,11 @@
367383 }
368384 }
369385
370 -
371386 /**
372387 * Generates a blank page with given HTTP error code
373388 *
374 - * @param $code Integer: HTTP error either 404 or 500
 389+ * @param $code Integer HTTP error either 404 or 500
 390+ * @param $error string
375391 */
376392 protected function streamError( $code, $error = '' ) {
377393 $this->getOutput()->setStatusCode( $code );
Index: trunk/extensions/VipsScaler/VipsScaler_body.php
@@ -38,6 +38,7 @@
3939 * @param File $file
4040 * @param array $params
4141 * @param MediaTransformOutput $mto
 42+ * @return bool
4243 */
4344 public static function onTransform( $handler, $file, &$params, &$mto ) {
4445 # Check $wgVipsConditions
@@ -46,15 +47,14 @@
4748 wfDebug( "...\n" );
4849 return true;
4950 }
50 -
5151 return self::doTransform( $handler, $file, $params, $options, $mto );
5252 }
53 -
 53+
5454 /**
5555 * Performs a transform with VIPS
56 - *
 56+ *
5757 * @see VipsScaler::onTransform
58 - *
 58+ *
5959 * @param BitmapHandler $handler
6060 * @param File $file
6161 * @param array $params
@@ -108,10 +108,11 @@
109109 }
110110
111111 /**
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
116117 */
117118 public static function makeCommands( $handler, $file, $params, $options ) {
118119 global $wgVipsCommand;
@@ -136,10 +137,10 @@
137138 # Calculate shrink factors. Offsetting by a small amount is required
138139 # because of rounding down of the target size by VIPS. See 25990#c7
139140 #
140 - # No need to invert source and physical dimensions. They already got
 141+ # No need to invert source and physical dimensions. They already got
141142 # switched if needed.
142143 #
143 - # Use sprintf() instead of plain string conversion so that we can
 144+ # Use sprintf() instead of plain string conversion so that we can
144145 # control the precision
145146 $rx = sprintf( "%.18e", $params['srcWidth'] / ($params['physicalWidth'] + 0.125) );
146147 $ry = sprintf( "%.18e", $params['srcHeight'] / ($params['physicalHeight'] + 0.125) );
@@ -178,7 +179,7 @@
179180 }
180181
181182 if ( !empty( $options['convolution'] ) ) {
182 - $commands[] = new VipsConvolution( $wgVipsCommand,
 183+ $commands[] = new VipsConvolution( $wgVipsCommand,
183184 array( 'im_convf', $options['convolution'] ) );
184185 }
185186
@@ -352,6 +353,7 @@
353354 $this->vips = $vips;
354355 $this->args = $args;
355356 }
 357+
356358 /**
357359 * Set the input and output file of this command
358360 *
@@ -374,6 +376,7 @@
375377 $this->output = $output;
376378 }
377379 }
 380+
378381 /**
379382 * Returns the output filename
380383 * @return string
@@ -381,6 +384,7 @@
382385 public function getOutput() {
383386 return $this->output;
384387 }
 388+
385389 /**
386390 * Return the output of the command
387391 * @return string
@@ -445,26 +449,30 @@
446450 * matrix file as its last argument
447451 */
448452 class VipsConvolution extends VipsCommand {
 453+
 454+ /**
 455+ * @return int
 456+ */
449457 public function execute() {
450458 # Convert a 2D array into a space/newline separated matrix
451459 $convolutionMatrix = array_pop( $this->args );
452460 $convolutionString = '';
453 - foreach ( $convolutionMatrix as $i=>$row ) {
 461+ foreach ( $convolutionMatrix as $row ) {
454462 $convolutionString .= implode( ' ', $row ) . "\n";
455463 }
456464 # Save the matrix in a tempfile
457465 $convolutionFile = self::makeTemp( 'conv' );
458466 file_put_contents( $convolutionFile, $convolutionString );
459467 array_push( $this->args, $convolutionFile );
460 -
 468+
461469 wfDebug( __METHOD__ . ": Convolving image [\n" . $convolutionString . "] \n" );
462 -
 470+
463471 # Call the parent to actually execute the command
464472 $retval = parent::execute();
465 -
 473+
466474 # Remove the temporary matrix file
467475 unlink( $convolutionFile );
468 -
 476+
469477 return $retval;
470478 }
471479 }

Status & tagging log