[FileRepo] Cleanup of URL config.
authorAaron <aschulz@wikimedia.org>
Thu, 10 May 2012 18:15:29 +0000 (11:15 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 23 May 2012 04:16:53 +0000 (21:16 -0700)
* Made the 'zones' config a bit easier to set by falling back to defaults more piecemeal.
  Each zone now also has a 'url' parameter. This is useful for CDN support for third parties.
* Deprecated weirdly name getRootUrl() function and made it wrap getZoneUrl( 'public' ).

Change-Id: I8295a81e9cc56c08069b35fa4e4f883fd0108df7

includes/DefaultSettings.php
includes/filerepo/FileRepo.php

index 3d1c418..8f61096 100644 (file)
@@ -328,9 +328,11 @@ $wgImgAuthPublicTest = true;
  *   - zones            Associative array of zone names that each map to an array with:
  *                          container : backend container name the zone is in
  *                          directory : root path within container for the zone
- *                      Zones default to using <repo name>-<zone> as the
- *                      container name and the container root as the zone directory.
- *   - url              Base public URL
+ *                          url       : base URL to the root of the zone
+ *                      Zones default to using <repo name>-<zone name> as the container name
+ *                      and default to using the container root as the zone's root directory.
+ *                      Nesting of zone locations within other zones should be avoided.
+ *   - url              Public zone URL. The 'zones' settings take precedence.
  *   - hashLevels       The number of directory levels for hash-based division of files
  *   - thumbScriptUrl   The URL for thumb.php (optional, not recommended)
  *   - transformVia404  Whether to skip media file transformation on parse and rely on a 404
index ff0e257..d4eef87 100644 (file)
@@ -64,7 +64,7 @@ class FileRepo {
         * @param $info array|null
         * @throws MWException
         */
-       function __construct( array $info = null ) {
+       public function __construct( array $info = null ) {
                // Verify required settings presence
                if(
                        $info === null
@@ -118,11 +118,11 @@ class FileRepo {
                        : array();
                // Give defaults for the basic zones...
                foreach ( array( 'public', 'thumb', 'temp', 'deleted' ) as $zone ) {
-                       if ( !isset( $this->zones[$zone] ) ) {
-                               $this->zones[$zone] = array(
-                                       'container' => "{$this->name}-{$zone}",
-                                       'directory' => '' // container root
-                               );
+                       if ( !isset( $this->zones[$zone]['container'] ) ) {
+                               $this->zones[$zone]['container'] = "{$this->name}-{$zone}";
+                       }
+                       if ( !isset( $this->zones[$zone]['directory'] ) ) {
+                               $this->zones[$zone]['directory'] = '';
                        }
                }
        }
@@ -209,6 +209,11 @@ class FileRepo {
         * @return String or false
         */
        public function getZoneUrl( $zone ) {
+               if ( isset( $this->zones[$zone]['url'] )
+                       && in_array( $zone, array( 'public', 'temp', 'thumb' ) ) )
+               {
+                       return $this->zones[$zone]['url']; // custom URL
+               }
                switch ( $zone ) {
                        case 'public':
                                return $this->url;
@@ -449,10 +454,11 @@ class FileRepo {
        /**
         * Get the public root URL of the repository
         *
+        * @deprecated since 1.20
         * @return string
         */
        public function getRootUrl() {
-               return $this->url;
+               return $this->getZoneUrl( 'public' );
        }
 
        /**