diff options
Diffstat (limited to 'includes/filerepo/ForeignAPIRepo.php')
-rw-r--r-- | includes/filerepo/ForeignAPIRepo.php | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 502b8c1d..e544defb 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -32,20 +32,16 @@ class ForeignAPIRepo extends FileRepo { var $apiThumbCacheExpiry = 86400; /* 24*60*60 */ /* Redownload thumbnail files after a month */ var $fileCacheExpiry = 2592000; /* 86400*30 */ - /* Local image directory */ - var $directory; - var $thumbDir; protected $mQueryCache = array(); protected $mFileExists = array(); function __construct( $info ) { + global $wgLocalFileRepo; parent::__construct( $info ); - global $wgUploadDirectory; // http://commons.wikimedia.org/w/api.php $this->mApiBase = isset( $info['apibase'] ) ? $info['apibase'] : null; - $this->directory = isset( $info['directory'] ) ? $info['directory'] : $wgUploadDirectory; if( isset( $info['apiThumbCacheExpiry'] ) ) { $this->apiThumbCacheExpiry = $info['apiThumbCacheExpiry']; @@ -59,17 +55,11 @@ class ForeignAPIRepo extends FileRepo { } // If we can cache thumbs we can guess sane defaults for these if( $this->canCacheThumbs() && !$this->url ) { - global $wgLocalFileRepo; $this->url = $wgLocalFileRepo['url']; } if( $this->canCacheThumbs() && !$this->thumbUrl ) { $this->thumbUrl = $this->url . '/thumb'; } - if ( isset( $info['thumbDir'] ) ) { - $this->thumbDir = $info['thumbDir']; - } else { - $this->thumbDir = "{$this->directory}/thumb"; - } } /** @@ -97,6 +87,10 @@ class ForeignAPIRepo extends FileRepo { return false; } + function concatenate( $fileList, $targetPath, $flags = 0 ){ + return false; + } + function append( $srcPath, $toAppendPath, $flags = 0 ){ return false; } @@ -280,9 +274,9 @@ class ForeignAPIRepo extends FileRepo { $localFilename = $localPath . "/" . $fileName; $localUrl = $this->getZoneUrl( 'thumb' ) . "/" . $this->getHashPath( $name ) . rawurlencode( $name ) . "/" . rawurlencode( $fileName ); - if( file_exists( $localFilename ) && isset( $metadata['timestamp'] ) ) { + if( $this->fileExists( $localFilename ) && isset( $metadata['timestamp'] ) ) { wfDebug( __METHOD__ . " Thumbnail was already downloaded before\n" ); - $modified = filemtime( $localFilename ); + $modified = $this->getFileTimestamp( $localFilename ); $remoteModified = strtotime( $metadata['timestamp'] ); $current = time(); $diff = abs( $modified - $current ); @@ -299,16 +293,12 @@ class ForeignAPIRepo extends FileRepo { wfDebug( __METHOD__ . " Could not download thumb\n" ); return false; } - if ( !is_dir($localPath) ) { - if( !wfMkdirParents($localPath) ) { - wfDebug( __METHOD__ . " could not create directory $localPath for thumb\n" ); - return $foreignUrl; - } - } # @todo FIXME: Delete old thumbs that aren't being used. Maintenance script? wfSuppressWarnings(); - if( !file_put_contents( $localFilename, $thumb ) ) { + $backend = $this->getBackend(); + $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; @@ -335,17 +325,14 @@ class ForeignAPIRepo extends FileRepo { } /** - * Get the local directory corresponding to one of the three basic zones + * Get the local directory corresponding to one of the basic zones */ function getZonePath( $zone ) { - switch ( $zone ) { - case 'public': - return $this->directory; - case 'thumb': - return $this->thumbDir; - default: - return false; + $supported = array( 'public', 'thumb' ); + if ( in_array( $zone, $supported ) ) { + return parent::getZonePath( $zone ); } + return false; } /** @@ -388,4 +375,8 @@ class ForeignAPIRepo extends FileRepo { return false; } } + + function enumFiles( $callback ) { + throw new MWException( 'enumFiles is not supported by ' . get_class( $this ) ); + } } |