Move construction of $url and $thumbUrl up to FileRepo so ForeignApiRepo can use...
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 9 Oct 2009 11:41:38 +0000 (11:41 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 9 Oct 2009 11:41:38 +0000 (11:41 +0000)
includes/filerepo/FSRepo.php
includes/filerepo/FileRepo.php
includes/filerepo/ForeignAPIRepo.php

index c6b9801..bf844a3 100644 (file)
@@ -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 );
                }
        }
 
index c11a23f..64a7bfd 100644 (file)
@@ -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
index 22b1b5d..7984a2d 100644 (file)
@@ -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