From 35e5762255b8cba9759a2db7e23dc2b785ff4444 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 3 Jun 2007 11:23:53 +0000 Subject: [PATCH] Fix SpecialUpload::unsaveUploadedFile(). Move UploadVerification hook so that it is only called as the file is uploaded, so that extensions don't die when fed an mwrepo:// URL. --- includes/SpecialUpload.php | 22 +++++++++++----------- includes/filerepo/FSRepo.php | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index 79ebef174d..2ebd3fa7ad 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -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; diff --git a/includes/filerepo/FSRepo.php b/includes/filerepo/FSRepo.php index 2c14e1bc22..c33df9464f 100644 --- a/includes/filerepo/FSRepo.php +++ b/includes/filerepo/FSRepo.php @@ -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. -- 2.20.1