interoduced new hoop in Uploadbase::verifyFile, as per comments to r71789
authorDaniel Kinzler <daniel@users.mediawiki.org>
Mon, 30 Aug 2010 12:10:02 +0000 (12:10 +0000)
committerDaniel Kinzler <daniel@users.mediawiki.org>
Mon, 30 Aug 2010 12:10:02 +0000 (12:10 +0000)
docs/hooks.txt
includes/upload/UploadBase.php

index d414145..f1bf512 100644 (file)
@@ -1671,7 +1671,8 @@ $descriptor: (array) the HTMLForm descriptor
 added to the descriptor
 $descriptor: (array) the HTMLForm descriptor
 
-'UploadVerification': additional chances to reject an uploaded file
+'UploadVerification': additional chances to reject an uploaded file. Consider 
+                      using UploadVerifyFile instead.
 string $saveName: destination file name
 string $tempName: filesystem path to the temporary file for checks
 string &$error: output: message key for message to show if upload canceled 
@@ -1679,6 +1680,16 @@ string &$error: output: message key for message to show if upload canceled
        is the message key and the remaining elements are used as parameters to
        the message.
 
+'UploadVerifyFile': extra file verification, based on mime type, etc. Preferred
+                    in most cases over UploadVerification.
+object $upload: an instance of UploadBase, with all info about the upload
+object $mime: the uploaded file's mime type, as detected by MediaWiki. Handlers 
+       will typically only apply for specific mime types.
+object &$error: output: true if the file is valid. Otherwise, and indexed array
+       representing the problem with the file, where the first element
+       is the message key and the remaining elements are used as parameters to
+       the message.
+
 'UploadComplete': Upon completion of a file upload
 $uploadBase: UploadBase (or subclass) object. File can be accessed by
        $uploadBase->getLocalFile().
index 1e23fbe..aa47e10 100644 (file)
@@ -371,6 +371,12 @@ abstract class UploadBase {
                if ( $virus ) {
                        return array( 'uploadvirus', $virus );
                }
+
+               wfRunHooks( 'UploadVerifyFile', array( $this, $mime, &$status ) );
+               if ( $status !== true ) {
+                       return $status;
+               }
+
                wfDebug( __METHOD__ . ": all clear; passing.\n" );
                return true;
        }