Go to the documentation of this file.
67 wfDebug( __METHOD__ .
" creating new UploadFromChunks instance for " .
$user->
getId() .
"\n" );
68 $this->stash =
new UploadStash( $this->repo, $this->user );
82 return parent::tryStashFile(
$user, $isPartial );
94 return parent::stashFile(
$user );
105 $this->mChunkIndex = 0;
109 $this->mStashFile = parent::doStashFile(
$user );
111 $this->mOffset = $this->mStashFile->getSize();
112 $this->mFileKey = $this->mStashFile->getFileKey();
115 $this->
outputChunk( $this->mStashFile->getPath() );
131 $this->mFileKey = $key;
132 $this->mUpload = $webRequestUpload;
136 $metadata = $this->stash->getMetadata( $key );
139 $metadata[
'us_size'],
150 wfDebug( __METHOD__ .
" concatenate {$this->mChunkIndex} chunks:" .
151 $this->
getOffset() .
' inx:' . $chunkIndex .
"\n" );
156 for ( $i = 0; $i <= $chunkIndex; $i++ ) {
163 $tmpFile = MediaWikiServices::getInstance()->getTempFSFileFactory()
164 ->newTempFSFile(
'chunkedupload_',
$ext );
168 $tmpPath = $tmpFile->bind( $this )->getPath();
172 $tStart = microtime(
true );
174 $tAmount = microtime(
true ) - $tStart;
175 if ( !$status->isOK() ) {
179 wfDebugLog(
'fileconcatenate',
"Combined $i chunks in $tAmount seconds." );
186 wfDebugLog(
'fileconcatenate',
"Verification failed for chunked upload" );
194 $tStart = microtime(
true );
199 $status->fatal( ...$error );
203 $this->mStashFile = parent::doStashFile( $this->user );
205 $status->fatal(
'uploadstash-exception', get_class( $e ), $e->getMessage() );
209 $tAmount = microtime(
true ) - $tStart;
210 $this->mStashFile->setLocalReference( $tmpFile );
211 wfDebugLog(
'fileconcatenate',
"Stashed combined file ($i chunks) in $tAmount seconds." );
222 return $this->repo->getVirtualUrl(
'temp' ) .
224 $this->repo->getHashPath(
238 public function addChunk( $chunkPath, $chunkSize, $offset ) {
246 if ( $preAppendOffset == $offset ) {
248 $this->mChunkIndex++;
250 # For some reason mTempPath is set to first part
252 $this->mTempPath = $chunkPath;
254 $this->mTempPath = $oldTemp;
259 if ( $status->isGood() ) {
261 $this->mOffset = $preAppendOffset + $chunkSize;
277 wfDebug( __METHOD__ .
" update chunk status for {$this->mFileKey} offset:" .
280 $dbw = $this->repo->getMasterDB();
284 'us_status' =>
'chunks',
288 [
'us_key' => $this->mFileKey ],
299 $dbw = $this->repo->getMasterDB();
300 $row = $dbw->selectRow(
307 [
'us_key' => $this->mFileKey ],
312 $this->mChunkIndex = $row->us_chunk_inx;
313 $this->mOffset = $row->us_size;
314 $this->mVirtualTempPath = $row->us_path;
323 if ( $this->mChunkIndex !==
null ) {
335 if ( $this->mOffset !==
null ) {
354 $hashPath = $this->repo->getHashPath( $fileKey );
355 $storeStatus = $this->repo->quickImport( $chunkPath,
356 $this->repo->getZonePath(
'temp' ) .
"/{$hashPath}{$fileKey}" );
359 if ( !$storeStatus->isOK() ) {
360 $error = $storeStatus->getErrorsArray();
361 $error = reset( $error );
362 if ( !count( $error ) ) {
363 $error = $storeStatus->getWarningsArray();
364 $error = reset( $error );
365 if ( !count( $error ) ) {
366 $error = [
'unknown',
'no error recorded' ];
370 implode(
'; ', $error ) );
377 if ( $index ===
null ) {
381 return $this->mFileKey .
'.' . $index;
393 $this->mTitle =
false;
395 $this->mDesiredDestName = $oldDesiredDestName;
396 $this->mTitle =
false;
397 if ( is_array(
$res ) ) {
updateChunkStatus()
Update the chunk db table with the current status:
static newFatal( $message,... $parameters)
Factory function for fatal errors.
getId()
Get the user's ID.
getOffset()
Get the offset at which the next uploaded chunk will be appended to.
getChunkIndex()
Get the current Chunk index.
outputChunk( $chunkPath)
Output the chunk to disk.
UploadStash is intended to accomplish a few things:
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
__construct(User $user, $stash=false, $repo=false)
@noinspection PhpMissingParentConstructorInspection
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
runUploadStashFileHook(User $user)
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getVerificationErrorCode( $error)
addChunk( $chunkPath, $chunkSize, $offset)
Add a chunk to the temporary directory.
setTempFile( $tempPath, $fileSize=null)
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
UploadStashFile $mStashFile
concatenateChunks()
Append the final chunk and ready file for parent::performUpload()
stashFile(User $user=null)
If the user does not supply all necessary information in the first upload form submission (either by ...
getChunkStatus()
Get the chunk db state and populate update relevant local values.
msg( $key, $fallback,... $params)
Get a message from i18n.
tryStashFile(User $user, $isPartial=false)
Like stashFile(), but respects extensions' wishes to prevent the stashing.verifyUpload() must be call...
getChunkFileKey( $index=null)
verifyPartialFile()
A verification routine suitable for partial files.
static getMaxUploadSize( $forType=null)
Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
Initialize the path information.
getVirtualChunkLocation( $index)
Returns the virtual chunk location:
doStashFile(User $user=null)
Calls the parent doStashFile and updates the uploadsession table to handle "chunks".
string $mTempPath
Local file system path to the file to upload (or a local copy)
continueChunks( $name, $key, $webRequestUpload)
Continue chunk uploading.
if(!is_readable( $file)) $ext
Implements uploading from chunks.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Implements regular file uploads.
A repository that stores files in the local filesystem and registers them in the wiki's own database.
string null $mDesiredDestName
verifyChunk()
Verify that the chunk isn't really an evil html file.