]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/media/Generic.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / media / Generic.php
index a9c681e1464e26938fe404632824956556924f81..fa4e731a3c5dd27ad88f89b7ea5b8fe318085726 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
  * Media-handling base classes and generic functionality
+ *
  * @file
  * @ingroup Media
  */
@@ -71,18 +72,19 @@ 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.
+        *   Warning, File::getPropsFromPath might pass an (object)array() instead (!)
+        * @param $path String: the filename
+        * @return String
         */
        function getMetadata( $image, $path ) { return ''; }
 
@@ -114,10 +116,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 );
@@ -127,11 +129,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 );
 
@@ -139,7 +141,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 );
        }
 
@@ -160,6 +162,10 @@ abstract class MediaHandler {
         * Page count for a multi-page document, false if unsupported or unknown
         */
        function pageCount( $file ) { return false; }
+       /**
+        * The material is vectorized and thus scaling is lossless
+        */
+       function isVectorized( $file ) { return false; }
        /**
         * False if the handler is disabled for all files
         */
@@ -179,6 +185,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:
         *
@@ -210,7 +224,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'.
@@ -227,8 +241,8 @@ abstract class MediaHandler {
 
        function getShortDesc( $file ) {
                global $wgLang;
-               $nbytes = '(' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
-                       $wgLang->formatNum( $file->getSize() ) ) . ')';
+               $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
+                       $wgLang->formatNum( $file->getSize() ) );
                return "$nbytes";
        }
 
@@ -242,8 +256,8 @@ abstract class MediaHandler {
        
        static function getGeneralShortDesc( $file ) {
                global $wgLang;
-               $nbytes = '(' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
-                       $wgLang->formatNum( $file->getSize() ) ) . ')';
+               $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
+                       $wgLang->formatNum( $file->getSize() ) );
                return "$nbytes";
        }
 
@@ -264,6 +278,20 @@ abstract class MediaHandler {
         */
        function parserTransformHook( $parser, $file ) {}
 
+       /**
+        * File validation hook called on upload.
+        *
+        * If the file at the given local path is not valid, or its MIME type does not 
+        * match the handler class, a Status object should be returned containing
+        * relevant errors.
+        * 
+        * @param $fileName The local path to the file.
+        * @return Status object
+        */
+       function verifyUpload( $fileName ) {
+               return Status::newGood();
+       }
+
        /**
         * Check for zero-sized thumbnails. These can be generated when
         * no disk space is available or some other error occurs
@@ -349,9 +377,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 ) {
@@ -376,8 +414,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 ) {
@@ -416,6 +457,10 @@ abstract class ImageHandler extends MediaHandler {
                return $gis;
        }
 
+       function isAnimatedImage( $image ) {
+               return false;
+       }
+
        function getShortDesc( $file ) {
                global $wgLang;
                $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),