X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialUploadStash.php;h=8cdfb87f5315a0982ba368beff1ffecfac050897;hb=1dee28cb5f1efd6d9e14d6cc1d0c73c3f69269b4;hp=b0bb595e850548000157def8bb904dddc044e823;hpb=ea79f57eb0d9d614c08dd31cd4eeb50132182c10;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialUploadStash.php b/includes/specials/SpecialUploadStash.php index b0bb595e85..a00b031c9c 100644 --- a/includes/specials/SpecialUploadStash.php +++ b/includes/specials/SpecialUploadStash.php @@ -18,8 +18,6 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @ingroup SpecialPage - * @ingroup Upload */ /** @@ -31,6 +29,9 @@ * * 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 @@ -106,8 +107,7 @@ class SpecialUploadStash extends UnlistedSpecialPage { $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(); @@ -129,7 +129,9 @@ class SpecialUploadStash extends UnlistedSpecialPage { $type = strtok( $key, '/' ); if ( $type !== 'file' && $type !== 'thumb' ) { - throw new UploadStashBadPathException( "Unknown type '$type'" ); + throw new UploadStashBadPathException( + $this->msg( 'uploadstash-bad-path-unknown-type', $type ) + ); } $fileName = strtok( '/' ); $thumbPart = strtok( '/' ); @@ -137,7 +139,9 @@ class SpecialUploadStash extends UnlistedSpecialPage { if ( $type === 'thumb' ) { $srcNamePos = strrpos( $thumbPart, $fileName ); if ( $srcNamePos === false || $srcNamePos < 1 ) { - throw new UploadStashBadPathException( 'Unrecognized thumb name' ); + throw new UploadStashBadPathException( + $this->msg( 'uploadstash-bad-path-unrecognized-thumb-name' ) + ); } $paramString = substr( $thumbPart, 0, $srcNamePos - 1 ); @@ -147,8 +151,9 @@ class SpecialUploadStash extends UnlistedSpecialPage { 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( + $this->msg( 'uploadstash-bad-path-no-handler', $file->getMimeType(), $file->getPath() ) + ); } } @@ -194,12 +199,16 @@ class SpecialUploadStash extends UnlistedSpecialPage { $thumbnailImage = $file->transform( $params, $flags ); if ( !$thumbnailImage ) { - throw new MWException( 'Could not obtain thumbnail' ); + throw new UploadStashFileNotFoundException( + $this->msg( '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( + $this->msg( '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 @@ -207,7 +216,9 @@ class SpecialUploadStash extends UnlistedSpecialPage { $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( + $this->msg( 'uploadstash-file-not-found-no-object' ) + ); } return $this->outputLocalFile( $thumbFile ); @@ -261,13 +272,19 @@ class SpecialUploadStash extends UnlistedSpecialPage { $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( + $this->msg( + '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( + $this->msg( 'uploadstash-file-not-found-missing-content-type' ) + ); } return $this->outputContents( $req->getContent(), $contentType ); @@ -284,7 +301,9 @@ class SpecialUploadStash extends UnlistedSpecialPage { */ private function outputLocalFile( File $file ) { if ( $file->getSize() > self::MAX_SERVE_BYTES ) { - throw new SpecialUploadStashTooLargeException(); + throw new SpecialUploadStashTooLargeException( + $this->msg( 'uploadstash-file-too-large', self::MAX_SERVE_BYTES ) + ); } return $file->getRepo()->streamFile( $file->getPath(), @@ -296,7 +315,7 @@ class SpecialUploadStash extends UnlistedSpecialPage { /** * Output HTTP response of raw content * Side effect: writes HTTP response to STDOUT. - * @param string $content Content + * @param string $content * @param string $contentType MIME type * @throws SpecialUploadStashTooLargeException * @return bool @@ -304,7 +323,9 @@ class SpecialUploadStash extends UnlistedSpecialPage { private function outputContents( $content, $contentType ) { $size = strlen( $content ); if ( $size > self::MAX_SERVE_BYTES ) { - throw new SpecialUploadStashTooLargeException(); + throw new SpecialUploadStashTooLargeException( + $this->msg( 'uploadstash-file-too-large', self::MAX_SERVE_BYTES ) + ); } // Cancel output buffering and gzipping if set wfResetOutputBuffers(); @@ -427,5 +448,9 @@ class SpecialUploadStash extends UnlistedSpecialPage { } } -class SpecialUploadStashTooLargeException extends MWException { +/** + * @ingroup SpecialPage + * @ingroup Upload + */ +class SpecialUploadStashTooLargeException extends UploadStashException { }