r101678 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101677‎ | r101678 | r101679 >
Date:20:51, 2 November 2011
Author:btongminh
Status:ok
Tags:
Comment:
Follow-up r99911, r99912: Hook into new BitmapHandlerCheckImageArea hook
Modified paths:
  • /trunk/extensions/VipsScaler/VipsScaler.php (modified) (history)
  • /trunk/extensions/VipsScaler/VipsScaler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/VipsScaler/VipsScaler.php
@@ -32,6 +32,7 @@
3333 $wgExtensionMessagesFiles['VipsScaler'] = "$dir/VipsScaler.i18n.php";
3434
3535 $wgHooks['BitmapHandlerTransform'][] = 'VipsScaler::onTransform';
 36+$wgHooks['BitmapHandlerCheckImageArea'][] = 'VipsScaler::onBitmapHandlerCheckImageArea';
3637
3738 # Download vips from http://www.vips.ecs.soton.ac.uk/
3839 $wgVipsCommand = 'vips';
Index: trunk/extensions/VipsScaler/VipsScaler_body.php
@@ -14,8 +14,10 @@
1515 $options = self::getHandlerOptions( $handler, $file, $params );
1616 if ( !$options ) {
1717 return true;
18 - }
 18+ }
1919
 20+ wfDebug( __METHOD__ . ': scaling ' . $file->getName() . " using vips\n" );
 21+
2022 $vipsCommands = self::makeCommands( $handler, $file, $params, $options );
2123 if ( count( $vipsCommands ) == 0 ) {
2224 return true;
@@ -46,7 +48,7 @@
4749 }
4850
4951 # Set comment
50 - if ( !empty( $options['setcomment'] ) && isset( $params['comment'] ) ) {
 52+ if ( !empty( $options['setcomment'] ) && !empty( $params['comment'] ) ) {
5153 self::setJpegComment( $params['dstPath'], $params['comment'] );
5254 }
5355
@@ -182,7 +184,7 @@
183185 continue;
184186 }
185187
186 - $area = $handler->getImageArea( $file, $params['srcWidth'], $params['srcHeight'] );
 188+ $area = $handler->getImageArea( $file );
187189 if ( isset( $condition['minArea'] ) && $area < $condition['minArea'] ) {
188190 continue;
189191 }
@@ -190,7 +192,7 @@
191193 continue;
192194 }
193195
194 - $shrinkFactor = $params['srcWidth'] / (
 196+ $shrinkFactor = $file->getWidth() / (
195197 ( ( $handler->getRotation( $file ) % 180 ) == 90 ) ?
196198 $params['physicalHeight'] : $params['physicalWidth'] );
197199 if ( isset( $condition['minShrinkFactor'] ) &&
@@ -240,6 +242,24 @@
241243 }
242244 }
243245
 246+ /**
 247+ * Hook to BitmapHandlerCheckImageArea. Will set $result to true if the
 248+ * file will by handled by VipsScaler.
 249+ *
 250+ * @param File $file
 251+ * @param array &$params
 252+ * @param mixed &$result
 253+ * @return bool
 254+ */
 255+ public static function onBitmapHandlerCheckImageArea( $file, &$params, &$result ) {
 256+ if ( self::getHandlerOptions( $file->getHandler(), $file, $params ) !== false ) {
 257+ wfDebug( __METHOD__ . ": Overriding $wgMaxImageAre\n" );
 258+ $result = true;
 259+ return false;
 260+ }
 261+ return true;
 262+ }
 263+
244264
245265 }
246266

Sign-offs

UserFlagDate
Hashartested14:39, 3 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99911Per bug 28135, disable $wgMaxImageArea check when transforming using a hook, ...btongminh20:36, 15 October 2011
r99912Per bug 28135:...btongminh20:39, 15 October 2011

Status & tagging log