From: Chad Horohoe Date: Fri, 9 Oct 2009 11:41:38 +0000 (+0000) Subject: Move construction of $url and $thumbUrl up to FileRepo so ForeignApiRepo can use... X-Git-Tag: 1.31.0-rc.0~39335 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=8ed9ea12b756b3e87ea8859f03ea596f7a71d7eb;p=lhc%2Fweb%2Fwiklou.git Move construction of $url and $thumbUrl up to FileRepo so ForeignApiRepo can use them. Also make no-op FileRepo::getZoneUrl() which always returns false. Also implement this in ForeignApiRepo and return public and thumb zones. Fixes bug 16832 --- diff --git a/includes/filerepo/FSRepo.php b/includes/filerepo/FSRepo.php index c6b9801659..bf844a3a0c 100644 --- a/includes/filerepo/FSRepo.php +++ b/includes/filerepo/FSRepo.php @@ -6,7 +6,7 @@ * @ingroup FileRepo */ class FSRepo extends FileRepo { - var $directory, $deletedDir, $url, $deletedHashLevels, $fileMode; + var $directory, $deletedDir, $deletedHashLevels, $fileMode; var $fileFactory = array( 'UnregisteredLocalFile', 'newFromTitle' ); var $oldFileFactory = false; var $pathDisclosureProtection = 'simple'; @@ -76,7 +76,7 @@ class FSRepo extends FileRepo { } /** - * Get the URL corresponding to one of the three basic zones + * @see FileRepo::getZoneUrl() */ function getZoneUrl( $zone ) { switch ( $zone ) { @@ -85,11 +85,11 @@ class FSRepo extends FileRepo { case 'temp': return "{$this->url}/temp"; case 'deleted': - return false; // no public URL + return parent::getZoneUrl( $zone ); // no public URL case 'thumb': return $this->thumbUrl; default: - return false; + return parent::getZoneUrl( $zone ); } } diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index c11a23faf0..64a7bfd49b 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -14,7 +14,7 @@ abstract class FileRepo { var $thumbScriptUrl, $transformVia404; var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription, $initialCapital; var $pathDisclosureProtection = 'paranoid'; - var $descriptionCacheExpiry, $apiThumbCacheExpiry, $hashLevels; + var $descriptionCacheExpiry, $hashLevels, $url, $thumbUrl; /** * Factory functions for creating new files @@ -31,7 +31,7 @@ abstract class FileRepo { $this->initialCapital = true; // by default foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', - 'descriptionCacheExpiry', 'apiThumbCacheExpiry', 'hashLevels' ) as $var ) + 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl' ) as $var ) { if ( isset( $info[$var] ) ) { $this->$var = $info[$var]; @@ -234,6 +234,15 @@ abstract class FileRepo { function getThumbScriptUrl() { return $this->thumbScriptUrl; } + + /** + * Get the URL corresponding to one of the four basic zones + * @param String $zone One of: public, deleted, temp, thumb + * @return String or false + */ + function getZoneUrl( $zone ) { + return false; + } /** * Returns true if the repository can transform files via a 404 handler diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 22b1b5d8e6..7984a2d609 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -26,10 +26,21 @@ class ForeignAPIRepo extends FileRepo { function __construct( $info ) { parent::__construct( $info ); $this->mApiBase = $info['apibase']; // http://commons.wikimedia.org/w/api.php + if( isset( $info['apiThumbCacheExpiry'] ) ) { + $this->apiThumbCacheExpiry = $info['apiThumbCacheExpiry']; + } if( !$this->scriptDirUrl ) { // hack for description fetches $this->scriptDirUrl = dirname( $this->mApiBase ); } + // 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'; + } } /** @@ -206,6 +217,20 @@ class ForeignAPIRepo extends FileRepo { } } + /** + * @see FileRepo::getZoneUrl() + */ + function getZoneUrl( $zone ) { + switch ( $zone ) { + case 'public': + return $this->url; + case 'thumb': + return $this->thumbUrl; + default: + return parent::getZoneUrl( $zone ); + } + } + /** * Are we locally caching the thumbnails? * @return bool