* http://www.gnu.org/copyleft/gpl.html
*
* @file
- * @ingroup SpecialPage
- * @ingroup Upload
*/
/**
*
* Since this is based on the user's session, in effect this creates a private temporary file area.
* However, the URLs for the files cannot be shared.
+ *
+ * @ingroup SpecialPage
+ * @ingroup Upload
*/
class SpecialUploadStash extends UnlistedSpecialPage {
// UploadStash
$message = $e->getMessage();
} catch ( SpecialUploadStashTooLargeException $e ) {
$code = 500;
- $message = 'Cannot serve a file larger than ' . self::MAX_SERVE_BYTES .
- ' bytes. ' . $e->getMessage();
+ $message = $e->getMessage();
} catch ( Exception $e ) {
$code = 500;
$message = $e->getMessage();
$type = strtok( $key, '/' );
if ( $type !== 'file' && $type !== 'thumb' ) {
- throw new UploadStashBadPathException( "Unknown type '$type'" );
+ throw new UploadStashBadPathException(
+ wfMessage( 'uploadstash-bad-path-unknown-type', $type )
+ );
}
$fileName = strtok( '/' );
$thumbPart = strtok( '/' );
if ( $type === 'thumb' ) {
$srcNamePos = strrpos( $thumbPart, $fileName );
if ( $srcNamePos === false || $srcNamePos < 1 ) {
- throw new UploadStashBadPathException( 'Unrecognized thumb name' );
+ throw new UploadStashBadPathException(
+ wfMessage( 'uploadstash-bad-path-unrecognized-thumb-name' )
+ );
}
$paramString = substr( $thumbPart, 0, $srcNamePos - 1 );
return [ 'file' => $file, 'type' => $type, 'params' => $params ];
} else {
- throw new UploadStashBadPathException( 'No handler found for ' .
- "mime {$file->getMimeType()} of file {$file->getPath()}" );
+ throw new UploadStashBadPathException(
+ wfMessage( 'uploadstash-bad-path-no-handler', $file->getMimeType(), $file->getPath() )
+ );
}
}
$thumbnailImage = $file->transform( $params, $flags );
if ( !$thumbnailImage ) {
- throw new MWException( 'Could not obtain thumbnail' );
+ throw new UploadStashFileNotFoundException(
+ wfMessage( 'uploadstash-file-not-found-no-thumb' )
+ );
}
// we should have just generated it locally
if ( !$thumbnailImage->getStoragePath() ) {
- throw new UploadStashFileNotFoundException( "no local path for scaled item" );
+ throw new UploadStashFileNotFoundException(
+ wfMessage( 'uploadstash-file-not-found-no-local-path' )
+ );
}
// now we should construct a File, so we can get MIME and other such info in a standard way
$thumbFile = new UnregisteredLocalFile( false,
$this->stash->repo, $thumbnailImage->getStoragePath(), false );
if ( !$thumbFile ) {
- throw new UploadStashFileNotFoundException( "couldn't create local file object for thumbnail" );
+ throw new UploadStashFileNotFoundException(
+ wfMessage( 'uploadstash-file-not-found-no-object' )
+ );
}
return $this->outputLocalFile( $thumbFile );
$status = $req->execute();
if ( !$status->isOK() ) {
$errors = $status->getErrorsArray();
- $errorStr = "Fetching thumbnail failed: " . print_r( $errors, 1 );
- $errorStr .= "\nurl = $scalerThumbUrl\n";
- throw new MWException( $errorStr );
+ throw new UploadStashFileNotFoundException(
+ wfMessage(
+ 'uploadstash-file-not-found-no-remote-thumb',
+ print_r( $errors, 1 ),
+ $scalerThumbUrl
+ )
+ );
}
$contentType = $req->getResponseHeader( "content-type" );
if ( !$contentType ) {
- throw new MWException( "Missing content-type header" );
+ throw new UploadStashFileNotFoundException(
+ wfMessage( 'uploadstash-file-not-found-missing-content-type' )
+ );
}
return $this->outputContents( $req->getContent(), $contentType );
*/
private function outputLocalFile( File $file ) {
if ( $file->getSize() > self::MAX_SERVE_BYTES ) {
- throw new SpecialUploadStashTooLargeException();
+ throw new SpecialUploadStashTooLargeException(
+ wfMessage( 'uploadstash-file-too-large', self::MAX_SERVE_BYTES )
+ );
}
return $file->getRepo()->streamFile( $file->getPath(),
private function outputContents( $content, $contentType ) {
$size = strlen( $content );
if ( $size > self::MAX_SERVE_BYTES ) {
- throw new SpecialUploadStashTooLargeException();
+ throw new SpecialUploadStashTooLargeException(
+ wfMessage( 'uploadstash-file-too-large', self::MAX_SERVE_BYTES )
+ );
}
// Cancel output buffering and gzipping if set
wfResetOutputBuffers();
}
}
-class SpecialUploadStashTooLargeException extends MWException {
+/**
+ * @ingroup SpecialPage
+ * @ingroup Upload
+ */
+class SpecialUploadStashTooLargeException extends UploadStashException {
}