* @author Michael Dale
*/
abstract class UploadBase {
+ /** @var string Local file system path to the file to upload (or a local copy) */
protected $mTempPath;
+ /** @var TempFSFile|null Wrapper to handle deleting the temp file */
+ protected $tempFileObj;
+
protected $mDesiredDestName, $mDestName, $mRemoveTempFile, $mSourceType;
protected $mTitle = false, $mTitleError = 0;
protected $mFilteredName, $mFinalExtension;
if ( FileBackend::isStoragePath( $tempPath ) ) {
throw new MWException( __METHOD__ . " given storage path `$tempPath`." );
}
- $this->mTempPath = $tempPath;
- $this->mFileSize = $fileSize;
+
+ $this->setTempFile( $tempPath, $fileSize );
$this->mRemoveTempFile = $removeTempFile;
}
*/
abstract public function initializeFromRequest( &$request );
+ /**
+ * @param string $tempPath File system path to temporary file containing the upload
+ * @param integer $fileSize
+ */
+ protected function setTempFile( $tempPath, $fileSize = null ) {
+ $this->mTempPath = $tempPath;
+ $this->mFileSize = $fileSize ?: null;
+ if ( strlen( $this->mTempPath ) && file_exists( $this->mTempPath ) ) {
+ $this->tempFileObj = new TempFSFile( $this->mTempPath );
+ if ( !$fileSize ) {
+ $this->mFileSize = filesize( $this->mTempPath );
+ }
+ } else {
+ $this->tempFileObj = null;
+ }
+ }
+
/**
* Fetch the file. Usually a no-op
* @return Status
if ( $this->mDesiredDestName != $filename && $comparableName != $filename ) {
$warnings['badfilename'] = $filename;
- // Debugging for bug 62241
- wfDebugLog( 'upload', "Filename: '$filename', mDesiredDestName: "
- . "'$this->mDesiredDestName', comparableName: '$comparableName'" );
}
// Check whether the file extension is on the unwanted list
}
if ( $this->mFileSize == 0 ) {
- $warnings['emptyfile'] = true;
+ $warnings['empty-file'] = true;
}
$exists = self::getExistsWarning( $localFile );
WatchAction::doWatch(
$this->getLocalFile()->getTitle(),
$user,
- WatchedItem::IGNORE_USER_RIGHTS
+ User::IGNORE_USER_RIGHTS
);
}
Hooks::run( 'UploadComplete', [ &$this ] );
* on exit to clean up.
*/
public function cleanupTempFile() {
- if ( $this->mRemoveTempFile && $this->mTempPath && file_exists( $this->mTempPath ) ) {
- wfDebug( __METHOD__ . ": Removing temporary file {$this->mTempPath}\n" );
- unlink( $this->mTempPath );
+ if ( $this->mRemoveTempFile && $this->tempFileObj ) {
+ // Delete when all relevant TempFSFile handles go out of scope
+ wfDebug( __METHOD__ . ": Marked temporary file '{$this->mTempPath}' for removal\n" );
+ $this->tempFileObj->autocollect();
}
}
&& strpos( $value, '#' ) !== 0
) {
if ( !( $strippedElement === 'a'
- && preg_match( '!^https?://!im', $value ) )
+ && preg_match( '!^https?://!i', $value ) )
) {
wfDebug( __METHOD__ . ": Found href attribute <$strippedElement "
. "'$attrib'='$value' in uploaded file.\n" );