Merge "Update documentation for log related classes"
[lhc/web/wiklou.git] / includes / media / ImageHandler.php
index d2bf1f3..eecef1d 100644 (file)
@@ -27,7 +27,6 @@
  * @ingroup Media
  */
 abstract class ImageHandler extends MediaHandler {
-
        /**
         * @param $file File
         * @return bool
@@ -60,6 +59,7 @@ abstract class ImageHandler extends MediaHandler {
                } else {
                        throw new MWException( 'No width specified to ' . __METHOD__ );
                }
+
                # Removed for ProofreadPage
                #$width = intval( $width );
                return "{$width}px";
@@ -92,7 +92,7 @@ abstract class ImageHandler extends MediaHandler {
 
                if ( !isset( $params['page'] ) ) {
                        $params['page'] = 1;
-               } else  {
+               } else {
                        if ( $params['page'] > $image->pageCount() ) {
                                $params['page'] = $image->pageCount();
                        }
@@ -140,9 +140,11 @@ abstract class ImageHandler extends MediaHandler {
                }
 
                if ( !$this->validateThumbParams( $params['physicalWidth'],
-                               $params['physicalHeight'], $srcWidth, $srcHeight, $mimeType ) ) {
+                       $params['physicalHeight'], $srcWidth, $srcHeight, $mimeType )
+               ) {
                        return false;
                }
+
                return true;
        }
 
@@ -160,12 +162,14 @@ abstract class ImageHandler extends MediaHandler {
                $width = intval( $width );
 
                # Sanity check $width
-               if( $width <= 0 ) {
+               if ( $width <= 0 ) {
                        wfDebug( __METHOD__ . ": Invalid destination width: $width\n" );
+
                        return false;
                }
                if ( $srcWidth <= 0 ) {
                        wfDebug( __METHOD__ . ": Invalid source width: $srcWidth\n" );
+
                        return false;
                }
 
@@ -174,6 +178,7 @@ abstract class ImageHandler extends MediaHandler {
                        # Force height to be at least 1 pixel
                        $height = 1;
                }
+
                return true;
        }
 
@@ -189,7 +194,7 @@ abstract class ImageHandler extends MediaHandler {
                }
                $url = wfAppendQuery( $script, $this->getScriptParams( $params ) );
 
-               if( $image->mustRender() || $params['width'] < $image->getWidth() ) {
+               if ( $image->mustRender() || $params['width'] < $image->getWidth() ) {
                        return new ThumbnailImage( $image, $url, false, $params );
                }
        }
@@ -198,9 +203,23 @@ abstract class ImageHandler extends MediaHandler {
                wfSuppressWarnings();
                $gis = getimagesize( $path );
                wfRestoreWarnings();
+
                return $gis;
        }
 
+       /**
+        * Function that returns the number of pixels to be thumbnailed.
+        * Intended for animated GIFs to multiply by the number of frames.
+        *
+        * If the file doesn't support a notion of "area" return 0.
+        *
+        * @param File $image
+        * @return int
+        */
+       function getImageArea( $image ) {
+               return $image->getWidth() * $image->getHeight();
+       }
+
        /**
         * @param $file File
         * @return string
@@ -208,7 +227,8 @@ abstract class ImageHandler extends MediaHandler {
        function getShortDesc( $file ) {
                global $wgLang;
                $nbytes = htmlspecialchars( $wgLang->formatSize( $file->getSize() ) );
-               $widthheight = wfMessage( 'widthheight' )->numParams( $file->getWidth(), $file->getHeight() )->escaped();
+               $widthheight = wfMessage( 'widthheight' )
+                       ->numParams( $file->getWidth(), $file->getHeight() )->escaped();
 
                return "$widthheight ($nbytes)";
        }
@@ -224,12 +244,13 @@ abstract class ImageHandler extends MediaHandler {
                if ( $pages === false || $pages <= 1 ) {
                        $msg = wfMessage( 'file-info-size' )->numParams( $file->getWidth(),
                                $file->getHeight() )->params( $size,
-                               $file->getMimeType() )->parse();
+                                       $file->getMimeType() )->parse();
                } else {
                        $msg = wfMessage( 'file-info-size-pages' )->numParams( $file->getWidth(),
                                $file->getHeight() )->params( $size,
-                               $file->getMimeType() )->numParams( $pages )->parse();
+                                       $file->getMimeType() )->numParams( $pages )->parse();
                }
+
                return $msg;
        }
 
@@ -240,9 +261,11 @@ abstract class ImageHandler extends MediaHandler {
        function getDimensionsString( $file ) {
                $pages = $file->pageCount();
                if ( $pages > 1 ) {
-                       return wfMessage( 'widthheightpage' )->numParams( $file->getWidth(), $file->getHeight(), $pages )->text();
+                       return wfMessage( 'widthheightpage' )
+                               ->numParams( $file->getWidth(), $file->getHeight(), $pages )->text();
                } else {
-                       return wfMessage( 'widthheight' )->numParams( $file->getWidth(), $file->getHeight() )->text();
+                       return wfMessage( 'widthheight' )
+                               ->numParams( $file->getWidth(), $file->getHeight() )->text();
                }
        }
 }