merged master
[lhc/web/wiklou.git] / includes / filerepo / FileRepo.php
index 3d2ccf4..3159077 100644 (file)
@@ -113,10 +113,9 @@ class FileRepo {
                        ? $info['deletedHashLevels']
                        : $this->hashLevels;
                $this->transformVia404 = !empty( $info['transformVia404'] );
-               $this->zones = isset( $info['zones'] )
-                       ? $info['zones']
-                       : array();
+               $this->isPrivate = !empty( $info['isPrivate'] );
                // Give defaults for the basic zones...
+               $this->zones = isset( $info['zones'] ) ? $info['zones'] : array();
                foreach ( array( 'public', 'thumb', 'temp', 'deleted' ) as $zone ) {
                        if ( !isset( $this->zones[$zone]['container'] ) ) {
                                $this->zones[$zone]['container'] = "{$this->name}-{$zone}";
@@ -216,6 +215,28 @@ class FileRepo {
                }
        }
 
+       /**
+        * Get the thumb zone URL configured to be handled by scripts like thumb_handler.php.
+        * This is probably only useful for internal requests, such as from a fast frontend server
+        * to a slower backend server.
+        *
+        * Large sites may use a different host name for uploads than for wikis. In any case, the
+        * wiki configuration is needed in order to use thumb.php. To avoid extracting the wiki ID
+        * from the URL path, one can configure thumb_handler.php to recognize a special path on the
+        * same host name as the wiki that is used for viewing thumbnails.
+        *
+        * @param $zone String: one of: public, deleted, temp, thumb
+        * @return String or false
+        */
+       public function getZoneHandlerUrl( $zone ) {
+               if ( isset( $this->zones[$zone]['handlerUrl'] )
+                       && in_array( $zone, array( 'public', 'temp', 'thumb' ) ) )
+               {
+                       return $this->zones[$zone]['handlerUrl'];
+               }
+               return false;
+       }
+
        /**
         * Get the backend storage path corresponding to a virtual URL.
         * Use this function wisely.
@@ -439,6 +460,24 @@ class FileRepo {
                return array();
        }
 
+       /**
+        * Get an array of arrays or iterators of file objects for files that
+        * have the given SHA-1 content hashes.
+        *
+        * @param $hashes array An array of hashes
+        * @return array An Array of arrays or iterators of file objects and the hash as key
+        */
+       public function findBySha1s( array $hashes ) {
+               $result = array();
+               foreach ( $hashes as $hash ) {
+                       $files = $this->findBySha1( $hash );
+                       if ( count( $files ) ) {
+                               $result[$hash] = $files;
+                       }
+               }
+               return $result;
+       }
+
        /**
         * Get the public root URL of the repository
         *
@@ -1123,7 +1162,7 @@ class FileRepo {
                list( $b, $container, $r ) = FileBackend::splitStoragePath( $path );
 
                $params = array( 'dir' => $path );
-               if ( $container === $this->zones['deleted']['container'] ) {
+               if ( $this->isPrivate || $container === $this->zones['deleted']['container'] ) {
                        # Take all available measures to prevent web accessibility of new deleted
                        # directories, in case the user has not configured offline storage
                        $params = array( 'noAccess' => true, 'noListing' => true ) + $params;
@@ -1348,18 +1387,14 @@ class FileRepo {
        }
 
        /**
-        * Get the sha1 of a file with a given virtual URL/storage path
+        * Get the sha1 (base 36) of a file with a given virtual URL/storage path
         *
         * @param $virtualUrl string
         * @return string|bool
         */
        public function getFileSha1( $virtualUrl ) {
                $path = $this->resolveToStoragePath( $virtualUrl );
-               $tmpFile = $this->backend->getLocalReference( array( 'src' => $path ) );
-               if ( !$tmpFile ) {
-                       return false;
-               }
-               return $tmpFile->getSha1Base36();
+               return $this->backend->getFileSha1Base36( array( 'src' => $path ) );
        }
 
        /**