61 $this->repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
67 wfDebug( __METHOD__ .
" creating new UploadFromChunks instance for " .
$user->
getId() );
68 $this->stash =
new UploadStash( $this->repo, $this->user );
79 return Status::newFatal( $e->
msg );
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 );
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 ) {
243 $status = Status::newFatal(
'file-too-large' );
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;
256 return Status::newFatal( $e->
msg );
259 if ( $status->isGood() ) {
261 $this->mOffset = $preAppendOffset + $chunkSize;
266 $status = Status::newFatal(
'invalid-chunk-offset' );
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 ) ) {
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
A repository that stores files in the local filesystem and registers them in the wiki's own database.
msg( $key, $fallback,... $params)
Get a message from i18n.
UploadStashFile null $mStashFile
string $mTempPath
Local file system path to the file to upload (or a local copy)
runUploadStashFileHook(User $user)
verifyPartialFile()
A verification routine suitable for partial files.
getVerificationErrorCode( $error)
string null $mDesiredDestName
setTempFile( $tempPath, $fileSize=null)
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
static getMaxUploadSize( $forType=null)
Get MediaWiki's maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
Implements uploading from chunks.
addChunk( $chunkPath, $chunkSize, $offset)
Add a chunk to the temporary directory.
outputChunk( $chunkPath)
Output the chunk to disk.
doStashFile(User $user=null)
Calls the parent doStashFile and updates the uploadsession table to handle "chunks".
getChunkFileKey( $index=null)
stashFile(User $user=null)
If the user does not supply all necessary information in the first upload form submission (either by ...
continueChunks( $name, $key, $webRequestUpload)
Continue chunk uploading.
tryStashFile(User $user, $isPartial=false)
Like stashFile(), but respects extensions' wishes to prevent the stashing.verifyUpload() must be call...
getVirtualChunkLocation( $index)
Returns the virtual chunk location:
__construct(User $user, $stash=false, $repo=false)
@noinspection PhpMissingParentConstructorInspection
getOffset()
Get the offset at which the next uploaded chunk will be appended to.
updateChunkStatus()
Update the chunk db table with the current status:
getChunkStatus()
Get the chunk db state and populate update relevant local values.
concatenateChunks()
Append the final chunk and ready file for parent::performUpload()
verifyChunk()
Verify that the chunk isn't really an evil html file.
getChunkIndex()
Get the current Chunk index.
Implements regular file uploads.
UploadStash is intended to accomplish a few things:
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getId()
Get the user's ID.
if(!is_readable( $file)) $ext