r105777 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105776‎ | r105777 | r105778 >
Date:01:53, 11 December 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Removed doFSTransform() hack and put that code in the File::maybeDoTransform(). doTransform() now works like it does in trunk mostly.
* Fixed the last failings tests.
Modified paths:
  • /branches/FileBackend/phase3/includes/filerepo/file/File.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/Bitmap.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/Bitmap_ClientOnly.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/DjVu.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/Generic.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/MediaTransformOutput.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/SVG.php (modified) (history)
  • /branches/FileBackend/phase3/includes/upload/UploadStash.php (modified) (history)
  • /branches/FileBackend/phase3/tests/parser/parserTest.inc (modified) (history)
  • /branches/FileBackend/phase3/tests/phpunit/includes/LocalFileTest.php (modified) (history)
  • /branches/FileBackend/phase3/tests/phpunit/includes/parser/NewParserTest.php (modified) (history)
  • /branches/FileBackend/phase3/tests/phpunit/suites/UploadFromUrlTestSuite.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/tests/phpunit/includes/LocalFileTest.php
@@ -9,25 +9,23 @@
1010 function setUp() {
1111 global $wgCapitalLinks;
1212
13 - $config = array(
 13+ $wgCapitalLinks = true;
 14+
 15+ $backend = new FSFileBackend( array(
1416 'name' => 'local-backend',
15 - 'class' => 'FSFileBackend',
1617 'lockManager' => 'fsLockManager',
1718 'containerPaths' => array(
1819 'cont1' => "/testdir/local-backend/tempimages/cont1",
1920 'cont2' => "/testdir/local-backend/tempimages/cont2"
2021 )
21 - );
22 - FileBackendGroup::singleton()->register( array( $config ) );
23 -
24 - $wgCapitalLinks = true;
 22+ ) );
2523 $info = array(
2624 'name' => 'test',
2725 'directory' => '/testdir',
2826 'url' => '/testurl',
2927 'hashLevels' => 2,
3028 'transformVia404' => false,
31 - 'backend' => 'local-backend'
 29+ 'backend' => $backend
3230 );
3331 $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
3432 $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
Index: branches/FileBackend/phase3/tests/phpunit/includes/parser/NewParserTest.php
@@ -56,12 +56,12 @@
5757 $tmpGlobals['wgStylePath'] = '/skins';
5858 $tmpGlobals['wgThumbnailScriptPath'] = false;
5959 $tmpGlobals['wgLocalFileRepo'] = array(
60 - 'class' => 'LocalRepo',
61 - 'name' => 'local',
62 - 'url' => 'http://example.com/images',
63 - 'hashLevels' => 2,
 60+ 'class' => 'LocalRepo',
 61+ 'name' => 'local',
 62+ 'url' => 'http://example.com/images',
 63+ 'hashLevels' => 2,
6464 'transformVia404' => false,
65 - 'backend' => 'local-backend'
 65+ 'backend' => 'local-backend'
6666 );
6767 $tmpGlobals['wgForeignFileRepos'] = array();
6868 $tmpGlobals['wgEnableParserCache'] = false;
@@ -116,6 +116,7 @@
117117 // Restore backends
118118 FileBackendGroup::destroySingleton();
119119 FileBackendGroup::singleton()->register( $GLOBALS['wgFileBackends'] );
 120+ RepoGroup::destroySingleton();
120121 }
121122
122123 function addDBData() {
@@ -233,12 +234,12 @@
234235 'wgExtensionAssetsPath' => '/extensions',
235236 'wgActionPaths' => array(),
236237 'wgLocalFileRepo' => array(
237 - 'class' => 'LocalRepo',
238 - 'name' => 'local',
239 - 'url' => 'http://example.com/images',
240 - 'hashLevels' => 2,
 238+ 'class' => 'LocalRepo',
 239+ 'name' => 'local',
 240+ 'url' => 'http://example.com/images',
 241+ 'hashLevels' => 2,
241242 'transformVia404' => false,
242 - 'backend' => 'local-backend'
 243+ 'backend' => 'local-backend'
243244 ),
244245 'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ),
245246 'wgStylePath' => '/skins',
@@ -381,13 +382,14 @@
382383 * after each test runs.
383384 */
384385 protected function teardownGlobals() {
385 - RepoGroup::destroySingleton();
386 - LinkCache::singleton()->clear();
387 -
388386 foreach ( $this->savedGlobals as $var => $val ) {
389387 $GLOBALS[$var] = $val;
390388 }
391389
 390+ RepoGroup::destroySingleton();
 391+ LinkCache::singleton()->clear();
 392+ FileBackendGroup::destroySingleton();
 393+
392394 $this->teardownUploadDir( $this->uploadDir );
393395 }
394396
Index: branches/FileBackend/phase3/tests/phpunit/suites/UploadFromUrlTestSuite.php
@@ -26,14 +26,23 @@
2727 $wgStyleSheetPath = '/skins';
2828 $wgStylePath = '/skins';
2929 $wgThumbnailScriptPath = false;
 30+ $backend = new FSFileBackend( array(
 31+ 'name' => 'local-backend',
 32+ 'lockManager' => 'fsLockManager',
 33+ 'containerPaths' => array(
 34+ 'images-public' => wfTempDir() . '/test-repo/public',
 35+ 'images-thumb' => wfTempDir() . '/test-repo/thumb',
 36+ 'images-temp' => wfTempDir() . '/test-repo/temp',
 37+ 'images-deleted' => wfTempDir() . '/test-repo/delete',
 38+ )
 39+ ) );
3040 $wgLocalFileRepo = array(
31 - 'class' => 'LocalRepo',
32 - 'name' => 'local',
33 - 'directory' => wfTempDir() . '/test-repo',
34 - 'url' => 'http://example.com/images',
35 - 'deletedDir' => wfTempDir() . '/test-repo/delete',
36 - 'hashLevels' => 2,
 41+ 'class' => 'LocalRepo',
 42+ 'name' => 'local',
 43+ 'url' => 'http://example.com/images',
 44+ 'hashLevels' => 2,
3745 'transformVia404' => false,
 46+ 'backend' => $backend
3847 );
3948 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
4049 $wgNamespaceAliases['Image'] = NS_FILE;
Index: branches/FileBackend/phase3/tests/parser/parserTest.inc
@@ -149,14 +149,23 @@
150150 $wgStylePath = '/skins';
151151 $wgExtensionAssetsPath = '/extensions';
152152 $wgThumbnailScriptPath = false;
 153+ $backend = new FSFileBackend( array(
 154+ 'name' => 'local-backend',
 155+ 'lockManager' => 'fsLockManager',
 156+ 'containerPaths' => array(
 157+ 'images-public' => wfTempDir() . '/test-repo/public',
 158+ 'images-thumb' => wfTempDir() . '/test-repo/thumb',
 159+ 'images-temp' => wfTempDir() . '/test-repo/temp',
 160+ 'images-deleted' => wfTempDir() . '/test-repo/delete',
 161+ )
 162+ ) );
153163 $wgLocalFileRepo = array(
154 - 'class' => 'LocalRepo',
155 - 'name' => 'local',
156 - 'directory' => wfTempDir() . '/test-repo',
157 - 'url' => 'http://example.com/images',
158 - 'deletedDir' => wfTempDir() . '/test-repo/delete',
159 - 'hashLevels' => 2,
 164+ 'class' => 'LocalRepo',
 165+ 'name' => 'local',
 166+ 'url' => 'http://example.com/images',
 167+ 'hashLevels' => 2,
160168 'transformVia404' => false,
 169+ 'backend' => $backend
161170 );
162171 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
163172 $wgNamespaceAliases['Image'] = NS_FILE;
Index: branches/FileBackend/phase3/includes/upload/UploadStash.php
@@ -48,7 +48,7 @@
4949 *
5050 * @param $repo FileRepo
5151 */
52 - public function __construct( $repo, $user = null ) {
 52+ public function __construct( FileRepo $repo, $user = null ) {
5353 // this might change based on wiki's configuration.
5454 $this->repo = $repo;
5555
Index: branches/FileBackend/phase3/includes/filerepo/file/File.php
@@ -751,45 +751,60 @@
752752 * Typical keys are width, height and page.
753753 * @param $flags Integer: a bitfield, may contain self::RENDER_NOW to force rendering
754754 *
755 - * @return MediaTransformOutput | false
 755+ * @return MediaTransformOutput|null
756756 */
757757 protected function maybeDoTransform( $thumbName, $thumbUrl, $params, $flags = 0 ) {
758758 global $wgIgnoreImageErrors, $wgThumbnailEpoch;
759759
760 - $thumbPath = $this->getThumbPath( $thumbName );
761 - if ( $this->repo && $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) {
 760+ $thumbPath = $this->getThumbPath( $thumbName ); // final thumb path
 761+ // Create a temp FS file with the same extension
 762+ $tmpFile = TempFSFile::factory( 'transform', $this->getExtension() );
 763+ if ( !$tmpFile ) {
 764+ return new MediaTransformError( 'thumbnail_error',
 765+ $params['width'], 0, wfMsg( 'thumbnail-temp-create' ) );
 766+ }
 767+ $tmpThumbPath = $tmpFile->getPath(); // path of 0-byte temp file
 768+
 769+ if ( $this->repo && $this->repo->canTransformVia404() && !( $flags & self::RENDER_NOW ) ) {
762770 wfDebug( __METHOD__ . " transformation deferred." );
763 - return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
 771+ return $this->handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $params );
764772 }
765773
766774 wfDebug( __METHOD__.": Doing stat for $thumbPath\n" );
767775 $this->migrateThumbFile( $thumbName );
768 - if ( $this->repo->fileExists( $thumbPath ) && !($flags & self::RENDER_FORCE) ) {
769 - $thumbTime = $this->repo->getFileTimestamp( $thumbPath );
770 - if ( $thumbTime !== false
771 - && gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch )
772 - {
773 - return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
 776+ if ( $this->repo->fileExists( $thumbPath ) && !( $flags & self::RENDER_FORCE ) ) {
 777+ $ts = $this->repo->getFileTimestamp( $thumbPath );
 778+ if ( $ts !== false && gmdate( 'YmdHis', $ts ) >= $wgThumbnailEpoch ) {
 779+ return $this->handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $params );
774780 }
775 - } elseif( $flags & self::RENDER_FORCE ) {
 781+ } elseif ( $flags & self::RENDER_FORCE ) {
776782 wfDebug( __METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n" );
777783 }
778 - $thumb = $this->handler->doTransform( $this, $thumbPath, $thumbUrl, $params );
779784
 785+ // Actually render the thumbnail
 786+ $thumb = $this->handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $params );
 787+
780788 // Ignore errors if requested
781789 if ( !$thumb ) {
782790 $thumb = null;
783791 } elseif ( $thumb->isError() ) {
784792 $this->lastError = $thumb->toText();
785 - if ( $wgIgnoreImageErrors && !($flags & self::RENDER_NOW) ) {
786 - $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
 793+ if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
 794+ $thumb = $this->handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $params );
787795 }
 796+ } elseif ( $thumb->hasFile() && !$thumb->fileIsSource() ) {
 797+ $op = array( 'op' => 'store',
 798+ 'src' => $tmpThumbPath, 'dst' => $thumbPath, 'overwriteDest' => true );
 799+ // Copy any thumbnail from the FS into storage at $dstpath
 800+ if ( !$this->getRepo()->getBackend()->doOperation( $op )->isOK() ) {
 801+ return new MediaTransformError( 'thumbnail_error',
 802+ $params['width'], 0, wfMsg( 'thumbnail-dest-create' ) );
 803+ }
788804 }
789805
790806 return $thumb;
791807 }
792808
793 -
794809 /**
795810 * Transform a media file
796811 *
Index: branches/FileBackend/phase3/includes/media/MediaTransformOutput.php
@@ -7,7 +7,7 @@
88 */
99
1010 /**
11 - * Base class for the output of MediaHandler::doFSTransform() and File::transform().
 11+ * Base class for the output of MediaHandler::doTransform() and File::transform().
1212 *
1313 * @ingroup Media
1414 */
Index: branches/FileBackend/phase3/includes/media/SVG.php
@@ -85,7 +85,7 @@
8686 * @param int $flags
8787 * @return bool|MediaTransformError|ThumbnailImage|TransformParameterError
8888 */
89 - function doFSTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
 89+ function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
9090 if ( !$this->normaliseParams( $image, $params ) ) {
9191 return new TransformParameterError( $params );
9292 }
Index: branches/FileBackend/phase3/includes/media/DjVu.php
@@ -113,7 +113,7 @@
114114 * @param int $flags
115115 * @return MediaTransformError|ThumbnailImage|TransformParameterError
116116 */
117 - function doFSTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
 117+ function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
118118 global $wgDjvuRenderer, $wgDjvuPostProcessor;
119119
120120 // Fetch XML and check it, to give a more informative error message than the one which
Index: branches/FileBackend/phase3/includes/media/Bitmap.php
@@ -106,7 +106,7 @@
107107 * @param int $flags
108108 * @return MediaTransformError|ThumbnailImage|TransformParameterError
109109 */
110 - function doFSTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
 110+ function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
111111 if ( !$this->normaliseParams( $image, $params ) ) {
112112 return new TransformParameterError( $params );
113113 }
Index: branches/FileBackend/phase3/includes/media/Bitmap_ClientOnly.php
@@ -33,7 +33,7 @@
3434 * @param int $flags
3535 * @return ThumbnailImage|TransformParameterError
3636 */
37 - function doFSTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
 37+ function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
3838 if ( !$this->normaliseParams( $image, $params ) ) {
3939 return new TransformParameterError( $params );
4040 }
Index: branches/FileBackend/phase3/includes/media/Generic.php
@@ -203,48 +203,9 @@
204204 *
205205 * @return MediaTransformOutput
206206 */
207 - final function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
208 - if ( FileBackend::isStoragePath( $dstPath ) ) {
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' ) );
214 - }
215 - $tmpDest = $tmpFile->getPath(); // path of 0-byte temp file
216 - // Create the output thumbnail on the FS
217 - $out = $this->doFSTransform( $image, $tmpDest, $dstUrl, $params, $flags );
218 - // Copy any thumbnail from FS into storage at $dstpath
219 - // Note: no file is created if it's to be rendered client-side.
220 - if ( !$out->isError() && $out->hasFile() && !$out->fileIsSource() ) {
221 - $op = array( 'op' => 'store',
222 - 'src' => $tmpDest, 'dst' => $dstPath, 'overwriteDest' => true );
223 - if ( !$image->getRepo()->getBackend()->doOperation( $op )->isOK() ) {
224 - return new MediaTransformError( 'thumbnail_error',
225 - $params['width'], 0, wfMsg( 'thumbnail-dest-create' ) );
226 - }
227 - }
228 - } else {
229 - $out = $this->doFSTransform( $image, $dstPath, $dstUrl, $params, $flags );
230 - }
231 - return $out;
232 - }
 207+ abstract function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
233208
234209 /**
235 - * Get a MediaTransformOutput object representing the transformed output. Does the
236 - * transform unless $flags contains self::TRANSFORM_LATER.
237 - *
238 - * @param $image File: the image object
239 - * @param $dstPath String: filesystem destination path
240 - * @param $dstUrl String: destination URL to use in output HTML
241 - * @param $params Array: arbitrary set of parameters validated by $this->validateParam()
242 - * @param $flags Integer: a bitfield, may contain self::TRANSFORM_LATER
243 - *
244 - * @return MediaTransformOutput
245 - */
246 - abstract function doFSTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
247 -
248 - /**
249210 * Get the thumbnail extension and MIME type for a given source MIME type
250211 * @return array thumbnail extension and MIME type
251212 */

Status & tagging log