Tim Starling has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/238082

Change subject: Fix support for height parameter and mustRender
......................................................................

Fix support for height parameter and mustRender

* Validate txopts as if they were image link parameters, by passing them
  through $handler->validateParam().
* Fill in the default width if it is not set, like in
  Linker::makeImageLink(). Parsoid always sets the width if a thumbnail
  format is requested, so we can assume that the source width is
  desired, which reduces the amount of code somewhat. This allows
  transform requests with only a height to work -- box scaling is done
  in MediaHandler::normaliseParams().
* Always transform the image, even if no txopts is given. This matches
  the behaviour of Linker::makeImageLink() and is required for
  mustRender() support. Parsoid will happily process the thumbnail
  output even if it didn't ask for it.

Bug: T111870
Bug: T112045
Change-Id: I56d28e9ae85b03ac59367fb2613da9f6b3987b4a
---
M includes/ApiParsoidBatch.php
1 file changed, 47 insertions(+), 15 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ParsoidBatchAPI 
refs/changes/82/238082/1

diff --git a/includes/ApiParsoidBatch.php b/includes/ApiParsoidBatch.php
index 02753ac..e3bc802 100644
--- a/includes/ApiParsoidBatch.php
+++ b/includes/ApiParsoidBatch.php
@@ -75,7 +75,7 @@
                        } elseif ( $action === 'imageinfo' ) {
                                $filename = $itemParams['filename'];
                                $file = isset( $files[$filename] ) ? 
$files[$filename] : null;
-                               $txopts = isset( $itemParams['txopts'] ) ? 
$itemParams['txopts'] : null;
+                               $txopts = isset( $itemParams['txopts'] ) ? 
$itemParams['txopts'] : array();
                                $itemResult = $this->imageinfo( $filename, 
$file, $txopts );
                        } else {
                                throw new Exception( "Invalid action despite 
validation already being done" );
@@ -190,26 +190,58 @@
                        'url' => wfExpandUrl( $file->getFullURL(), 
PROTO_CURRENT )
                );
 
-               if ( $txopts ) {
-                       $mto = $file->transform( $txopts );
-                       if ( $mto ) {
-                               if ( $mto->isError() ) {
-                                       $result['thumberror'] = $mto->toText();
-                               } else {
-                                       // Proposed MediaTransformOutput 
serialization method for T51896 etc.
-                                       if ( is_callable( $mto, 'getAPIData' ) 
) {
-                                               $result['thumbdata'] = 
$mto->getAPIData();
-                                       }
-
-                                       $result['thumburl'] = wfExpandUrl( 
$mto->getUrl(), PROTO_CURRENT );
-                                       $result['thumbwidth'] = 
$mto->getWidth();
-                                       $result['thumbheight'] = 
$mto->getHeight();
+               $txopts = $this->makeTransformOptions( $file, $txopts );
+               $mto = $file->transform( $txopts );
+               if ( $mto ) {
+                       if ( $mto->isError() ) {
+                               $result['thumberror'] = $mto->toText();
+                       } else {
+                               // Proposed MediaTransformOutput serialization 
method for T51896 etc.
+                               if ( is_callable( $mto, 'getAPIData' ) ) {
+                                       $result['thumbdata'] = 
$mto->getAPIData();
                                }
+
+                               $result['thumburl'] = wfExpandUrl( 
$mto->getUrl(), PROTO_CURRENT );
+                               $result['thumbwidth'] = $mto->getWidth();
+                               $result['thumbheight'] = $mto->getHeight();
                        }
                }
                return $result;
        }
 
+       protected function makeTransformOptions( $file, $hp ) {
+               // Validate the input parameters like Parser::makeImage()
+               $handler = $file->getHandler();
+               if ( !$handler ) {
+                       return array(); // will get iconThumb()
+               }
+               foreach ( $hp as $name => $value ) {
+                       if ( !$handler->validateParam( $name, $value ) ) {
+                               unset( $hp[$name] );
+                       }
+               }
+
+               // This part is similar to Linker::makeImageLink(). If there is 
no width,
+               // set one based on the source file size.
+               $page = isset( $hp['page'] ) ? $hp['page'] : false;
+               if ( !isset( $hp['width'] ) ) {
+                       if ( isset( $hp['height'] ) && $file->isVectorized() ) {
+                               // If it's a vector image, and user only 
specifies height
+                               // we don't want it to be limited by its 
"normal" width.
+                               global $wgSVGMaxSize;
+                               $hp['width'] = $wgSVGMaxSize;
+                       } else {
+                               $hp['width'] = $file->getWidth( $page );
+                       }
+
+                       // We don't need to fill in a default thumbnail width 
here, since
+                       // that is done by Parsoid. Parsoid always sets the 
width parameter
+                       // for thumbnails.
+               }
+
+               return $hp;
+       }
+
        public function isInternal() {
                return true;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/238082
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I56d28e9ae85b03ac59367fb2613da9f6b3987b4a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ParsoidBatchAPI
Gerrit-Branch: master
Gerrit-Owner: Tim Starling <tstarl...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to