Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / includes / specials / SpecialUploadStash.php
index b0bb595..c8b1578 100644 (file)
@@ -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(
+                               wfMessage( '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(
+                                       wfMessage( '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(
+                                       wfMessage( '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(
+                               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
@@ -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(
+                               wfMessage( '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(
+                               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 );
@@ -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(
+                               wfMessage( '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(
+                               wfMessage( '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 {
 }