// Stash the file and get stash result
return $this->getStashResult( $warnings );
}
+
// This is the most common case -- a normal upload with no warnings
// performUpload will return a formatted properly for the API with status
return $this->performUpload( $warnings );
} catch ( MWException $e ) {
$this->dieUsage( $e->getMessage(), 'stashfailed' );
}
+
return $result;
}
} catch ( MWException $e ) {
$result['warnings']['stashfailed'] = $e->getMessage();
}
+
return $result;
}
$chunkPath, $chunkSize, $this->mParams['offset'] );
if ( !$status->isGood() ) {
$this->dieUsage( $status->getWikiText(), 'stashfailed' );
+
return array();
}
}
$status = $this->mUpload->concatenateChunks();
if ( !$status->isGood() ) {
$this->dieUsage( $status->getWikiText(), 'stashfailed' );
+
return array();
}
}
$result['filekey'] = $filekey;
$result['offset'] = $this->mParams['offset'] + $chunkSize;
+
return $result;
}
wfDebug( __METHOD__ . ' ' . $message . "\n" );
throw new MWException( $message );
}
+
return $fileKey;
}
}
unset( $progress['status'] ); // remove Status object
$this->getResult()->addValue( null, $this->getModuleName(), $progress );
+
return false;
}
$sessionData['sessionkey'] = $this->mParams['statuskey'];
}
$this->getResult()->addValue( null, $this->getModuleName(), $sessionData );
+
return false;
}
if ( $permission !== true ) {
if ( !$user->isLoggedIn() ) {
$this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
- } else {
- $this->dieUsageMsg( 'badaccess-groups' );
}
+
+ $this->dieUsageMsg( 'badaccess-groups' );
}
}
break;
case UploadBase::ILLEGAL_FILENAME:
$this->dieRecoverableError( 'illegal-filename', 'filename',
- array( 'filename' => $verification['filtered'] ) );
+ array( 'filename' => $verification['filtered'] ) );
break;
case UploadBase::FILENAME_TOO_LONG:
$this->dieRecoverableError( 'filename-toolong', 'filename' );
case UploadBase::VERIFICATION_ERROR:
$this->getResult()->setIndexedTagName( $verification['details'], 'detail' );
$this->dieUsage( 'This file did not pass file verification', 'verification-error',
- 0, array( 'details' => $verification['details'] ) );
+ 0, array( 'details' => $verification['details'] ) );
break;
case UploadBase::HOOK_ABORTED:
$this->dieUsage( "The modification you tried to make was aborted by an extension hook",
- 'hookaborted', 0, array( 'error' => $verification['error'] ) );
+ 'hookaborted', 0, array( 'error' => $verification['error'] ) );
break;
default:
$this->dieUsage( 'An unknown error occurred', 'unknown-error',
- 0, array( 'code' => $verification['status'] ) );
+ 0, array( 'code' => $verification['status'] ) );
break;
}
}
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();
}
}
+
return $warnings;
}
/** @var $file File */
$file = $this->mUpload->getLocalFile();
- $watch = $this->getWatchlistValue( $this->mParams['watchlist'], $file->getTitle() );
+
+ // 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.
+ $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'
+ );
+ }
// Deprecated parameters
if ( $this->mParams['watch'] ) {
'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',
);
return $params;
-
}
public function getResultProperties() {
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',