Index: branches/FileBackend/phase3/includes/filerepo/file/TempFSFile.php |
— | — | @@ -16,6 +16,29 @@ |
17 | 17 | protected $canDelete = true; // garbage collect the temp file |
18 | 18 | |
19 | 19 | /** |
| 20 | + * Make a new temporary file on the file system |
| 21 | + * |
| 22 | + * @param $prefix string |
| 23 | + * @param $extension string |
| 24 | + * @return TempFSFile|null |
| 25 | + */ |
| 26 | + public static function factory( $prefix, $extension = '' ) { |
| 27 | + $tmpDest = tempnam( wfTempDir(), $prefix ); |
| 28 | + if ( $tmpDest === false ) { |
| 29 | + return null; |
| 30 | + } |
| 31 | + if ( $extension != '' ) { |
| 32 | + $path = "{$tmpDest}.{$extension}"; |
| 33 | + if ( !rename( $tmpDest, $path ) ) { |
| 34 | + return null; |
| 35 | + } |
| 36 | + } else { |
| 37 | + $path = $tmpDest; |
| 38 | + } |
| 39 | + return new self( $path ); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
20 | 43 | * Flag to not clean up after the temporary file |
21 | 44 | * |
22 | 45 | * @return void |
Index: branches/FileBackend/phase3/includes/media/Generic.php |
— | — | @@ -205,24 +205,25 @@ |
206 | 206 | */ |
207 | 207 | final function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { |
208 | 208 | if ( FileBackend::isStoragePath( $dstPath ) ) { |
209 | | - // Create output on FS |
210 | | - $tmpDest = tempnam( wfTempDir(), 'transform' ) . '.' . $image->getExtension(); |
211 | | - if ( $tmpDest === false ) { |
212 | | - throw new MWException( "Could not create temporary thumbnail file." ); |
| 209 | + // Create a temp FS file with the same extension |
| 210 | + $tmpFile = TempFSFile::factory( 'transform', $image->getExtension() ); |
| 211 | + if ( !$tmpFile ) { |
| 212 | + return new MediaTransformError( 'thumbnail_error', |
| 213 | + $params['width'], 0, wfMsg( 'thumbnail-temp-create' ) ); |
213 | 214 | } |
| 215 | + $tmpDest = $tmpFile->getPath(); |
| 216 | + // Create the output thumbnail on the FS |
214 | 217 | $out = $this->doFSTransform( $image, $tmpDest, $dstUrl, $params, $flags ); |
215 | | - // Copy any thumbnail from FS $tmpDest to $dstpath. |
| 218 | + // Copy any thumbnail from FS into storage at $dstpath |
216 | 219 | // Note: no file is created if it's to be rendered client-side. |
217 | 220 | if ( !$out->isError() && is_file( $tmpDest ) ) { |
218 | 221 | $op = array( 'op' => 'store', |
219 | 222 | 'source' => $tmpDest, 'dest' => $dstPath, 'overwriteDest' => true ); |
220 | 223 | if ( !$image->getRepo()->getBackend()->doOperation( $op )->isOK() ) { |
221 | | - throw new MWException( "Could not copy thumbnail to $dstPath." ); |
| 224 | + return new MediaTransformError( 'thumbnail_error', |
| 225 | + $params['width'], 0, wfMsg( 'thumbnail-dest-create' ) ); |
222 | 226 | } |
223 | 227 | } |
224 | | - wfSuppressWarnings(); |
225 | | - unlink( $tmpDest ); |
226 | | - wfRestoreWarnings(); |
227 | 228 | } else { |
228 | 229 | $out = $this->doFSTransform( $image, $dstPath, $dstUrl, $params, $flags ); |
229 | 230 | } |
Index: branches/FileBackend/phase3/languages/messages/MessagesEn.php |
— | — | @@ -3311,6 +3311,8 @@ |
3312 | 3312 | 'thumbnail_error' => 'Error creating thumbnail: $1', |
3313 | 3313 | 'djvu_page_error' => 'DjVu page out of range', |
3314 | 3314 | 'djvu_no_xml' => 'Unable to fetch XML for DjVu file', |
| 3315 | +'thumbnail-temp-create' => 'Unable to create temporary thumbnail file', |
| 3316 | +'thumbnail-dest-create' => 'Unable to save thumbnail to destination', |
3315 | 3317 | 'thumbnail_invalid_params' => 'Invalid thumbnail parameters', |
3316 | 3318 | 'thumbnail_dest_directory' => 'Unable to create destination directory', |
3317 | 3319 | 'thumbnail_image-type' => 'Image type not supported', |
Property changes on: branches/FileBackend/phase3 |
___________________________________________________________________ |
Modified: svn:ignore |
3318 | 3320 | - *~ |
.classpath |
.idea |
.metadata* |
.project |
.settings |
AdminSettings.php |
LocalSettings.php |
StartProfiler.php |
cscope.files |
cscope.out |
favicon.ico |
nbproject* |
project.index |
static* |
tags |
3319 | 3321 | + *~ |
.classpath |
.idea |
.metadata* |
.project |
.settings |
AdminSettings.php |
LocalSettings.php |
StartProfiler.php |
cscope.files |
cscope.out |
favicon.ico |
nbproject* |
project.index |
static* |
tags |
.jpg |
.png |