introducing Generic::verifyFileHook() to let media handlers do the verification on...
authorDaniel Kinzler <daniel@users.mediawiki.org>
Tue, 31 Aug 2010 14:08:45 +0000 (14:08 +0000)
committerDaniel Kinzler <daniel@users.mediawiki.org>
Tue, 31 Aug 2010 14:08:45 +0000 (14:08 +0000)
includes/media/Generic.php
includes/upload/UploadBase.php

index 9dbd7e3..4e91d50 100644 (file)
@@ -273,6 +273,21 @@ abstract class MediaHandler {
         */
        function parserTransformHook( $parser, $file ) {}
 
+       /**
+        * File validation hook; Called by UploadBase::verifyFile, exactly like UploadVerifyFile hooks.
+        * If the file represented by the $upload object is not valid, $error should be set to an array
+        * in which the first item is the name of a system message describing the problem, and any
+        * remaining items are parameters for that message. In that case, verifyFileHook should return false.
+        *
+        * @param $upload An instance of UploadBase, representing a freshly uploaded file
+        * @param $mime The mime type of the uploaded file
+        * @param $error (output) set to an array describing the problem, if there is one. If the file is OK, this should not be modified.
+        * @return true if the file is OK, false otherwise
+        */
+       function verifyFileHook( $upload, $mime, &$error ) {
+               return true;
+       }
+
        /**
         * Check for zero-sized thumbnails. These can be generated when
         * no disk space is available or some other error occurs
index ccd43ce..b63185a 100644 (file)
@@ -371,6 +371,14 @@ abstract class UploadBase {
                        return array( 'uploadvirus', $virus );
                }
 
+               $handler = MediaHandler::getHandler( $mime );
+               if ( $handler ) {
+                       $handler->verifyFileHook( $this, $mime, &$status );
+                       if ( $status !== true ) {
+                               return $status;
+                       }
+               }
+
                wfRunHooks( 'UploadVerifyFile', array( $this, $mime, &$status ) );
                if ( $status !== true ) {
                        return $status;