The current API implementation has a parameter for uploads that is
called "ignorewarnings". Currently, it will not only suppress any
warnings from stopping the upload, it will also lose any data from
those warnings.
This patch is sort of on the way to solving Bug 30625, which is in
the UploadWizard extension. That extension needs to know when a file
upload *will* fail, barring a change in some data, in order to make
it easier for a user to fix the foreseeable problems. The solution is
either to fix it this way, or to somehow spoof a file upload, and see
if it succeeds. In the hopes that other extensions will also find
this useful, I opted for the former.
Change-Id: I08b4e29e89ade6cf391ae044fceb788aaba3f5b4
*/
private function getContextResult(){
$warnings = $this->getApiWarnings();
*/
private function getContextResult(){
$warnings = $this->getApiWarnings();
+ if ( $warnings && !$this->mParams['ignorewarnings'] ) {
// Get warnings formated in result array format
return $this->getWarningsResult( $warnings );
} elseif ( $this->mParams['chunk'] ) {
// Add chunk, and get result
// Get warnings formated in result array format
return $this->getWarningsResult( $warnings );
} elseif ( $this->mParams['chunk'] ) {
// Add chunk, and get result
- return $this->getChunkResult();
+ return $this->getChunkResult( $warnings );
} elseif ( $this->mParams['stash'] ) {
// Stash the file and get stash result
} elseif ( $this->mParams['stash'] ) {
// Stash the file and get stash result
- return $this->getStashResult();
+ 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
}
// 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();
+ return $this->performUpload( $warnings );
}
/**
* Get Stash Result, throws an expetion if the file could not be stashed.
* @return array
*/
}
/**
* Get Stash Result, throws an expetion if the file could not be stashed.
* @return array
*/
- private function getStashResult(){
+ private function getStashResult( $warnings ){
$result = array ();
// 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
$result = array ();
// 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
$result['result'] = 'Success';
$result['filekey'] = $this->performStash();
$result['sessionkey'] = $result['filekey']; // backwards compatibility
$result['result'] = 'Success';
$result['filekey'] = $this->performStash();
$result['sessionkey'] = $result['filekey']; // backwards compatibility
+ $result['warnings'] = $warnings;
} catch ( MWException $e ) {
$this->dieUsage( $e->getMessage(), 'stashfailed' );
}
} catch ( MWException $e ) {
$this->dieUsage( $e->getMessage(), 'stashfailed' );
}
* Get the result of a chunk upload.
* @return array
*/
* Get the result of a chunk upload.
* @return array
*/
- private function getChunkResult(){
+ private function getChunkResult( $warnings ){
$result = array();
$result['result'] = 'Continue';
$result = array();
$result['result'] = 'Continue';
+ $result['warnings'] = $warnings;
$request = $this->getMain()->getRequest();
$chunkPath = $request->getFileTempname( 'chunk' );
$chunkSize = $request->getUpload( 'chunk' )->getSize();
$request = $this->getMain()->getRequest();
$chunkPath = $request->getFileTempname( 'chunk' );
$chunkSize = $request->getUpload( 'chunk' )->getSize();
protected function getApiWarnings() {
$warnings = array();
protected function getApiWarnings() {
$warnings = array();
- if ( !$this->mParams['ignorewarnings'] ) {
- $warnings = $this->mUpload->checkWarnings();
- }
+ $warnings = $this->mUpload->checkWarnings();
+
return $this->transformWarnings( $warnings );
}
return $this->transformWarnings( $warnings );
}
- protected function performUpload() {
+ protected function performUpload( $warnings ) {
// Use comment as initial page text by default
if ( is_null( $this->mParams['text'] ) ) {
$this->mParams['text'] = $this->mParams['comment'];
// Use comment as initial page text by default
if ( is_null( $this->mParams['text'] ) ) {
$this->mParams['text'] = $this->mParams['comment'];
$result['result'] = 'Success';
$result['filename'] = $file->getName();
$result['result'] = 'Success';
$result['filename'] = $file->getName();
+ $result['warnings'] = $warnings;