* @return array
*/
private function getStashResult( $warnings ) {
- $result = array();
+ $result = [];
// Some uploads can request they be stashed, so as not to publish them immediately.
// In this case, a failure to stash ought to be fatal
try {
* @return array
*/
private function getWarningsResult( $warnings ) {
- $result = array();
+ $result = [];
$result['result'] = 'Warning';
$result['warnings'] = $warnings;
// in case the warnings can be fixed with some further user action, let's stash this upload
* @return array
*/
private function getChunkResult( $warnings ) {
- $result = array();
+ $result = [];
if ( $warnings && count( $warnings ) > 0 ) {
$result['warnings'] = $warnings;
$status = $this->mUpload->addChunk(
$chunkPath, $chunkSize, $this->mParams['offset'] );
if ( !$status->isGood() ) {
- $extradata = array(
+ $extradata = [
'offset' => $this->mUpload->getOffset(),
- );
+ ];
- $this->dieUsage( $status->getWikiText(), 'stashfailed', 0, $extradata );
+ $this->dieUsage( $status->getWikiText( false, false, 'en' ), 'stashfailed', 0, $extradata );
}
}
UploadBase::setSessionStatus(
$this->getUser(),
$filekey,
- array( 'result' => 'Poll',
- 'stage' => 'queued', 'status' => Status::newGood() )
+ [ 'result' => 'Poll',
+ 'stage' => 'queued', 'status' => Status::newGood() ]
);
JobQueueGroup::singleton()->push( new AssembleUploadChunksJob(
Title::makeTitle( NS_FILE, $filekey ),
- array(
+ [
'filename' => $this->mParams['filename'],
'filekey' => $filekey,
'session' => $this->getContext()->exportSession()
- )
+ ]
) );
$result['result'] = 'Poll';
$result['stage'] = 'queued';
UploadBase::setSessionStatus(
$this->getUser(),
$filekey,
- array( 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status )
+ [ 'result' => 'Failure', 'stage' => 'assembling', 'status' => $status ]
);
- $this->dieUsage( $status->getWikiText(), 'stashfailed' );
+ $this->dieUsage( $status->getWikiText( false, false, 'en' ), 'stashfailed' );
}
// The fully concatenated file has a new filekey. So remove
UploadBase::setSessionStatus(
$this->getUser(),
$filekey,
- array(
+ [
'result' => 'Continue',
'stage' => 'uploading',
'offset' => $totalSoFar,
'status' => Status::newGood(),
- )
+ ]
);
$result['result'] = 'Continue';
$result['offset'] = $totalSoFar;
* @param array $data Optional extra data to pass to the user
* @throws UsageException
*/
- private function dieRecoverableError( $error, $parameter, $data = array() ) {
+ private function dieRecoverableError( $error, $parameter, $data = [] ) {
try {
$data['filekey'] = $this->performStash();
$data['sessionkey'] = $data['filekey'];
if ( !$progress ) {
$this->dieUsage( 'No result in status data', 'missingresult' );
} elseif ( !$progress['status']->isGood() ) {
- $this->dieUsage( $progress['status']->getWikiText(), 'stashfailed' );
+ $this->dieUsage( $progress['status']->getWikiText( false, false, 'en' ), 'stashfailed' );
}
if ( isset( $progress['status']->value['verification'] ) ) {
$this->checkVerification( $progress['status']->value['verification'] );
// The following modules all require the filename parameter to be set
if ( is_null( $this->mParams['filename'] ) ) {
- $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
+ $this->dieUsageMsg( [ 'missingparam', 'filename' ] );
}
if ( $this->mParams['chunk'] ) {
if ( $permission !== true ) {
if ( !$user->isLoggedIn() ) {
- $this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
+ $this->dieUsageMsg( [ 'mustbeloggedin', 'upload' ] );
}
$this->dieUsageMsg( 'badaccess-groups' );
break;
case UploadBase::ILLEGAL_FILENAME:
$this->dieRecoverableError( 'illegal-filename', 'filename',
- array( 'filename' => $verification['filtered'] ) );
+ [ 'filename' => $verification['filtered'] ] );
break;
case UploadBase::FILENAME_TOO_LONG:
$this->dieRecoverableError( 'filename-toolong', 'filename' );
break;
case UploadBase::FILETYPE_BADTYPE:
- $extradata = array(
+ $extradata = [
'filetype' => $verification['finalExt'],
'allowed' => array_values( array_unique( $this->getConfig()->get( 'FileExtensions' ) ) )
- );
+ ];
ApiResult::setIndexedTagName( $extradata['allowed'], 'ext' );
- $msg = "Filetype not permitted: ";
+ $msg = 'Filetype not permitted: ';
if ( isset( $verification['blacklistedExt'] ) ) {
- $msg .= join( ', ', $verification['blacklistedExt'] );
+ $msg .= implode( ', ', $verification['blacklistedExt'] );
$extradata['blacklisted'] = array_values( $verification['blacklistedExt'] );
ApiResult::setIndexedTagName( $extradata['blacklisted'], 'ext' );
} else {
$msg = $this->msg( $key, $params )->inLanguage( 'en' )->useDatabase( false )->text();
ApiResult::setIndexedTagName( $verification['details'], 'detail' );
$this->dieUsage( "This file did not pass file verification: $msg", 'verification-error',
- 0, array( 'details' => $verification['details'] ) );
+ 0, [ 'details' => $verification['details'] ] );
break;
case UploadBase::HOOK_ABORTED:
if ( is_array( $verification['error'] ) ) {
$params = $verification['error'];
} elseif ( $verification['error'] !== '' ) {
- $params = array( $verification['error'] );
+ $params = [ $verification['error'] ];
} else {
- $params = array( 'hookaborted' );
+ $params = [ 'hookaborted' ];
}
$key = array_shift( $params );
$msg = $this->msg( $key, $params )->inLanguage( 'en' )->useDatabase( false )->text();
- $this->dieUsage( $msg, 'hookaborted', 0, array( 'details' => $verification['error'] ) );
+ $this->dieUsage( $msg, 'hookaborted', 0, [ 'details' => $verification['error'] ] );
break;
default:
$this->dieUsage( 'An unknown error occurred', 'unknown-error',
- 0, array( 'details' => array( 'code' => $verification['status'] ) ) );
+ 0, [ 'details' => [ 'code' => $verification['status'] ] ] );
break;
}
}
ApiResult::setIndexedTagName( $warnings, 'warning' );
if ( isset( $warnings['duplicate'] ) ) {
- $dupes = array();
+ $dupes = [];
/** @var File $dupe */
foreach ( $warnings['duplicate'] as $dupe ) {
$dupes[] = $dupe->getName();
$this->dieUsage( 'No such filekey: ' . $e->getMessage(), 'stashnosuchfilekey' );
break;
default:
- $this->dieUsage( $exceptionType . ": " . $e->getMessage(), 'stasherror' );
+ $this->dieUsage( $exceptionType . ': ' . $e->getMessage(), 'stasherror' );
break;
}
}
/** @var $file File */
$file = $this->mUpload->getLocalFile();
- // For preferences mode, we want to watch if 'watchdefault' is set or
- // if the *file* doesn't exist and 'watchcreations' is set. But
- // getWatchlistValue()'s automatic handling checks if the *title*
- // exists or not, so we need to check both prefs manually.
+ // For preferences mode, we want to watch if 'watchdefault' is set,
+ // or if the *file* doesn't exist, and either 'watchuploads' or
+ // 'watchcreations' is set. But getWatchlistValue()'s automatic
+ // handling checks if the *title* exists or not, so we need to check
+ // all three preferences manually.
$watch = $this->getWatchlistValue(
$this->mParams['watchlist'], $file->getTitle(), 'watchdefault'
);
+
if ( !$watch && $this->mParams['watchlist'] == 'preferences' && !$file->exists() ) {
- $watch = $this->getWatchlistValue(
- $this->mParams['watchlist'], $file->getTitle(), 'watchcreations'
+ $watch = (
+ $this->getWatchlistValue( 'preferences', $file->getTitle(), 'watchuploads' ) ||
+ $this->getWatchlistValue( 'preferences', $file->getTitle(), 'watchcreations' )
);
}
$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'] );
if ( $progress && $progress['result'] === 'Poll' ) {
- $this->dieUsage( "Upload from stash already in progress.", 'publishfailed' );
+ $this->dieUsage( 'Upload from stash already in progress.', 'publishfailed' );
}
UploadBase::setSessionStatus(
$this->getUser(),
$this->mParams['filekey'],
- array( 'result' => 'Poll', 'stage' => 'queued', 'status' => Status::newGood() )
+ [ 'result' => 'Poll', 'stage' => 'queued', 'status' => Status::newGood() ]
);
JobQueueGroup::singleton()->push( new PublishStashedFileJob(
Title::makeTitle( NS_FILE, $this->mParams['filename'] ),
- array(
+ [
'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()
- )
+ ]
) );
$result['result'] = 'Poll';
$result['stage'] = 'queued';
} 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();
}
public function getAllowedParams() {
- $params = array(
- 'filename' => array(
+ $params = [
+ 'filename' => [
ApiBase::PARAM_TYPE => 'string',
- ),
- 'comment' => array(
+ ],
+ 'comment' => [
ApiBase::PARAM_DFLT => ''
- ),
- 'text' => array(
+ ],
+ 'tags' => [
+ ApiBase::PARAM_TYPE => 'tags',
+ ApiBase::PARAM_ISMULTI => true,
+ ],
+ 'text' => [
ApiBase::PARAM_TYPE => 'text',
- ),
- 'watch' => array(
+ ],
+ 'watch' => [
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
- ),
- 'watchlist' => array(
+ ],
+ 'watchlist' => [
ApiBase::PARAM_DFLT => 'preferences',
- ApiBase::PARAM_TYPE => array(
+ ApiBase::PARAM_TYPE => [
'watch',
'preferences',
'nochange'
- ),
- ),
+ ],
+ ],
'ignorewarnings' => false,
- 'file' => array(
+ 'file' => [
ApiBase::PARAM_TYPE => 'upload',
- ),
+ ],
'url' => null,
'filekey' => null,
- 'sessionkey' => array(
+ 'sessionkey' => [
ApiBase::PARAM_DEPRECATED => true,
- ),
+ ],
'stash' => false,
- 'filesize' => array(
+ 'filesize' => [
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MIN => 0,
ApiBase::PARAM_MAX => UploadBase::getMaxUploadSize(),
- ),
- 'offset' => array(
+ ],
+ 'offset' => [
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MIN => 0,
- ),
- 'chunk' => array(
+ ],
+ 'chunk' => [
ApiBase::PARAM_TYPE => 'upload',
- ),
+ ],
'async' => false,
'checkstatus' => false,
- );
+ ];
return $params;
}
}
protected function getExamplesMessages() {
- return array(
+ return [
'action=upload&filename=Wiki.png' .
'&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png&token=123ABC'
=> 'apihelp-upload-example-url',
'action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1&token=123ABC'
=> 'apihelp-upload-example-filekey',
- );
+ ];
}
public function getHelpUrls() {