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, $wgUploadDirectory;
+ if ( !isset( $info['directory'] ) ) { // b/c
+ $info['directory'] = $wgUploadDirectory; // Local image directory
+ }
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'];
}
// 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";
- }
}
/**
$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 );
wfDebug( __METHOD__ . " Could not download thumb\n" );
return false;
}
- if ( !is_dir($localPath) ) {
- if( !wfMkdirParents( $localPath, null, __METHOD__ ) ) {
- 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;
}
/**
- * 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;
}
/**
return false;
}
}
+
+ function enumFiles( $callback ) {
+ throw new MWException( 'enumFiles is not supported by ' . get_class( $this ) );
+ }
}