55 $this->stash = $stash;
58 wfDebug( __METHOD__ .
" creating new UploadFromChunks instance for " . $user->
getId() .
"\n" );
60 wfDebug( __METHOD__ .
" creating new UploadFromChunks instance with no user\n" );
74 $this->mChunkIndex = 0;
79 $this->mStashFile = parent::doStashFile(
$user );
81 $this->mOffset = $this->mStashFile->getSize();
82 $this->mFileKey = $this->mStashFile->getFileKey();
101 $this->mFileKey = $key;
102 $this->mUpload = $webRequestUpload;
106 $metadata = $this->stash->getMetadata( $key );
109 $metadata[
'us_size'],
120 wfDebug( __METHOD__ .
" concatenate {$this->mChunkIndex} chunks:" .
121 $this->
getOffset() .
' inx:' . $chunkIndex .
"\n" );
126 for ( $i = 0; $i <= $chunkIndex; $i++ ) {
137 $tmpPath = $tmpFile->bind( $this )->getPath();
141 $tStart = microtime(
true );
143 $tAmount = microtime(
true ) - $tStart;
148 wfDebugLog(
'fileconcatenate',
"Combined $i chunks in $tAmount seconds." );
155 wfDebugLog(
'fileconcatenate',
"Verification failed for chunked upload" );
163 $tStart = microtime(
true );
168 call_user_func_array( [
$status,
'fatal' ], $error );
172 $this->mStashFile = parent::doStashFile( $this->
user );
174 $status->fatal(
'uploadstash-exception', get_class( $e ), $e->getMessage() );
178 $tAmount = microtime(
true ) - $tStart;
179 $this->mStashFile->setLocalReference( $tmpFile );
180 wfDebugLog(
'fileconcatenate',
"Stashed combined file ($i chunks) in $tAmount seconds." );
191 return $this->repo->getVirtualUrl(
'temp' ) .
193 $this->repo->getHashPath(
207 public function addChunk( $chunkPath, $chunkSize, $offset ) {
215 if ( $preAppendOffset == $offset ) {
217 $this->mChunkIndex++;
219 # For some reason mTempPath is set to first part
221 $this->mTempPath = $chunkPath;
223 $this->mTempPath = $oldTemp;
230 $this->mOffset = $preAppendOffset + $chunkSize;
246 wfDebug( __METHOD__ .
" update chunk status for {$this->mFileKey} offset:" .
249 $dbw = $this->repo->getMasterDB();
253 'us_status' =>
'chunks',
257 [
'us_key' => $this->mFileKey ],
268 $dbw = $this->repo->getMasterDB();
269 $row = $dbw->selectRow(
276 [
'us_key' => $this->mFileKey ],
281 $this->mChunkIndex = $row->us_chunk_inx;
282 $this->mOffset = $row->us_size;
283 $this->mVirtualTempPath = $row->us_path;
292 if ( $this->mChunkIndex !== null ) {
304 if ( $this->mOffset !== null ) {
323 $hashPath = $this->repo->getHashPath( $fileKey );
324 $storeStatus = $this->repo->quickImport( $chunkPath,
325 $this->repo->getZonePath(
'temp' ) .
"/{$hashPath}{$fileKey}" );
328 if ( !$storeStatus->isOK() ) {
329 $error = $storeStatus->getErrorsArray();
330 $error = reset( $error );
331 if ( !count( $error ) ) {
332 $error = $storeStatus->getWarningsArray();
333 $error = reset( $error );
334 if ( !count( $error ) ) {
335 $error = [
'unknown',
'no error recorded' ];
339 implode(
'; ', $error ) );
346 if ( $index === null ) {
350 return $this->mFileKey .
'.' . $index;
362 $this->mTitle =
false;
364 $this->mDesiredDestName = $oldDesiredDestName;
365 $this->mTitle =
false;
366 if ( is_array(
$res ) ) {
getVerificationErrorCode($error)
continueChunks($name, $key, $webRequestUpload)
Continue chunk uploading.
getChunkIndex()
Get the current Chunk index.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
static newFatal($message)
Factory function for fatal errors.
string $mTempPath
Local file system path to the file to upload (or a local copy)
updateChunkStatus()
Update the chunk db table with the current status:
static extensionFromPath($path, $case= 'lowercase')
Get the final extension from a storage or FS path.
static factory($prefix, $extension= '', $tmpDirectory=null)
Make a new temporary file on the file system.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getOffset()
Get the offset at which the next uploaded chunk will be appended to.
static getMaxUploadSize($forType=null)
Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
setTempFile($tempPath, $fileSize=null)
verifyPartialFile()
A verification routine suitable for partial files.
addChunk($chunkPath, $chunkSize, $offset)
Add a chunk to the temporary directory.
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
Implements regular file uploads.
wfTempDir()
Tries to get the system directory for temporary files.
static singleton()
Get a RepoGroup instance.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
Implements uploading from chunks.
__construct(User $user, $stash=false, $repo=false)
Setup local pointers to stash, repo and user (similar to UploadFromStash)
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
verifyChunk()
Verify that the chunk isn't really an evil html file.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
UploadStash is intended to accomplish a few things:
getChunkFileKey($index=null)
getId()
Get the user's ID.
concatenateChunks()
Append the final chunk and ready file for parent::performUpload()
doStashFile(User $user=null)
Calls the parent doStashFile and updates the uploadsession table to handle "chunks".
getVirtualChunkLocation($index)
Returns the virtual chunk location:
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
getChunkStatus()
Get the chunk db state and populate update relevant local values.
outputChunk($chunkPath)
Output the chunk to disk.
initializePathInfo($name, $tempPath, $fileSize, $removeTempFile=false)
Initialize the path information.
runUploadStashFileHook(User $user)
Allows to change the fields on the form that will be generated $name