From 28d16923a19bba2e9da90fcc6e8f964c0d993b48 Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Tue, 31 Aug 2010 14:08:45 +0000 Subject: [PATCH] introducing Generic::verifyFileHook() to let media handlers do the verification on upload. triggered from UploadBase:verifyFile, like the UploadVerifyFile hook. --- includes/media/Generic.php | 15 +++++++++++++++ includes/upload/UploadBase.php | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/includes/media/Generic.php b/includes/media/Generic.php index 9dbd7e30db..4e91d50418 100644 --- a/includes/media/Generic.php +++ b/includes/media/Generic.php @@ -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 diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index ccd43ce0ea..b63185ab31 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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; -- 2.20.1