From 30befebf5d88c6028d685959d48e9312a5e78031 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 3 May 2012 13:54:39 -0700 Subject: [PATCH] [FileRepo] Various ForeignApiRepo fixes. * 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 | 17 ++++++++++++----- includes/filerepo/backend/FileBackendGroup.php | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index ba2694e910..6a4b12e3c1 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -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" ); diff --git a/includes/filerepo/backend/FileBackendGroup.php b/includes/filerepo/backend/FileBackendGroup.php index d705f76057..d02c7d409f 100644 --- a/includes/filerepo/backend/FileBackendGroup.php +++ b/includes/filerepo/backend/FileBackendGroup.php @@ -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() { -- 2.20.1