$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 {
+class SpecialUploadStashTooLargeException extends UploadStashException {
}
*/
public function getFile( $key, $noAuth = false ) {
if ( !preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
- throw new UploadStashBadPathException( "key '$key' is not in a proper format" );
+ throw new UploadStashBadPathException(
+ wfMessage( 'uploadstash-bad-path-bad-format', $key )
+ );
}
if ( !$noAuth && !$this->isLoggedIn ) {
- throw new UploadStashNotLoggedInException( __METHOD__ .
- ' No user is logged in, files must belong to users' );
+ throw new UploadStashNotLoggedInException(
+ wfMessage( 'uploadstash-not-logged-in' )
+ );
}
if ( !isset( $this->fileMetadata[$key] ) ) {
}
if ( !isset( $this->fileMetadata[$key] ) ) {
- throw new UploadStashFileNotFoundException( "key '$key' not found in stash" );
+ throw new UploadStashFileNotFoundException(
+ wfMessage( 'uploadstash-file-not-found', $key )
+ );
}
// create $this->files[$key]
if ( !$this->files[$key]->exists() ) {
wfDebug( __METHOD__ . " tried to get file at $key, but it doesn't exist\n" );
// @todo Is this not an UploadStashFileNotFoundException case?
- throw new UploadStashBadPathException( "path doesn't exist" );
+ throw new UploadStashBadPathException(
+ wfMessage( 'uploadstash-bad-path' )
+ );
}
if ( !$noAuth ) {
if ( $this->fileMetadata[$key]['us_user'] != $this->userId ) {
- throw new UploadStashWrongOwnerException( "This file ($key) doesn't "
- . "belong to the current user." );
+ throw new UploadStashWrongOwnerException(
+ wfMessage( 'uploadstash-wrong-owner', $key )
+ );
}
}
public function stashFile( $path, $sourceType = null ) {
if ( !is_file( $path ) ) {
wfDebug( __METHOD__ . " tried to stash file at '$path', but it doesn't exist\n" );
- throw new UploadStashBadPathException( "path doesn't exist" );
+ throw new UploadStashBadPathException(
+ wfMessage( 'uploadstash-bad-path' )
+ );
}
$mwProps = new MWFileProps( MimeMagic::singleton() );
$this->fileProps[$key] = $fileProps;
if ( !preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
- throw new UploadStashBadPathException( "key '$key' is not in a proper format" );
+ throw new UploadStashBadPathException(
+ wfMessage( 'uploadstash-bad-path-bad-format', $key )
+ );
}
wfDebug( __METHOD__ . " key for '$path': $key\n" );
// fetch the current user ID
if ( !$this->isLoggedIn ) {
- throw new UploadStashNotLoggedInException( __METHOD__
- . ' No user is logged in, files must belong to users' );
+ throw new UploadStashNotLoggedInException(
+ wfMessage( 'uploadstash-not-logged-in' )
+ );
}
// insert the file metadata into the db.
*/
public function clear() {
if ( !$this->isLoggedIn ) {
- throw new UploadStashNotLoggedInException( __METHOD__
- . ' No user is logged in, files must belong to users' );
+ throw new UploadStashNotLoggedInException(
+ wfMessage( 'uploadstash-not-logged-in' )
+ );
}
wfDebug( __METHOD__ . ' clearing all rows for user ' . $this->userId . "\n" );
*/
public function removeFile( $key ) {
if ( !$this->isLoggedIn ) {
- throw new UploadStashNotLoggedInException( __METHOD__
- . ' No user is logged in, files must belong to users' );
+ throw new UploadStashNotLoggedInException(
+ wfMessage( 'uploadstash-not-logged-in' )
+ );
}
$dbw = $this->repo->getMasterDB();
);
if ( !$row ) {
- throw new UploadStashNoSuchKeyException( "No such key ($key), cannot remove" );
+ throw new UploadStashNoSuchKeyException(
+ wfMessage( 'uploadstash-no-such-key', $key )
+ );
}
if ( $row->us_user != $this->userId ) {
- throw new UploadStashWrongOwnerException( "Can't delete: "
- . "the file ($key) doesn't belong to this user." );
+ throw new UploadStashWrongOwnerException(
+ wfMessage( 'uploadstash-wrong-owner', $key )
+ );
}
return $this->removeFileNoAuth( $key );
*/
public function listFiles() {
if ( !$this->isLoggedIn ) {
- throw new UploadStashNotLoggedInException( __METHOD__
- . ' No user is logged in, files must belong to users' );
+ throw new UploadStashNotLoggedInException(
+ wfMessage( 'uploadstash-not-logged-in' )
+ );
}
$dbr = $this->repo->getReplicaDB();
}
if ( is_null( $extension ) ) {
- throw new UploadStashFileException( "extension is null" );
+ throw new UploadStashFileException(
+ wfMessage( 'uploadstash-no-extension' )
+ );
}
$extension = File::normalizeExtension( $extension );
protected function initFile( $key ) {
$file = new UploadStashFile( $this->repo, $this->fileMetadata[$key]['us_path'], $key );
if ( $file->getSize() === 0 ) {
- throw new UploadStashZeroLengthFileException( "File is zero length" );
+ throw new UploadStashZeroLengthFileException(
+ wfMessage( 'uploadstash-zero-length' )
+ );
}
$this->files[$key] = $file;
) {
wfDebug( "UploadStash: tried to construct an UploadStashFile "
. "from a file that should already exist at '$path', but path is not valid\n" );
- throw new UploadStashBadPathException( 'path is not valid' );
+ throw new UploadStashBadPathException(
+ wfMessage( 'uploadstash-bad-path-invalid' )
+ );
}
// check if path exists! and is a plain file.
if ( !$repo->fileExists( $path ) ) {
wfDebug( "UploadStash: tried to construct an UploadStashFile from "
. "a file that should already exist at '$path', but path is not found\n" );
- throw new UploadStashFileNotFoundException( 'cannot find path, or not a plain file' );
+ throw new UploadStashFileNotFoundException(
+ wfMessage( 'uploadstash-file-not-found-not-exists' )
+ );
}
}
"uploadstash-refresh": "Refresh the list of files",
"uploadstash-thumbnail": "view thumbnail",
"uploadstash-exception": "Could not store upload in the stash ($1): \"$2\".",
+ "uploadstash-bad-path": "Path doesn't exist.",
+ "uploadstash-bad-path-invalid": "Path is not valid.",
+ "uploadstash-bad-path-unknown-type": "Unknown type \"$1\".",
+ "uploadstash-bad-path-unrecognized-thumb-name": "Unrecognized thumb name.",
+ "uploadstash-bad-path-no-handler": "No handler found for mime $1 of file $2.",
+ "uploadstash-bad-path-bad-format": "Key \"$1\" is not in a proper format.",
+ "uploadstash-file-not-found": "Key \"$1\" not found in stash.",
+ "uploadstash-file-not-found-no-thumb": "Could not obtain thumbnail.",
+ "uploadstash-file-not-found-no-local-path": "No local path for scaled item.",
+ "uploadstash-file-not-found-no-object": "Couldn't create local file object for thumbnail.",
+ "uploadstash-file-not-found-no-remote-thumb": "Fetching thumbnail failed: $1\nurl = $2\n.",
+ "uploadstash-file-not-found-missing-content-type": "Missing content-type header.",
+ "uploadstash-file-not-found-not-exists": "Cannot find path, or not a plain file.",
+ "uploadstash-file-too-large": "Cannot serve a file larger than $1 bytes.",
+ "uploadstash-not-logged-in": "No user is logged in, files must belong to users.",
+ "uploadstash-wrong-owner": "This file ($1) doesn't belong to the current user.",
+ "uploadstash-no-such-key": "No such key ($1), cannot remove.",
+ "uploadstash-no-extension": "Extension is null.",
+ "uploadstash-zero-length": "File is zero length.",
"invalid-chunk-offset": "Invalid chunk offset",
"img-auth-accessdenied": "Access denied",
"img-auth-nopathinfo": "Missing PATH_INFO.\nYour server is not set up to pass this information.\nIt may be CGI-based and cannot support img_auth.\nSee https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Image_Authorization.",
"uploadstash-refresh": "Used as link text in [[Special:UploadStash]].",
"uploadstash-thumbnail": "Used as link text in [[Special:UploadStash]].",
"uploadstash-exception": "Error message shown when an action related to the upload stash fails unexpectedly.\n\nParameters:\n* $1 - exception name, e.g. 'UploadStashFileNotFoundException'\n* $2 - exceptions details (always in English), e.g. 'cannot find path, or not a plain file'",
+ "uploadstash-bad-path": "Error message when the upload stash path doesn't exist.",
+ "uploadstash-bad-path-invalid": "Error message when the upload stash path is invalid.",
+ "uploadstash-bad-path-unknown-type": "Error message when the upload stash key is of an invalid type.\n\nParameters:\n* $1 - the type",
+ "uploadstash-bad-path-unrecognized-thumb-name": "Error message when the upload stash key is of an unrecognized thumbnail",
+ "uploadstash-bad-path-no-handler": "Error message when no handler can be found for the given upload stash key.\n\nParameters:\n* $1 - the mine type\n* $2 - the file path",
+ "uploadstash-bad-path-bad-format": "Error message when the upload stash key if formatted incorrectly.\n\nParameters:\n* $1 - the stash key",
+ "uploadstash-file-not-found": "Error message when a stashed file can't be found.\n\nParameters:\n* $1 - the stash key",
+ "uploadstash-file-not-found-no-thumb": "Error message when no thumbnail could be generated.",
+ "uploadstash-file-not-found-no-local-path": "Error message when no locally generated thumbnail can be found.",
+ "uploadstash-file-not-found-no-object": "Error message when no local thumbnail object can be created.",
+ "uploadstash-file-not-found-no-remote-thumb": "Error message when a thumbnail could not be retrieved from a remote server.\n\nParameters:\n*1 - error details\n* $2 - remote url",
+ "uploadstash-file-not-found-missing-content-type": "Error message when a thumbnail from a remote server is missing the content-type header.",
+ "uploadstash-file-not-found-not-exists": "Error message when a stashed file doesn't exist.",
+ "uploadstash-file-too-large": "Error message when a too large thumbnail is requested.\n\nParameters:\n* $1 - The maximum amount of bytes",
+ "uploadstash-not-logged-in": "Error message when a logged out user tries to access a stashed upload.",
+ "uploadstash-wrong-owner": "Error message when a wrong user tries to access a stashed upload.\n\nParameters:\n* $1 - the stash key",
+ "uploadstash-no-such-key": "Error message when a stash key couldn't be found.\n\nParameters:\n* $1 - the stash key",
+ "uploadstash-no-extension": "Error message when a stashed file has no extension.",
+ "uploadstash-zero-length": "Error message when a file has no length (file size is zero).",
"invalid-chunk-offset": "Error that can happen if chunks get uploaded out of order.\nAs a result of this error, clients can continue from an offset provided or restart the upload.\nUsed on [[Special:UploadWizard]].",
"img-auth-accessdenied": "[[mw:Manual:Image Authorization|Manual:Image Authorization]]: Access Denied\n{{Identical|Access denied}}",
"img-auth-nopathinfo": "[[mw:Manual:Image Authorization|Manual:Image Authorization]]: Missing PATH_INFO - see english description\n{{Doc-important|This is plain text. Do not use any wiki syntax.}}",