From db643f03c27ce035441cff3085083c2189abcbfa Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 7 Sep 2010 10:38:19 +0000 Subject: [PATCH] Fixes for r72024: * Renamed MediaHandler::verifyFileHook() to verifyUpload() since it isn't a hook and the fact that it operates on files is obvious. * Separated some concerns by simply passing verifyUpload() function a file path instead of an UploadBase object and MIME type. This simplifies the implementation of subclasses, makes the function accessible to non-UploadBase callers, and avoids breaking the interface constantly due to UploadBase changes. * Have verifyUpload() return a Status object instead of allowing the idiosyncratic and feature-poor error array convention from UploadBase to infect MediaHandler. The required update to PagedTiffHandler will be in a subsequent commit. --- includes/media/Generic.php | 19 +++++++++---------- includes/upload/UploadBase.php | 7 ++++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/includes/media/Generic.php b/includes/media/Generic.php index 4e91d50418..db3f4ce38b 100644 --- a/includes/media/Generic.php +++ b/includes/media/Generic.php @@ -274,18 +274,17 @@ 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. + * File validation hook called on upload. * - * @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 + * 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 verifyFileHook( $upload, $mime, &$error ) { - return true; + function verifyUpload( $fileName ) { + return Status::newGood(); } /** diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 3ed61bbd69..e09ac0ff04 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -373,9 +373,10 @@ abstract class UploadBase { $handler = MediaHandler::getHandler( $mime ); if ( $handler ) { - $handler->verifyFileHook( $this, $mime, $status ); - if ( $status !== true ) { - return $status; + $handlerStatus = $handler->verifyUpload( $this->mTempPath ); + if ( !$handlerStatus->isOK() ) { + $errors = $handlerStatus->getErrorsArray(); + return reset( $errors ); } } -- 2.20.1