Fix SpecialUpload::unsaveUploadedFile(). Move UploadVerification hook so that it...
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 3 Jun 2007 11:23:53 +0000 (11:23 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 3 Jun 2007 11:23:53 +0000 (11:23 +0000)
includes/SpecialUpload.php
includes/filerepo/FSRepo.php

index 79ebef1..2ebd3fa 100644 (file)
@@ -368,17 +368,18 @@ class UploadForm {
                        if( $veri !== true ) { //it's a wiki error...
                                return $this->uploadError( $veri->toString() );
                        }
-               }
 
-               /**
-                * Provide an opportunity for extensions to add futher checks
-                */
-               $error = '';
-               if( !wfRunHooks( 'UploadVerification',
-                               array( $this->mUploadSaveName, $this->mUploadTempName, &$error ) ) ) {
-                       return $this->uploadError( $error );
+                       /**
+                        * Provide an opportunity for extensions to add futher checks
+                        */
+                       $error = '';
+                       if( !wfRunHooks( 'UploadVerification',
+                                       array( $this->mUploadSaveName, $this->mUploadTempName, &$error ) ) ) {
+                               return $this->uploadError( $error );
+                       }
                }
 
+
                /**
                 * Check for non-fatal conditions
                 */
@@ -602,9 +603,8 @@ class UploadForm {
         */
        function unsaveUploadedFile() {
                global $wgOut;
-               wfSuppressWarnings();
-               $success = unlink( $this->mUploadTempName );
-               wfRestoreWarnings();
+               $repo = RepoGroup::singleton()->getLocalRepo();
+               $success = $repo->freeTemp( $this->mUploadTempName );
                if ( ! $success ) {
                        $wgOut->showFileDeleteError( $this->mUploadTempName );
                        return false;
index 2c14e1b..c33df94 100644 (file)
@@ -236,6 +236,25 @@ class FSRepo {
                }
        }
 
+       /**
+        * Remove a temporary file or mark it for garbage collection
+        * @param string $virtualUrl The virtual URL returned by storeTemp
+        * @return boolean True on success, false on failure
+        */
+       function freeTemp( $virtualUrl ) {
+               $temp = 'mwrepo:///temp';
+               if ( substr( $virtualUrl, 0, strlen( $temp ) ) != $temp ) {
+                       wfDebug( __METHOD__.": Invalid virtual URL\n" );
+                       return false;
+               }
+               $path = $this->resolveVirtualUrl( $virtualUrl );
+               wfSuppressWarnings();
+               $success = unlink( $path );
+               wfRestoreWarnings();
+               return $success;
+       }
+
+
        /**
         * Copy or move a file either from the local filesystem or from an mwrepo://
         * virtual URL, into this repository at the specified destination location.