Move wfFixBoxImage() out of ImageFunctions and into MediaHandler. It's only used...
authorChad Horohoe <demon@users.mediawiki.org>
Thu, 28 Jul 2011 00:07:08 +0000 (00:07 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Thu, 28 Jul 2011 00:07:08 +0000 (00:07 +0000)
Where to move wfIsBadImage() so we can kill ImageFunctions?

includes/ImageFunctions.php
includes/media/Generic.php

index d048a9d..aea00da 100644 (file)
@@ -75,20 +75,3 @@ function wfIsBadImage( $name, $contextTitle = false ) {
        wfProfileOut( __METHOD__ );
        return $bad;
 }
-
-/**
- * Calculate the largest thumbnail width for a given original file size
- * such that the thumbnail's height is at most $maxHeight.
- * @param $boxWidth Integer Width of the thumbnail box.
- * @param $boxHeight Integer Height of the thumbnail box.
- * @param $maxHeight Integer Maximum height expected for the thumbnail.
- * @return Integer.
- */
-function wfFitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
-       $idealWidth = $boxWidth * $maxHeight / $boxHeight;
-       $roundedUp = ceil( $idealWidth );
-       if( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight )
-               return floor( $idealWidth );
-       else
-               return $roundedUp;
-}
index 48735eb..0b3d546 100644 (file)
@@ -441,6 +441,24 @@ abstract class MediaHandler {
                        $file->getMimeType() );
        }
 
+       /**
+        * Calculate the largest thumbnail width for a given original file size
+        * such that the thumbnail's height is at most $maxHeight.
+        * @param $boxWidth Integer Width of the thumbnail box.
+        * @param $boxHeight Integer Height of the thumbnail box.
+        * @param $maxHeight Integer Maximum height expected for the thumbnail.
+        * @return Integer.
+        */
+       public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
+               $idealWidth = $boxWidth * $maxHeight / $boxHeight;
+               $roundedUp = ceil( $idealWidth );
+               if( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) {
+                       return floor( $idealWidth );
+               } else {
+                       return $roundedUp;
+               }
+       }
+
        function getDimensionsString( $file ) {
                return '';
        }
@@ -575,7 +593,7 @@ abstract class ImageHandler extends MediaHandler {
                        # Height & width were both set
                        if ( $params['width'] * $srcHeight > $params['height'] * $srcWidth ) {
                                # Height is the relative smaller dimension, so scale width accordingly
-                               $params['width'] = wfFitBoxWidth( $srcWidth, $srcHeight, $params['height'] );
+                               $params['width'] = self::fitBoxWidth( $srcWidth, $srcHeight, $params['height'] );
                                
                                if ( $params['width'] == 0 ) {
                                        # Very small image, so we need to rely on client side scaling :(