[FileRepo] Various ForeignApiRepo fixes.
authorAaron <aschulz@wikimedia.org>
Thu, 3 May 2012 20:54:39 +0000 (13:54 -0700)
committerAaron <aschulz@wikimedia.org>
Thu, 3 May 2012 21:04:12 +0000 (14:04 -0700)
* Avoid using FileRepo functions to stat cache files as we override/hack
  fileExistsBatch(). Instead, use the FileBackend object directly.
* Adding missing prepare() call to unbreak thumbnail cache.
* Added a warning and sanity check for mwstore:// paths rather than appending them
  to URLs and shipping them off to Commons. This seem to be mostly gone now though.
* Removed useless error suppression calls that were broken due to a "return" statement.

Change-Id: Ie760f09e6bfa1752544cdb60018513ffc7823496

includes/filerepo/ForeignAPIRepo.php
includes/filerepo/backend/FileBackendGroup.php

index ba2694e..6a4b12e 100644 (file)
@@ -87,6 +87,10 @@ class ForeignAPIRepo extends FileRepo {
                                # same repo.
                                $results[$k] = false;
                                unset( $files[$k] );
+                       } elseif ( FileBackend::isStoragePath( $f ) ) {
+                               $results[$k] = false;
+                               unset( $files[$k] );
+                               wfWarn( "Got mwstore:// path '$f'." );
                        }
                }
 
@@ -203,6 +207,9 @@ class ForeignAPIRepo extends FileRepo {
         */
        function getThumbUrlFromCache( $name, $width, $height, $params="" ) {
                global $wgMemc;
+               // We can't check the local cache using FileRepo functions because
+               // we override fileExistsBatch(). We have to use the FileBackend directly.
+               $backend = $this->getBackend(); // convenience
 
                if ( !$this->canCacheThumbs() ) {
                        $result = null; // can't pass "null" by reference, but it's ok as default value
@@ -243,9 +250,11 @@ class ForeignAPIRepo extends FileRepo {
                $localFilename = $localPath . "/" . $fileName;
                $localUrl =  $this->getZoneUrl( 'thumb' ) . "/" . $this->getHashPath( $name ) . rawurlencode( $name ) . "/" . rawurlencode( $fileName );
 
-               if( $this->fileExists( $localFilename ) && isset( $metadata['timestamp'] ) ) {
+               if( $backend->fileExists( array( 'src' => $localFilename ) )
+                       && isset( $metadata['timestamp'] ) )
+               {
                        wfDebug( __METHOD__ . " Thumbnail was already downloaded before\n" );
-                       $modified = $this->getFileTimestamp( $localFilename );
+                       $modified = $backend->getFileTimestamp( array( 'src' => $localFilename ) );
                        $remoteModified = strtotime( $metadata['timestamp'] );
                        $current = time();
                        $diff = abs( $modified - $current );
@@ -264,15 +273,13 @@ class ForeignAPIRepo extends FileRepo {
                }
 
                # @todo FIXME: Delete old thumbs that aren't being used. Maintenance script?
-               wfSuppressWarnings();
-               $backend = $this->getBackend();
+               $backend->prepare( array( 'dir' => dirname( $localFilename ) ) );
                $op = array( 'op' => 'create', 'dst' => $localFilename, 'content' => $thumb );
                if( !$backend->doOperation( $op )->isOK() ) {
                        wfRestoreWarnings();
                        wfDebug( __METHOD__ . " could not write to thumb path\n" );
                        return $foreignUrl;
                }
-               wfRestoreWarnings();
                $knownThumbUrls[$sizekey] = $localUrl;
                $wgMemc->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
                wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" );
index d705f76..d02c7d4 100644 (file)
@@ -35,7 +35,7 @@ class FileBackendGroup {
 
        /**
         * Destroy the singleton instance
-        * 
+        *
         * @return void
         */
        public static function destroySingleton() {
@@ -44,7 +44,7 @@ class FileBackendGroup {
 
        /**
         * Register file backends from the global variables
-        * 
+        *
         * @return void
         */
        protected function initFromGlobals() {