From: Aaron Date: Thu, 10 May 2012 18:15:29 +0000 (-0700) Subject: [FileRepo] Cleanup of URL config. X-Git-Tag: 1.31.0-rc.0~23526 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/fiche.php?a=commitdiff_plain;h=11b67f0093649dc969a072336c2137d165b02dd7;p=lhc%2Fweb%2Fwiklou.git [FileRepo] Cleanup of URL config. * 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 --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 3d1c41865e..8f61096510 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 - 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 - 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 diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index ff0e257c98..d4eef8704f 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -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' ); } /**