<?php
/**
- *
- *
- * Created on Aug 21, 2008
- *
* Copyright © 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
*
* This program is free software; you can redistribute it and/or modify
$this->checkPermissions( $user );
// Fetch the file (usually a no-op)
- /** @var $status Status */
+ /** @var Status $status */
$status = $this->mUpload->fetchFile();
if ( !$status->isGood() ) {
$this->dieStatus( $status );
if ( $status->isGood() && !$status->getValue() ) {
// Not actually a 'good' status...
- $status->fatal( new ApiRawMessage( 'Invalid stashed file', 'stashfailed' ) );
+ $status->fatal( new ApiMessage( 'apierror-stashinvalidfile', 'stashfailed' ) );
}
} catch ( Exception $e ) {
$debugMessage = 'Stashing temporary file failed: ' . get_class( $e ) . ' ' . $e->getMessage();
wfDebug( __METHOD__ . ' ' . $debugMessage . "\n" );
- $status = Status::newFatal( new ApiRawMessage( $e->getMessage(), 'stashfailed' ) );
+ $status = Status::newFatal( $this->getErrorFormatter()->getMessageFromException(
+ $e, [ 'wrap' => new ApiMessage( 'apierror-stashexception', 'stashfailed' ) ]
+ ) );
}
if ( $status->isGood() ) {
$this->mParams['filekey'], $this->mParams['filename'], !$this->mParams['async']
);
} elseif ( isset( $this->mParams['file'] ) ) {
+ // Can't async upload directly from a POSTed file, we'd have to
+ // stash the file and then queue the publish job. The user should
+ // just submit the two API queries to perform those two steps.
+ if ( $this->mParams['async'] ) {
+ $this->dieWithError( 'apierror-cannot-async-upload-file' );
+ }
+
$this->mUpload = new UploadFromFile();
$this->mUpload->initialize(
$this->mParams['filename'],
* @param array $verification
*/
protected function checkVerification( array $verification ) {
- // @todo Move them to ApiBase's message map
switch ( $verification['status'] ) {
// Recoverable errors
case UploadBase::MIN_LENGTH_PARTNAME:
break;
case UploadBase::HOOK_ABORTED:
- $this->dieWithError( $params, 'hookaborted', [ 'details' => $verification['error'] ] );
+ $msg = $verification['error'] === '' ? 'hookaborted' : $verification['error'];
+ $this->dieWithError( $msg, 'hookaborted', [ 'details' => $verification['error'] ] );
break;
default:
$this->dieWithError( 'apierror-unknownerror-nocode', 'unknown-error',
/**
* Handles a stash exception, giving a useful error to the user.
- * @todo Internationalize the exceptions
+ * @todo Internationalize the exceptions then get rid of this
* @param Exception $e
* @return StatusValue
*/
protected function handleStashException( $e ) {
- $err = wfEscapeWikiText( $e->getMessage() );
- switch ( get_class( $exception ) ) {
- case 'UploadStashFileNotFoundException':
- return StatusValue::newFatal( 'apierror-stashedfilenotfound', $err );
- case 'UploadStashBadPathException':
- return StatusValue::newFatal( 'apierror-stashpathinvalid', $err );
- case 'UploadStashFileException':
- return StatusValue::newFatal( 'apierror-stashfilestorage', $err );
- case 'UploadStashZeroLengthFileException':
- return StatusValue::newFatal( 'apierror-stashzerolength', $err );
- case 'UploadStashNotLoggedInException':
+ switch ( get_class( $e ) ) {
+ case UploadStashFileNotFoundException::class:
+ $wrap = 'apierror-stashedfilenotfound';
+ break;
+ case UploadStashBadPathException::class:
+ $wrap = 'apierror-stashpathinvalid';
+ break;
+ case UploadStashFileException::class:
+ $wrap = 'apierror-stashfilestorage';
+ break;
+ case UploadStashZeroLengthFileException::class:
+ $wrap = 'apierror-stashzerolength';
+ break;
+ case UploadStashNotLoggedInException::class:
return StatusValue::newFatal( ApiMessage::create(
[ 'apierror-mustbeloggedin', $this->msg( 'action-upload' ) ], 'stashnotloggedin'
) );
- case 'UploadStashWrongOwnerException':
- return StatusValue::newFatal( 'apierror-stashwrongowner', $err );
- case 'UploadStashNoSuchKeyException':
- return StatusValue::newFatal( 'apierror-stashnosuchfilekey', $err );
+ case UploadStashWrongOwnerException::class:
+ $wrap = 'apierror-stashwrongowner';
+ break;
+ case UploadStashNoSuchKeyException::class:
+ $wrap = 'apierror-stashnosuchfilekey';
+ break;
default:
- return StatusValue::newFatal( 'uploadstash-exception', get_class( $e ), $err );
+ $wrap = [ 'uploadstash-exception', get_class( $e ) ];
+ break;
}
+ return StatusValue::newFatal(
+ $this->getErrorFormatter()->getMessageFromException( $e, [ 'wrap' => $wrap ] )
+ );
}
/**
$this->mParams['text'] = $this->mParams['comment'];
}
- /** @var $file LocalFile */
+ /** @var LocalFile $file */
$file = $this->mUpload->getLocalFile();
// For preferences mode, we want to watch if 'watchdefault' is set,
$result['result'] = 'Poll';
$result['stage'] = 'queued';
} else {
- /** @var $status Status */
+ /** @var Status $status */
$status = $this->mUpload->performUpload( $this->mParams['comment'],
$this->mParams['text'], $watch, $this->getUser(), $this->mParams['tags'] );
}
public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:Upload';
+ return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Upload';
}
}