* UploadBase and subclasses are the backend of MediaWiki's file uploads.
* The frontends are formed by ApiUpload and SpecialUpload.
*
- * See also includes/docs/upload.txt
- *
* @author Brion Vibber
* @author Bryan Tong Minh
* @author Michael Dale
/**
* @param string $srcPath the source path
- * @return string the real path if it was a virtual URL
+ * @return string|bool the real path if it was a virtual URL Returns false on failure
*/
function getRealPath( $srcPath ) {
wfProfileIn( __METHOD__ );
// @todo just make uploads work with storage paths
// UploadFromStash loads files via virtual URLs
$tmpFile = $repo->getLocalCopy( $srcPath );
- $tmpFile->bind( $this ); // keep alive with $this
- wfProfileOut( __METHOD__ );
- return $tmpFile->getPath();
+ if ( $tmpFile ) {
+ $tmpFile->bind( $this ); // keep alive with $this
+ }
+ $path = $tmpFile ? $tmpFile->getPath() : false;
+ } else {
+ $path = $srcPath;
}
wfProfileOut( __METHOD__ );
- return $srcPath;
+ return $path;
}
/**
$error = '';
if ( !wfRunHooks( 'UploadVerification',
- array( $this->mDestName, $this->mTempPath, &$error ) ) )
- {
+ array( $this->mDestName, $this->mTempPath, &$error ) )
+ ) {
wfProfileOut( __METHOD__ );
return array( 'status' => self::HOOK_ABORTED, 'error' => $error );
}
return true;
}
-
/**
* Verifies that it's ok to include the uploaded file
*
}
}
-
$handler = MediaHandler::getHandler( $mime );
if ( $handler ) {
$handlerStatus = $handler->verifyUpload( $this->mTempPath );
// Check dupes against archives
$archivedImage = new ArchivedFile( null, 0, "{$hash}.{$this->mFinalExtension}" );
if ( $archivedImage->getID() > 0 ) {
- $warnings['duplicate-archive'] = $archivedImage->getName();
+ if ( $archivedImage->userCan( File::DELETED_FILE ) ) {
+ $warnings['duplicate-archive'] = $archivedImage->getName();
+ } else {
+ $warnings['duplicate-archive'] = '';
+ }
}
wfProfileOut( __METHOD__ );
# exclamation mark, so restrict file name to 240 bytes.
if ( strlen( $this->mFilteredName ) > 240 ) {
$this->mTitleError = self::FILENAME_TOO_LONG;
- return $this->mTitle = null;
+ $this->mTitle = null;
+ return $this->mTitle;
}
/**
$nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName );
if ( is_null( $nt ) ) {
$this->mTitleError = self::ILLEGAL_FILENAME;
- return $this->mTitle = null;
+ $this->mTitle = null;
+ return $this->mTitle;
}
$this->mFilteredName = $nt->getDBkey();
if ( $this->mFinalExtension == '' ) {
$this->mTitleError = self::FILETYPE_MISSING;
- return $this->mTitle = null;
+ $this->mTitle = null;
+ return $this->mTitle;
} elseif ( $blackListedExtensions ||
( $wgCheckFileExtensions && $wgStrictFileExtensions &&
!$this->checkFileExtensionList( $ext, $wgFileExtensions ) ) ) {
$this->mBlackListedExtensions = $blackListedExtensions;
$this->mTitleError = self::FILETYPE_BADTYPE;
- return $this->mTitle = null;
+ $this->mTitle = null;
+ return $this->mTitle;
}
// Windows may be broken with special characters, see bug XXX
if ( wfIsWindows() && !preg_match( '/^[\x0-\x7f]*$/', $nt->getText() ) ) {
$this->mTitleError = self::WINDOWS_NONASCII_FILENAME;
- return $this->mTitle = null;
+ $this->mTitle = null;
+ return $this->mTitle;
}
# If there was more than one "extension", reassemble the base
if ( strlen( $partname ) < 1 ) {
$this->mTitleError = self::MIN_LENGTH_PARTNAME;
- return $this->mTitle = null;
+ $this->mTitle = null;
+ return $this->mTitle;
}
- return $this->mTitle = $nt;
+ $this->mTitle = $nt;
+ return $this->mTitle;
}
/**
return false;
}
-
/**
* Check a whitelist of xml encodings that are known not to be interpreted differently
* by the server's xml parser (expat) and some common browsers.