User:BDavis (WMF)/Notes/ApiUpload

What happens inside ApiUpload?
Pseudo code walkthrough from rev cd74d6228df8d93565929244c202a5682228ddeb

ApiUpload::execute

 * die( uploaddisabled ) unless UploadBase::isEnabled
 * toggle mParams['async'] off if not globally enabled
 * mParams['file'] = $_FILES['file']
 * mParams['chunk'] = $_FILES['chunk']
 * mParams['filekey'] = mParams['sessionkey'] unless mParams['filekey']
 * try
 * return unless self::selectUploadModule
 * die( nomodule ) unless isset( mUpload )
 * catch UploadStashException && die( stasherror )
 * die( mustbeloggedin | badaccess-groups ) unless mUpload->isAllowed
 * status = mUpload->fetchFile
 * die( status->errors[0] ) unless status->isGood
 * if mParams['chunk'] :
 * die( file-too-large ) if mParams['filesize'] > mUpload->getMaxUploadSize
 * die( internal-error ) unless mUpload->getTitle
 * self::verifyUpload unless ( mParams['async'] && mParams['filekey'] )
 * unless mParams['stash'] :
 * die(filename) unless mUpload->verifyTitlePermissions
 * try
 * cr = self::getContextResult
 * if cr['result'] === 'Success' :
 * cr['imageinfo'] = mUpload->getImageInfo
 * catch UploadStashException && die( stasherror )
 * getResult->addValue(cr)
 * mUpload->cleanupTempFile

ApiUpload::selectUploadModule

 * die( invalidparammix | missingparam ) unless ( mParams['chunk'] | mParams['filekey'] | mParams['file'] | mParams['url'] | mParams['statuskey'] )
 * if mParams['checkstatus'] : # check stash status
 * add progress message to result
 * return false
 * if mParams['statuskey'] : # check async upload status
 * sessionData = $_SESSION['wsUploadFromUrlJobData'][ mParams['statuskey'] ]
 * die( missingresult ) unless sessionData['result']
 * add sessionData to result
 * return false
 * die( missingparam ) unless mParams['filename']
 * if mParams['chunk'] :
 * mUpload = new UploadFromChunks
 * mParams['filekey'] ? mUpload->continueChunks : mUpload->initialize
 * if mParams['filekey'] :
 * die( invalid-file-key ) unless UploadFromStash::isValidKey
 * mUpload = new UploadFromStash
 * mUpload->initialize
 * if mParams['file'] :
 * mUpload = new UploadFromFile
 * mUpload->initialize
 * if mParams['url'] :
 * die( copyuploaddisabled ) unless UploadFromUrl::isEnabled
 * die( copyuploadbaddomain ) unless UploadFromUrl::isAllowedHost
 * die( copyuploadbadurl ) unless UploadFromUrl::isAllowedUrl
 * if mParams['asyncdownload'] :
 * die( asynccopyuploaddisabled ) unless $wgAllowAsyncCopyUploads
 * die( missing-ignorewarnings ) if mParams['leavemessage'] && !mParams['ignorewarnings']
 * mUpload = new UploadFromUrl
 * mUpload->initialize
 * return true

ApiUpload::verifyUpload

 * FIXME

ApiUpload::getContextResult
* FIXME