Fixes for r72024:
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 7 Sep 2010 10:38:19 +0000 (10:38 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 7 Sep 2010 10:38:19 +0000 (10:38 +0000)
* 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
includes/upload/UploadBase.php

index 4e91d50..db3f4ce 100644 (file)
@@ -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();
        }
 
        /**
index 3ed61bb..e09ac0f 100644 (file)
@@ -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 );
                        }
                }