* @ingroup API
*/
class ApiUpload extends ApiBase {
-
- /**
- * @var UploadBase
- */
+ /** @var UploadBase */
protected $mUpload = null;
protected $mParams;
} elseif ( $this->mParams['async'] && $this->mParams['filekey'] ) {
// defer verification to background process
} else {
- wfDebug( __METHOD__ . 'about to verify' );
+ wfDebug( __METHOD__ . " about to verify\n" );
$this->verifyUpload();
}
array( 'result' => 'Poll',
'stage' => 'queued', 'status' => Status::newGood() )
);
- $ok = JobQueueGroup::singleton()->push( new AssembleUploadChunksJob(
+ JobQueueGroup::singleton()->push( new AssembleUploadChunksJob(
Title::makeTitle( NS_FILE, $filekey ),
array(
'filename' => $this->mParams['filename'],
'session' => $this->getContext()->exportSession()
)
) );
- if ( $ok ) {
- $result['result'] = 'Poll';
- } else {
- UploadBase::setSessionStatus( $filekey, false );
- $this->dieUsage(
- "Failed to start AssembleUploadChunks.php", 'stashfailed' );
- }
+ $result['result'] = 'Poll';
} else {
$status = $this->mUpload->concatenateChunks();
if ( !$status->isGood() ) {
* Stash the file and return the file key
* Also re-raises exceptions with slightly more informative message strings (useful for API)
* @throws MWException
- * @return String file key
+ * @return string File key
*/
private function performStash() {
try {
/**
* Checks that the user has permissions to perform this upload.
* Dies with usage message on inadequate permissions.
- * @param $user User The user to check.
+ * @param User $user The user to check.
*/
protected function checkPermissions( $user ) {
// Check whether the user has the appropriate permissions to upload anyway
if ( $permission !== true ) {
if ( !$user->isLoggedIn() ) {
$this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
- } else {
- $this->dieUsageMsg( 'badaccess-groups' );
}
+
+ $this->dieUsageMsg( 'badaccess-groups' );
}
}
if ( isset( $warnings['exists'] ) ) {
$warning = $warnings['exists'];
unset( $warnings['exists'] );
- $localFile = isset( $warning['normalizedFile'] ) ? $warning['normalizedFile'] : $warning['file'];
+ $localFile = isset( $warning['normalizedFile'] )
+ ? $warning['normalizedFile']
+ : $warning['file'];
$warnings[$warning['warning']] = $localFile->getName();
}
}
$this->mParams['filekey'],
array( 'result' => 'Poll', 'stage' => 'queued', 'status' => Status::newGood() )
);
- $ok = JobQueueGroup::singleton()->push( new PublishStashedFileJob(
+ JobQueueGroup::singleton()->push( new PublishStashedFileJob(
Title::makeTitle( NS_FILE, $this->mParams['filename'] ),
array(
'filename' => $this->mParams['filename'],
'session' => $this->getContext()->exportSession()
)
) );
- if ( $ok ) {
- $result['result'] = 'Poll';
- } else {
- UploadBase::setSessionStatus( $this->mParams['filekey'], false );
- $this->dieUsage(
- "Failed to start PublishStashedFile.php", 'publishfailed' );
- }
+ $result['result'] = 'Poll';
} else {
/** @var $status Status */
$status = $this->mUpload->performUpload( $this->mParams['comment'],
'result' => 'Queued',
'statuskey' => $error[0][1],
);
- } else {
- $this->getResult()->setIndexedTagName( $error, 'error' );
-
- $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
}
+
+ $this->getResult()->setIndexedTagName( $error, 'error' );
+ $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
}
$result['result'] = 'Success';
}
$params = array(
'filename' => 'Target filename',
'token' => 'Edit token. You can get one of these through prop=info',
- 'comment' => 'Upload comment. Also used as the initial page text for new files if "text" is not specified',
+ 'comment' => 'Upload comment. Also used as the initial page text for new ' .
+ 'files if "text" is not specified',
'text' => 'Initial page text for new files',
'watch' => 'Watch the page',
- 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
+ 'watchlist' => 'Unconditionally add or remove the page from your watchlist, ' .
+ 'use preferences or do not change watch',
'ignorewarnings' => 'Ignore any warnings',
'file' => 'File contents',
'url' => 'URL to fetch the file from',
'filekey' => 'Key that identifies a previous upload that was stashed temporarily.',
'sessionkey' => 'Same as filekey, maintained for backward compatibility.',
- 'stash' => 'If set, the server will not add the file to the repository and stash it temporarily.',
+ 'stash' => 'If set, the server will not add the file to the repository ' .
+ 'and stash it temporarily.',
'chunk' => 'Chunk contents',
'offset' => 'Offset of chunk in bytes',
' * Have the MediaWiki server fetch a file from a URL, using the "url" parameter',
' * Complete an earlier upload that failed due to warnings, using the "filekey" parameter',
'Note that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when',
- 'sending the "file". Also you must get and send an edit token before doing any upload stuff'
+ 'sending the "file". Also you must get and send an edit token before doing any upload stuff.'
);
}
public function getExamples() {
return array(
- 'api.php?action=upload&filename=Wiki.png&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'
+ 'api.php?action=upload&filename=Wiki.png' .
+ '&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'
=> 'Upload from a URL',
'api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1'
=> 'Complete an upload that failed due to warnings',