// Copy the session key to the file key, for backward compatibility.
if ( !$this->mParams['filekey'] && $this->mParams['sessionkey'] ) {
- $this->logFeatureUsage( 'action=upload&sessionkey' );
$this->mParams['filekey'] = $this->mParams['sessionkey'];
}
$data['invalidparameter'] = $parameter;
$parsed = $this->parseMsg( $error );
+ if ( isset( $parsed['data'] ) ) {
+ $data = array_merge( $data, $parsed['data'] );
+ }
+
$this->dieUsage( $parsed['info'], $parsed['code'], 0, $data );
}
// chunk or one and only one of the following parameters is needed
if ( !$this->mParams['chunk'] ) {
$this->requireOnlyOneParameter( $this->mParams,
- 'filekey', 'file', 'url', 'statuskey' );
+ 'filekey', 'file', 'url' );
}
// Status report for "upload to stash"/"upload from stash"
return false;
}
- if ( $this->mParams['statuskey'] ) {
- $this->checkAsyncDownloadEnabled();
-
- // Status request for an async upload
- $sessionData = UploadFromUrlJob::getSessionData( $this->mParams['statuskey'] );
- if ( !isset( $sessionData['result'] ) ) {
- $this->dieUsage( 'No result in session data', 'missingresult' );
- }
- if ( $sessionData['result'] == 'Warning' ) {
- $sessionData['warnings'] = $this->transformWarnings( $sessionData['warnings'] );
- $sessionData['sessionkey'] = $this->mParams['statuskey'];
- }
- $this->getResult()->addValue( null, $this->getModuleName(), $sessionData );
-
- return false;
- }
-
// The following modules all require the filename parameter to be set
if ( is_null( $this->mParams['filename'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'filename' ) );
$this->dieUsageMsg( 'copyuploadbadurl' );
}
- $async = false;
- if ( $this->mParams['asyncdownload'] ) {
- $this->checkAsyncDownloadEnabled();
-
- if ( $this->mParams['leavemessage'] && !$this->mParams['ignorewarnings'] ) {
- $this->dieUsage( 'Using leavemessage without ignorewarnings is not supported',
- 'missing-ignorewarnings' );
- }
-
- if ( $this->mParams['leavemessage'] ) {
- $async = 'async-leavemessage';
- } else {
- $async = 'async';
- }
- }
$this->mUpload = new UploadFromUrl;
$this->mUpload->initialize( $this->mParams['filename'],
- $this->mParams['url'], $async );
+ $this->mParams['url'] );
}
return true;
protected function transformWarnings( $warnings ) {
if ( $warnings ) {
// Add indices
- $result = $this->getResult();
ApiResult::setIndexedTagName( $warnings, 'warning' );
if ( isset( $warnings['duplicate'] ) ) {
// Deprecated parameters
if ( $this->mParams['watch'] ) {
- $this->logFeatureUsage( 'action=upload&watch' );
$watch = true;
}
+ if ( $this->mParams['tags'] ) {
+ $status = ChangeTags::canAddTagsAccompanyingChange( $this->mParams['tags'], $this->getUser() );
+ if ( !$status->isOK() ) {
+ $this->dieStatus( $status );
+ }
+ }
+
// No errors, no warnings: do the upload
if ( $this->mParams['async'] ) {
$progress = UploadBase::getSessionStatus( $this->getUser(), $this->mParams['filekey'] );
'filename' => $this->mParams['filename'],
'filekey' => $this->mParams['filekey'],
'comment' => $this->mParams['comment'],
+ 'tags' => $this->mParams['tags'],
'text' => $this->mParams['text'],
'watch' => $watch,
'session' => $this->getContext()->exportSession()
} else {
/** @var $status Status */
$status = $this->mUpload->performUpload( $this->mParams['comment'],
- $this->mParams['text'], $watch, $this->getUser() );
+ $this->mParams['text'], $watch, $this->getUser(), $this->mParams['tags'] );
if ( !$status->isGood() ) {
$error = $status->getErrorsArray();
-
- if ( count( $error ) == 1 && $error[0][0] == 'async' ) {
- // The upload can not be performed right now, because the user
- // requested so
- return array(
- 'result' => 'Queued',
- 'statuskey' => $error[0][1],
- );
- }
-
ApiResult::setIndexedTagName( $error, 'error' );
$this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
}
return $result;
}
- /**
- * Checks if asynchronous copy uploads are enabled and throws an error if they are not.
- */
- protected function checkAsyncDownloadEnabled() {
- if ( !$this->getConfig()->get( 'AllowAsyncCopyUploads' ) ) {
- $this->dieUsage( 'Asynchronous copy uploads disabled', 'asynccopyuploaddisabled' );
- }
- }
-
public function mustBePosted() {
return true;
}
'comment' => array(
ApiBase::PARAM_DFLT => ''
),
+ 'tags' => array(
+ ApiBase::PARAM_TYPE => 'tags',
+ ApiBase::PARAM_ISMULTI => true,
+ ),
'text' => array(
ApiBase::PARAM_TYPE => 'text',
),
),
'async' => false,
- 'asyncdownload' => false,
- 'leavemessage' => false,
- 'statuskey' => null,
'checkstatus' => false,
);