56 $this->stash = $stash;
59 wfDebug( __METHOD__ .
" creating new UploadFromChunks instance for " .
$user->getId() .
"\n" );
61 wfDebug( __METHOD__ .
" creating new UploadFromChunks instance with no user\n" );
75 $this->mChunkIndex = 0;
80 $this->mLocalFile = parent::stashFile(
$user );
82 $this->mOffset = $this->mLocalFile->getSize();
83 $this->mFileKey = $this->mLocalFile->getFileKey();
102 $this->mFileKey =
$key;
103 $this->mUpload = $webRequestUpload;
107 $metadata = $this->stash->getMetadata(
$key );
110 $metadata[
'us_size'],
121 wfDebug( __METHOD__ .
" concatenate {$this->mChunkIndex} chunks:" .
122 $this->
getOffset() .
' inx:' . $chunkIndex .
"\n" );
127 for ( $i = 0; $i <= $chunkIndex; $i++ ) {
138 $tmpPath = $tmpFile->bind( $this )->getPath();
142 $tStart = microtime(
true );
144 $tAmount = microtime(
true ) - $tStart;
149 wfDebugLog(
'fileconcatenate',
"Combined $i chunks in $tAmount seconds." );
156 wfDebugLog(
'fileconcatenate',
"Verification failed for chunked upload" );
164 $tStart = microtime(
true );
165 $this->mLocalFile = parent::stashFile( $this->
user );
166 $tAmount = microtime(
true ) - $tStart;
167 $this->mLocalFile->setLocalReference( $tmpFile );
168 wfDebugLog(
'fileconcatenate',
"Stashed combined file ($i chunks) in $tAmount seconds." );
179 return $this->repo->getVirtualUrl(
'temp' ) .
181 $this->repo->getHashPath(
195 public function addChunk( $chunkPath, $chunkSize, $offset ) {
203 if ( $preAppendOffset == $offset ) {
205 $this->mChunkIndex++;
207 # For some reason mTempPath is set to first part
209 $this->mTempPath = $chunkPath;
211 $this->mTempPath = $oldTemp;
218 $this->mOffset = $preAppendOffset + $chunkSize;
234 wfDebug( __METHOD__ .
" update chunk status for {$this->mFileKey} offset:" .
237 $dbw = $this->repo->getMasterDB();
243 'us_status' =>
'chunks',
247 [
'us_key' => $this->mFileKey ],
250 $dbw->commit( __METHOD__,
'flush' );
259 $dbw = $this->repo->getMasterDB();
260 $row = $dbw->selectRow(
267 [
'us_key' => $this->mFileKey ],
272 $this->mChunkIndex = $row->us_chunk_inx;
273 $this->mOffset = $row->us_size;
274 $this->mVirtualTempPath = $row->us_path;
283 if ( $this->mChunkIndex !== null ) {
295 if ( $this->mOffset !== null ) {
314 $hashPath = $this->repo->getHashPath( $fileKey );
315 $storeStatus = $this->repo->quickImport( $chunkPath,
316 $this->repo->getZonePath(
'temp' ) .
"/{$hashPath}{$fileKey}" );
319 if ( !$storeStatus->isOK() ) {
320 $error = $storeStatus->getErrorsArray();
321 $error = reset( $error );
322 if ( !count( $error ) ) {
323 $error = $storeStatus->getWarningsArray();
324 $error = reset( $error );
325 if ( !count( $error ) ) {
326 $error = [
'unknown',
'no error recorded' ];
330 implode(
'; ', $error ) );
337 if ( $index === null ) {
341 return $this->mFileKey .
'.' . $index;
353 $this->mTitle =
false;
355 $this->mDesiredDestName = $oldDesiredDestName;
356 $this->mTitle =
false;
357 if ( is_array(
$res ) ) {
static factory($prefix, $extension= '')
Make a new temporary file on the file system.
getVerificationErrorCode($error)
__construct($user=null, $stash=false, $repo=false)
Setup local pointers to stash, repo and user (similar to UploadFromStash)
continueChunks($name, $key, $webRequestUpload)
Continue chunk uploading.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
getChunkIndex()
Get the current Chunk index.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
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
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 newFatal($message)
Factory function for fatal errors.
static extensionFromPath($path, $case= 'lowercase')
Get the final extension from a storage or FS path.
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.
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.
stashFile(User $user=null)
Calls the parent stashFile and updates the uploadsession table to handle "chunks".
Implements uploading from chunks.
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)
concatenateChunks()
Append the final chunk and ready file for parent::performUpload()
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.
Allows to change the fields on the form that will be generated $name