r104645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104644‎ | r104645 | r104646 >
Date:01:53, 30 November 2011
Author:aaron
Status:deferred
Tags:
Comment:
* doTranform() error handling cleanups
* Created TempFSFile::factory() function
Modified paths:
  • /branches/FileBackend/phase3 (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/file/TempFSFile.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/Generic.php (modified) (history)
  • /branches/FileBackend/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/includes/filerepo/file/TempFSFile.php
@@ -16,6 +16,29 @@
1717 protected $canDelete = true; // garbage collect the temp file
1818
1919 /**
 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+ /**
2043 * Flag to not clean up after the temporary file
2144 *
2245 * @return void
Index: branches/FileBackend/phase3/includes/media/Generic.php
@@ -205,24 +205,25 @@
206206 */
207207 final function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
208208 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' ) );
213214 }
 215+ $tmpDest = $tmpFile->getPath();
 216+ // Create the output thumbnail on the FS
214217 $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
216219 // Note: no file is created if it's to be rendered client-side.
217220 if ( !$out->isError() && is_file( $tmpDest ) ) {
218221 $op = array( 'op' => 'store',
219222 'source' => $tmpDest, 'dest' => $dstPath, 'overwriteDest' => true );
220223 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' ) );
222226 }
223227 }
224 - wfSuppressWarnings();
225 - unlink( $tmpDest );
226 - wfRestoreWarnings();
227228 } else {
228229 $out = $this->doFSTransform( $image, $dstPath, $dstUrl, $params, $flags );
229230 }
Index: branches/FileBackend/phase3/languages/messages/MessagesEn.php
@@ -3311,6 +3311,8 @@
33123312 'thumbnail_error' => 'Error creating thumbnail: $1',
33133313 'djvu_page_error' => 'DjVu page out of range',
33143314 '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',
33153317 'thumbnail_invalid_params' => 'Invalid thumbnail parameters',
33163318 'thumbnail_dest_directory' => 'Unable to create destination directory',
33173319 'thumbnail_image-type' => 'Image type not supported',
Property changes on: branches/FileBackend/phase3
___________________________________________________________________
Modified: svn:ignore
33183320 - *~
.classpath
.idea
.metadata*
.project
.settings
AdminSettings.php
LocalSettings.php
StartProfiler.php
cscope.files
cscope.out
favicon.ico
nbproject*
project.index
static*
tags
33193321 + *~
.classpath
.idea
.metadata*
.project
.settings
AdminSettings.php
LocalSettings.php
StartProfiler.php
cscope.files
cscope.out
favicon.ico
nbproject*
project.index
static*
tags
.jpg
.png

Status & tagging log