* Standardised file description headers
[lhc/web/wiklou.git] / includes / media / Generic.php
index 8da1b60..9dbd7e3 100644 (file)
@@ -1,13 +1,15 @@
 <?php
-
 /**
  * Media-handling base classes and generic functionality
+ *
+ * @file
+ * @ingroup Media
  */
 
 /**
  * Base media handler class
  *
- * @addtogroup Media
+ * @ingroup Media
  */
 abstract class MediaHandler {
        const TRANSFORM_LATER = 1;
@@ -70,18 +72,18 @@ abstract class MediaHandler {
         * Get an image size array like that returned by getimagesize(), or false if it
         * can't be determined.
         *
-        * @param Image $image The image object, or false if there isn't one
-        * @param string $fileName The filename
-        * @return array
+        * @param $image File: the image object, or false if there isn't one
+        * @param $path String: the filename
+        * @return Array
         */
        abstract function getImageSize( $image, $path );
 
        /**
         * Get handler-specific metadata which will be saved in the img_metadata field.
         *
-        * @param Image $image The image object, or false if there isn't one
-        * @param string $fileName The filename
-        * @return string
+        * @param $image File: the image object, or false if there isn't one
+        * @param $path String: the filename
+        * @return String
         */
        function getMetadata( $image, $path ) { return ''; }
 
@@ -113,10 +115,10 @@ abstract class MediaHandler {
         * Get a MediaTransformOutput object representing the transformed output. Does not
         * actually do the transform.
         *
-        * @param Image $image The image object
-        * @param string $dstPath Filesystem destination path
-        * @param string $dstUrl Destination URL to use in output HTML
-        * @param array $params Arbitrary set of parameters validated by $this->validateParam()
+        * @param $image File: the image object
+        * @param $dstPath String: filesystem destination path
+        * @param $dstUrl String: Destination URL to use in output HTML
+        * @param $params Array: Arbitrary set of parameters validated by $this->validateParam()
         */
        function getTransform( $image, $dstPath, $dstUrl, $params ) {
                return $this->doTransform( $image, $dstPath, $dstUrl, $params, self::TRANSFORM_LATER );
@@ -126,11 +128,11 @@ abstract class MediaHandler {
         * Get a MediaTransformOutput object representing the transformed output. Does the
         * transform unless $flags contains self::TRANSFORM_LATER.
         *
-        * @param Image $image The image object
-        * @param string $dstPath Filesystem destination path
-        * @param string $dstUrl Destination URL to use in output HTML
-        * @param array $params Arbitrary set of parameters validated by $this->validateParam()
-        * @param integer $flags A bitfield, may contain self::TRANSFORM_LATER
+        * @param $image File: the image object
+        * @param $dstPath String: filesystem destination path
+        * @param $dstUrl String: destination URL to use in output HTML
+        * @param $params Array: arbitrary set of parameters validated by $this->validateParam()
+        * @param $flags Integer: a bitfield, may contain self::TRANSFORM_LATER
         */
        abstract function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
 
@@ -138,7 +140,7 @@ abstract class MediaHandler {
         * Get the thumbnail extension and MIME type for a given source MIME type
         * @return array thumbnail extension and MIME type
         */
-       function getThumbType( $ext, $mime ) {
+       function getThumbType( $ext, $mime, $params = null ) {
                return array( $ext, $mime );
        }
 
@@ -178,6 +180,14 @@ abstract class MediaHandler {
                );
        }
 
+       /**
+        * Generic getter for text layer.
+        * Currently overloaded by PDF and DjVu handlers
+        */
+       function getPageText( $image, $page ) {
+               return false;
+       }
+
        /**
         * Get an array structure that looks like this:
         *
@@ -209,7 +219,7 @@ abstract class MediaHandler {
        }
 
        /**
-        * @fixme document this!
+        * @todo Fixme: document this!
         * 'value' thingy goes into a wikitext table; it used to be escaped but
         * that was incompatible with previous practice of customized display
         * with wikitext formatting via messages such as 'exif-model-value'.
@@ -234,7 +244,24 @@ abstract class MediaHandler {
        function getLongDesc( $file ) {
                global $wgUser;
                $sk = $wgUser->getSkin();
-               return wfMsg( 'file-info', $sk->formatSize( $file->getSize() ), $file->getMimeType() );
+               return wfMsgExt( 'file-info', 'parseinline',
+                       $sk->formatSize( $file->getSize() ),
+                       $file->getMimeType() );
+       }
+       
+       static function getGeneralShortDesc( $file ) {
+               global $wgLang;
+               $nbytes = '(' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
+                       $wgLang->formatNum( $file->getSize() ) ) . ')';
+               return "$nbytes";
+       }
+
+       static function getGeneralLongDesc( $file ) {
+               global $wgUser;
+               $sk = $wgUser->getSkin();
+               return wfMsgExt( 'file-info', 'parseinline',
+                       $sk->formatSize( $file->getSize() ),
+                       $file->getMimeType() );
        }
 
        function getDimensionsString( $file ) {
@@ -272,7 +299,7 @@ abstract class MediaHandler {
 /**
  * Media handler abstract base class for images
  *
- * @addtogroup Media
+ * @ingroup Media
  */
 abstract class ImageHandler extends MediaHandler {
        function canRender( $file ) {
@@ -331,9 +358,19 @@ abstract class ImageHandler extends MediaHandler {
                if ( !isset( $params['width'] ) ) {
                        return false;
                }
+
                if ( !isset( $params['page'] ) ) {
                        $params['page'] = 1;
+               } else  {
+                       if ( $params['page'] > $image->pageCount() ) {
+                               $params['page'] = $image->pageCount();
+                       }
+
+                       if ( $params['page'] < 1 ) {
+                               $params['page'] = 1;
+                       }
                }
+
                $srcWidth = $image->getWidth( $params['page'] );
                $srcHeight = $image->getHeight( $params['page'] );
                if ( isset( $params['height'] ) && $params['height'] != -1 ) {
@@ -358,8 +395,11 @@ abstract class ImageHandler extends MediaHandler {
        /**
         * Validate thumbnail parameters and fill in the correct height
         *
-        * @param integer &$width Specified width (input/output)
-        * @param integer &$height Height (output only)
+        * @param $width Integer: specified width (input/output)
+        * @param $height Integer: height (output only)
+        * @param $srcWidth Integer: width of the source image
+        * @param $srcHeight Integer: height of the source image
+        * @param $mimeType Unused
         * @return false to indicate that an error should be returned to the user.
         */
        function validateThumbParams( &$width, &$height, $srcWidth, $srcHeight, $mimeType ) {
@@ -398,6 +438,10 @@ abstract class ImageHandler extends MediaHandler {
                return $gis;
        }
 
+       function isAnimatedImage( $image ) {
+               return false;
+       }
+
        function getShortDesc( $file ) {
                global $wgLang;
                $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
@@ -409,8 +453,11 @@ abstract class ImageHandler extends MediaHandler {
 
        function getLongDesc( $file ) {
                global $wgLang;
-               return wfMsgHtml('file-info-size', $wgLang->formatNum( $file->getWidth() ), $wgLang->formatNum( $file->getHeight() ),
-                       $wgLang->formatSize( $file->getSize() ), $file->getMimeType() );
+               return wfMsgExt('file-info-size', 'parseinline',
+                       $wgLang->formatNum( $file->getWidth() ),
+                       $wgLang->formatNum( $file->getHeight() ),
+                       $wgLang->formatSize( $file->getSize() ),
+                       $file->getMimeType() );
        }
 
        function getDimensionsString( $file ) {