r72525 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72524‎ | r72525 | r72526 >
Date:10:38, 7 September 2010
Author:tstarling
Status:ok
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/media/Generic.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -373,9 +373,10 @@
374374
375375 $handler = MediaHandler::getHandler( $mime );
376376 if ( $handler ) {
377 - $handler->verifyFileHook( $this, $mime, $status );
378 - if ( $status !== true ) {
379 - return $status;
 377+ $handlerStatus = $handler->verifyUpload( $this->mTempPath );
 378+ if ( !$handlerStatus->isOK() ) {
 379+ $errors = $handlerStatus->getErrorsArray();
 380+ return reset( $errors );
380381 }
381382 }
382383
Index: trunk/phase3/includes/media/Generic.php
@@ -274,18 +274,17 @@
275275 function parserTransformHook( $parser, $file ) {}
276276
277277 /**
278 - * File validation hook; Called by UploadBase::verifyFile, exactly like UploadVerifyFile hooks.
279 - * If the file represented by the $upload object is not valid, $error should be set to an array
280 - * in which the first item is the name of a system message describing the problem, and any
281 - * remaining items are parameters for that message. In that case, verifyFileHook should return false.
 278+ * File validation hook called on upload.
282279 *
283 - * @param $upload An instance of UploadBase, representing a freshly uploaded file
284 - * @param $mime The mime type of the uploaded file
285 - * @param $error (output) set to an array describing the problem, if there is one. If the file is OK, this should not be modified.
286 - * @return true if the file is OK, false otherwise
 280+ * If the file at the given local path is not valid, or its MIME type does not
 281+ * match the handler class, a Status object should be returned containing
 282+ * relevant errors.
 283+ *
 284+ * @param $fileName The local path to the file.
 285+ * @return Status object
287286 */
288 - function verifyFileHook( $upload, $mime, &$error ) {
289 - return true;
 287+ function verifyUpload( $fileName ) {
 288+ return Status::newGood();
290289 }
291290
292291 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r72526* PagedTiffHandler update for core change r72525, fixes r72025....tstarling10:43, 7 September 2010
r72893MFT r71942, r72024, r72120, r72525: supporting changes for PagedTiffHandler f...tstarling07:18, 13 September 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r72024introducing Generic::verifyFileHook() to let media handlers do the verificati...daniel14:08, 31 August 2010

Status & tagging log