Fix various type and reference issues
[lhc/web/wiklou.git] / includes / filebackend / SwiftFileBackend.php
index a620f88..c5111e2 100644 (file)
@@ -24,7 +24,7 @@
  */
 
 /**
- * @brief Class for an OpenStack Swift based file backend.
+ * @brief Class for an OpenStack Swift (or Ceph RGW) based file backend.
  *
  * This requires the SwiftCloudFiles MediaWiki extension, which includes
  * the php-cloudfiles library (https://github.com/rackspace/php-cloudfiles).
  * @since 1.19
  */
 class SwiftFileBackend extends FileBackendStore {
-       /** @var CF_Authentication */
-       protected $auth; // Swift authentication handler
-       protected $authTTL; // integer seconds
-       protected $swiftTempUrlKey; // string; shared secret value for making temp urls
-       protected $swiftAnonUser; // string; username to handle unauthenticated requests
-       protected $swiftUseCDN; // boolean; whether CloudFiles CDN is enabled
-       protected $swiftCDNExpiry; // integer; how long to cache things in the CDN
-       protected $swiftCDNPurgable; // boolean; whether object CDN purging is enabled
+       /** @var CF_Authentication Swift authentication handler */
+       protected $auth;
+
+       /** @var int TTL in seconds */
+       protected $authTTL;
+
+       /** @var string Shared secret value for making temp URLs */
+       protected $swiftTempUrlKey;
+
+       /** @var string Username to handle unauthenticated requests */
+       protected $swiftAnonUser;
+
+       /** @var bool Whether CloudFiles CDN is enabled */
+       protected $swiftUseCDN;
+
+       /** @var int How long to cache things in the CDN */
+       protected $swiftCDNExpiry;
+
+       /** @var bool Whether object CDN purging is enabled */
+       protected $swiftCDNPurgable;
 
        // Rados Gateway specific options
-       protected $rgwS3AccessKey; // string; S3 access key
-       protected $rgwS3SecretKey; // string; S3 authentication key
+       /** @var string S3 access key */
+       protected $rgwS3AccessKey;
+
+       /** @var string S3 authentication key */
+       protected $rgwS3SecretKey;
 
-       /** @var CF_Connection */
-       protected $conn; // Swift connection handle
-       protected $sessionStarted = 0; // integer UNIX timestamp
+       /** @var CF_Connection Swift connection handle*/
+       protected $conn;
+
+       /** @var int UNIX timestamp */
+       protected $sessionStarted = 0;
 
        /** @var CloudFilesException */
        protected $connException;
-       protected $connErrorTime = 0; // UNIX timestamp
+
+       /** @var int UNIX timestamp */
+       protected $connErrorTime = 0;
 
        /** @var BagOStuff */
        protected $srvCache;
@@ -153,7 +172,8 @@ class SwiftFileBackend extends FileBackendStore {
                        } else {
                                try { // look for APC, XCache, WinCache, ect...
                                        $this->srvCache = ObjectCache::newAccelerator( array() );
-                               } catch ( Exception $e ) {}
+                               } catch ( Exception $e ) {
+                               }
                        }
                }
                $this->srvCache = $this->srvCache ? $this->srvCache : new EmptyBagOStuff();
@@ -161,7 +181,10 @@ class SwiftFileBackend extends FileBackendStore {
 
        /**
         * @see FileBackendStore::resolveContainerPath()
-        * @return null
+        * @param string $container
+        * @param string $relStoragePath
+        * @return string|null Returns null when the URL encoded storage path is
+        *   longer than 1024 characters or not UTF-8 encoded.
         */
        protected function resolveContainerPath( $container, $relStoragePath ) {
                if ( !mb_check_encoding( $relStoragePath, 'UTF-8' ) ) { // mb_string required by CF
@@ -169,6 +192,7 @@ class SwiftFileBackend extends FileBackendStore {
                } elseif ( strlen( urlencode( $relStoragePath ) ) > 1024 ) {
                        return null; // too long for Swift
                }
+
                return $relStoragePath;
        }
 
@@ -180,6 +204,7 @@ class SwiftFileBackend extends FileBackendStore {
 
                try {
                        $this->getContainer( $container );
+
                        return true; // container exists
                } catch ( NoSuchContainerException $e ) {
                } catch ( CloudFilesException $e ) { // some other exception?
@@ -198,6 +223,7 @@ class SwiftFileBackend extends FileBackendStore {
                if ( isset( $headers['Content-Disposition'] ) ) {
                        $headers['Content-Disposition'] = $this->truncDisp( $headers['Content-Disposition'] );
                }
+
                return $headers;
        }
 
@@ -216,6 +242,7 @@ class SwiftFileBackend extends FileBackendStore {
                                break; // too long; sigh
                        }
                }
+
                return $res;
        }
 
@@ -225,6 +252,7 @@ class SwiftFileBackend extends FileBackendStore {
                list( $dstCont, $dstRel ) = $this->resolveStoragePathReal( $params['dst'] );
                if ( $dstRel === null ) {
                        $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
                        return $status;
                }
 
@@ -233,9 +261,11 @@ class SwiftFileBackend extends FileBackendStore {
                        $dContObj = $this->getContainer( $dstCont );
                } catch ( NoSuchContainerException $e ) {
                        $status->fatal( 'backend-fail-create', $params['dst'] );
+
                        return $status;
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, $status, __METHOD__, $params );
+
                        return $status;
                }
 
@@ -293,6 +323,7 @@ class SwiftFileBackend extends FileBackendStore {
                list( $dstCont, $dstRel ) = $this->resolveStoragePathReal( $params['dst'] );
                if ( $dstRel === null ) {
                        $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
                        return $status;
                }
 
@@ -301,9 +332,11 @@ class SwiftFileBackend extends FileBackendStore {
                        $dContObj = $this->getContainer( $dstCont );
                } catch ( NoSuchContainerException $e ) {
                        $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
+
                        return $status;
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, $status, __METHOD__, $params );
+
                        return $status;
                }
 
@@ -313,6 +346,7 @@ class SwiftFileBackend extends FileBackendStore {
                wfRestoreWarnings();
                if ( $sha1Hash === false ) { // source doesn't exist?
                        $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
+
                        return $status;
                }
                $sha1Hash = wfBaseConvert( $sha1Hash, 16, 36, 31 );
@@ -379,12 +413,14 @@ class SwiftFileBackend extends FileBackendStore {
                list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
                if ( $srcRel === null ) {
                        $status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
                        return $status;
                }
 
                list( $dstCont, $dstRel ) = $this->resolveStoragePathReal( $params['dst'] );
                if ( $dstRel === null ) {
                        $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
                        return $status;
                }
 
@@ -396,9 +432,11 @@ class SwiftFileBackend extends FileBackendStore {
                        if ( empty( $params['ignoreMissingSource'] ) || isset( $sContObj ) ) {
                                $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
                        }
+
                        return $status;
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, $status, __METHOD__, $params );
+
                        return $status;
                }
 
@@ -448,12 +486,14 @@ class SwiftFileBackend extends FileBackendStore {
                list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
                if ( $srcRel === null ) {
                        $status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
                        return $status;
                }
 
                list( $dstCont, $dstRel ) = $this->resolveStoragePathReal( $params['dst'] );
                if ( $dstRel === null ) {
                        $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
                        return $status;
                }
 
@@ -465,9 +505,11 @@ class SwiftFileBackend extends FileBackendStore {
                        if ( empty( $params['ignoreMissingSource'] ) || isset( $sContObj ) ) {
                                $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
                        }
+
                        return $status;
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, $status, __METHOD__, $params );
+
                        return $status;
                }
 
@@ -520,6 +562,7 @@ class SwiftFileBackend extends FileBackendStore {
                list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
                if ( $srcRel === null ) {
                        $status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
                        return $status;
                }
 
@@ -572,6 +615,7 @@ class SwiftFileBackend extends FileBackendStore {
                list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
                if ( $srcRel === null ) {
                        $status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
                        return $status;
                }
 
@@ -605,12 +649,14 @@ class SwiftFileBackend extends FileBackendStore {
                // (a) Check if container already exists
                try {
                        $this->getContainer( $fullCont );
+
                        // NoSuchContainerException not thrown: container must exist
                        return $status; // already exists
                } catch ( NoSuchContainerException $e ) {
                        // NoSuchContainerException thrown: container does not exist
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, $status, __METHOD__, $params );
+
                        return $status;
                }
 
@@ -631,6 +677,7 @@ class SwiftFileBackend extends FileBackendStore {
                        // CDN not enabled; nothing to see here
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, $status, __METHOD__, $params );
+
                        return $status;
                }
 
@@ -639,6 +686,9 @@ class SwiftFileBackend extends FileBackendStore {
 
        /**
         * @see FileBackendStore::doSecureInternal()
+        * @param string $fullCont
+        * @param string $dir
+        * @param array $params
         * @return Status
         */
        protected function doSecureInternal( $fullCont, $dir, array $params ) {
@@ -674,6 +724,9 @@ class SwiftFileBackend extends FileBackendStore {
 
        /**
         * @see FileBackendStore::doPublishInternal()
+        * @param string $fullCont
+        * @param string $dir
+        * @param array $params
         * @return Status
         */
        protected function doPublishInternal( $fullCont, $dir, array $params ) {
@@ -727,6 +780,7 @@ class SwiftFileBackend extends FileBackendStore {
                        return $status; // ok, nothing to do
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, $status, __METHOD__, $params );
+
                        return $status;
                }
 
@@ -740,6 +794,7 @@ class SwiftFileBackend extends FileBackendStore {
                                return $status; // race? consistency delay?
                        } catch ( CloudFilesException $e ) { // some other exception?
                                $this->handleException( $e, $status, __METHOD__, $params );
+
                                return $status;
                        }
                }
@@ -759,8 +814,8 @@ class SwiftFileBackend extends FileBackendStore {
                        $srcObj = $contObj->get_object( $srcRel, $this->headersFromParams( $params ) );
                        $this->addMissingMetadata( $srcObj, $params['src'] );
                        $stat = array(
-                               // Convert dates like "Tue, 03 Jan 2012 22:01:04 GMT" to TS_MW
-                               'mtime' => wfTimestamp( TS_MW, $srcObj->last_modified ),
+                               // Convert various random Swift dates to TS_MW
+                               'mtime' => $this->convertSwiftDate( $srcObj->last_modified, TS_MW ),
                                'size' => (int)$srcObj->content_length,
                                'sha1' => $srcObj->getMetadataValue( 'Sha1base36' )
                        );
@@ -774,6 +829,22 @@ class SwiftFileBackend extends FileBackendStore {
                return $stat;
        }
 
+       /**
+        * Convert dates like "Tue, 03 Jan 2012 22:01:04 GMT"/"2013-05-11T07:37:27.678360Z".
+        * Dates might also come in like "2013-05-11T07:37:27.678360" from Swift listings,
+        * missing the timezone suffix (though Ceph RGW does not appear to have this bug).
+        *
+        * @param string $ts
+        * @param int $format Output format (TS_* constant)
+        * @return string
+        * @throws MWException
+        */
+       protected function convertSwiftDate( $ts, $format = TS_MW ) {
+               $timestamp = new MWTimestamp( $ts );
+
+               return $timestamp->getTimestamp( $format );
+       }
+
        /**
         * Fill in any missing object metadata and save it to Swift
         *
@@ -798,6 +869,7 @@ class SwiftFileBackend extends FileBackendStore {
                                        $obj->setMetadataValues( array( 'Sha1base36' => $hash ) );
                                        $obj->sync_metadata(); // save to Swift
                                        wfProfileOut( __METHOD__ );
+
                                        return true; // success
                                }
                        }
@@ -805,6 +877,7 @@ class SwiftFileBackend extends FileBackendStore {
                trigger_error( "Unable to set SHA-1 metadata for $path", E_USER_WARNING );
                $obj->setMetadataValues( array( 'Sha1base36' => false ) );
                wfProfileOut( __METHOD__ );
+
                return false; // failed
        }
 
@@ -878,12 +951,16 @@ class SwiftFileBackend extends FileBackendStore {
 
        /**
         * @see FileBackendStore::doDirectoryExists()
+        * @param string $fullCont
+        * @param string $dir
+        * @param array $params
         * @return bool|null
         */
        protected function doDirectoryExists( $fullCont, $dir, array $params ) {
                try {
                        $container = $this->getContainer( $fullCont );
                        $prefix = ( $dir == '' ) ? null : "{$dir}/";
+
                        return ( count( $container->list_objects( 1, null, $prefix ) ) > 0 );
                } catch ( NoSuchContainerException $e ) {
                        return false;
@@ -897,6 +974,9 @@ class SwiftFileBackend extends FileBackendStore {
 
        /**
         * @see FileBackendStore::getDirectoryListInternal()
+        * @param string $fullCont
+        * @param string $dir
+        * @param array $params
         * @return SwiftFileBackendDirList
         */
        public function getDirectoryListInternal( $fullCont, $dir, array $params ) {
@@ -905,6 +985,9 @@ class SwiftFileBackend extends FileBackendStore {
 
        /**
         * @see FileBackendStore::getFileListInternal()
+        * @param string $fullCont
+        * @param string $dir
+        * @param array $params
         * @return SwiftFileBackendFileList
         */
        public function getFileListInternal( $fullCont, $dir, array $params ) {
@@ -916,10 +999,10 @@ class SwiftFileBackend extends FileBackendStore {
         *
         * @param string $fullCont Resolved container name
         * @param string $dir Resolved storage directory with no trailing slash
-        * @param string|null $after Storage path of file to list items after
-        * @param integer $limit Max number of items to list
+        * @param string|null $after Resolved container relative path to list items after
+        * @param int $limit Max number of items to list
         * @param array $params Parameters for getDirectoryList()
-        * @return Array List of resolved paths of directories directly under $dir
+        * @return array List of container relative resolved paths of directories directly under $dir
         * @throws FileBackendError
         */
        public function getDirListPageInternal( $fullCont, $dir, &$after, $limit, array $params ) {
@@ -991,14 +1074,14 @@ class SwiftFileBackend extends FileBackendStore {
         *
         * @param string $fullCont Resolved container name
         * @param string $dir Resolved storage directory with no trailing slash
-        * @param string|null $after Storage path of file to list items after
-        * @param integer $limit Max number of items to list
+        * @param string|null $after Resolved container relative path of file to list items after
+        * @param int $limit Max number of items to list
         * @param array $params Parameters for getDirectoryList()
-        * @return Array List of resolved paths of files under $dir
+        * @return array List of resolved container relative paths of files under $dir
         * @throws FileBackendError
         */
        public function getFileListPageInternal( $fullCont, $dir, &$after, $limit, array $params ) {
-               $files = array();
+               $files = array(); // list of (path, stat array or null) entries
                if ( $after === INF ) {
                        return $files; // nothing more
                }
@@ -1007,38 +1090,34 @@ class SwiftFileBackend extends FileBackendStore {
                try {
                        $container = $this->getContainer( $fullCont );
                        $prefix = ( $dir == '' ) ? null : "{$dir}/";
+
+                       // $objects will contain a list of unfiltered names or CF_Object items
                        // Non-recursive: only list files right under $dir
-                       if ( !empty( $params['topOnly'] ) ) { // files and dirs
+                       if ( !empty( $params['topOnly'] ) ) {
                                if ( !empty( $params['adviseStat'] ) ) {
-                                       $limit = min( $limit, self::CACHE_CHEAP_SIZE );
                                        // Note: get_objects() does not include directories
-                                       $objects = $this->loadObjectListing( $params, $dir,
-                                               $container->get_objects( $limit, $after, $prefix, null, '/' ) );
-                                       $files = $objects;
+                                       $objects = $container->get_objects( $limit, $after, $prefix, null, '/' );
                                } else {
+                                       // Note: list_objects() includes directories here
                                        $objects = $container->list_objects( $limit, $after, $prefix, null, '/' );
-                                       foreach ( $objects as $object ) { // files and directories
-                                               if ( substr( $object, -1 ) !== '/' ) {
-                                                       $files[] = $object; // directories end in '/'
-                                               }
-                                       }
                                }
+                               $files = $this->buildFileObjectListing( $params, $dir, $objects );
                        // Recursive: list all files under $dir and its subdirs
-                       } else { // files
+                       } else {
+                               // Note: get_objects()/list_objects() here only return file objects
                                if ( !empty( $params['adviseStat'] ) ) {
-                                       $limit = min( $limit, self::CACHE_CHEAP_SIZE );
-                                       $objects = $this->loadObjectListing( $params, $dir,
-                                               $container->get_objects( $limit, $after, $prefix ) );
+                                       $objects = $container->get_objects( $limit, $after, $prefix );
                                } else {
                                        $objects = $container->list_objects( $limit, $after, $prefix );
                                }
-                               $files = $objects;
+                               $files = $this->buildFileObjectListing( $params, $dir, $objects );
                        }
                        // Page on the unfiltered object listing (what is returned may be filtered)
                        if ( count( $objects ) < $limit ) {
                                $after = INF; // avoid a second RTT
                        } else {
                                $after = end( $objects ); // update last item
+                               $after = is_object( $after ) ? $after->name : $after;
                        }
                } catch ( NoSuchContainerException $e ) {
                } catch ( CloudFilesException $e ) { // some other exception?
@@ -1051,34 +1130,42 @@ class SwiftFileBackend extends FileBackendStore {
        }
 
        /**
-        * Load a list of objects that belong under $dir into stat cache
-        * and return a list of the names of the objects in the same order.
+        * Build a list of file objects, filtering out any directories
+        * and extracting any stat info if provided in $objects (for CF_Objects)
         *
         * @param array $params Parameters for getDirectoryList()
         * @param string $dir Resolved container directory path
-        * @param array $cfObjects List of CF_Object items
-        * @return array List of object names
+        * @param array $objects List of CF_Object items or object names
+        * @return array List of (names,stat array or null) entries
         */
-       private function loadObjectListing( array $params, $dir, array $cfObjects ) {
+       private function buildFileObjectListing( array $params, $dir, array $objects ) {
                $names = array();
-               $storageDir = rtrim( $params['dir'], '/' );
-               $suffixStart = ( $dir === '' ) ? 0 : strlen( $dir ) + 1; // size of "path/to/dir/"
-               // Iterate over the list *backwards* as this primes the stat cache, which is LRU.
-               // If this fills the cache and the caller stats an uncached file before stating
-               // the ones on the listing, there would be zero cache hits if this went forwards.
-               for ( end( $cfObjects ); key( $cfObjects ) !== null; prev( $cfObjects ) ) {
-                       $object = current( $cfObjects );
-                       $path = "{$storageDir}/" . substr( $object->name, $suffixStart );
-                       $val = array(
-                               // Convert dates like "Tue, 03 Jan 2012 22:01:04 GMT" to TS_MW
-                               'mtime'  => wfTimestamp( TS_MW, $object->last_modified ),
-                               'size'   => (int)$object->content_length,
-                               'latest' => false // eventually consistent
-                       );
-                       $this->cheapCache->set( $path, 'stat', $val );
-                       $names[] = $object->name;
+               foreach ( $objects as $object ) {
+                       if ( is_object( $object ) ) {
+                               $stat = array(
+                                       // Convert various random Swift dates to TS_MW
+                                       'mtime' => $this->convertSwiftDate( $object->last_modified, TS_MW ),
+                                       'size' => (int)$object->content_length,
+                                       'latest' => false // eventually consistent
+                               );
+                               $names[] = array( $object->name, $stat );
+                       } elseif ( substr( $object, -1 ) !== '/' ) {
+                               // Omit directories, which end in '/' in listings
+                               $names[] = array( $object, null );
+                       }
                }
-               return array_reverse( $names ); // keep the paths in original order
+
+               return $names;
+       }
+
+       /**
+        * Do not call this function outside of SwiftFileBackendFileList
+        *
+        * @param string $path Storage path
+        * @param array $val Stat value
+        */
+       public function loadListingStatInternal( $path, array $val ) {
+               $this->cheapCache->set( $path, 'stat', $val );
        }
 
        protected function doGetFileSha1base36( array $params ) {
@@ -1089,6 +1176,7 @@ class SwiftFileBackend extends FileBackendStore {
                                $this->clearCache( array( $params['src'] ) );
                                $stat = $this->getFileStat( $params );
                        }
+
                        return $stat['sha1'];
                } else {
                        return false;
@@ -1107,9 +1195,11 @@ class SwiftFileBackend extends FileBackendStore {
                        $cont = $this->getContainer( $srcCont );
                } catch ( NoSuchContainerException $e ) {
                        $status->fatal( 'backend-fail-stream', $params['src'] );
+
                        return $status;
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, $status, __METHOD__, $params );
+
                        return $status;
                }
 
@@ -1197,8 +1287,8 @@ class SwiftFileBackend extends FileBackendStore {
 
        public function getFileHttpUrl( array $params ) {
                if ( $this->swiftTempUrlKey != '' ||
-                       ( $this->rgwS3AccessKey != '' && $this->rgwS3SecretKey != '' ) )
-               {
+                       ( $this->rgwS3AccessKey != '' && $this->rgwS3SecretKey != '' )
+               {
                        list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
                        if ( $srcRel === null ) {
                                return null; // invalid path
@@ -1221,6 +1311,7 @@ class SwiftFileBackend extends FileBackendStore {
                                                $this->rgwS3SecretKey,
                                                true // raw
                                        ) );
+
                                        // See http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html.
                                        // Note: adding a newline for empty CanonicalizedAmzHeaders does not work.
                                        return wfAppendQuery(
@@ -1237,6 +1328,7 @@ class SwiftFileBackend extends FileBackendStore {
                                $this->handleException( $e, null, __METHOD__, $params );
                        }
                }
+
                return null;
        }
 
@@ -1250,13 +1342,14 @@ class SwiftFileBackend extends FileBackendStore {
         * $params is currently only checked for a 'latest' flag.
         *
         * @param array $params
-        * @return Array
+        * @return array
         */
        protected function headersFromParams( array $params ) {
                $hdrs = array();
                if ( !empty( $params['latest'] ) ) {
                        $hdrs[] = 'X-Newest: true';
                }
+
                return $hdrs;
        }
 
@@ -1289,7 +1382,13 @@ class SwiftFileBackend extends FileBackendStore {
        /**
         * Set read/write permissions for a Swift container.
         *
-        * $readGrps is a list of the possible criteria for a request to have
+        * @see http://swift.openstack.org/misc.html#acls
+        *
+        * In general, we don't allow listings to end-users. It's not useful, isn't well-defined
+        * (lists are truncated to 10000 item with no way to page), and is just a performance risk.
+        *
+        * @param CF_Container $contObj Swift container
+        * @param array $readGrps List of the possible criteria for a request to have
         * access to read a container. Each item is one of the following formats:
         *   - account:user        : Grants access if the request is by the given user
         *   - ".r:<regex>"        : Grants access if the request is from a referrer host that
@@ -1297,19 +1396,9 @@ class SwiftFileBackend extends FileBackendStore {
         *                           Setting this to '*' effectively makes a container public.
         *   -".rlistings:<regex>" : Grants access if the request is from a referrer host that
         *                           matches the expression and the request is for a listing.
-        *
-        * $writeGrps is a list of the possible criteria for a request to have
+        * @param array $writeGrps A list of the possible criteria for a request to have
         * access to write to a container. Each item is of the following format:
         *   - account:user       : Grants access if the request is by the given user
-        *
-        * @see http://swift.openstack.org/misc.html#acls
-        *
-        * In general, we don't allow listings to end-users. It's not useful, isn't well-defined
-        * (lists are truncated to 10000 item with no way to page), and is just a performance risk.
-        *
-        * @param CF_Container $contObj Swift container
-        * @param array $readGrps List of read access routes
-        * @param array $writeGrps List of write access routes
         * @return Status
         */
        protected function setContainerAccess(
@@ -1333,7 +1422,6 @@ class SwiftFileBackend extends FileBackendStore {
         * This is for Rackspace/Akamai CDNs.
         *
         * @param array $objects List of CF_Object items
-        * @return void
         */
        public function purgeCDNCache( array $objects ) {
                if ( $this->swiftUseCDN && $this->swiftCDNPurgable ) {
@@ -1395,13 +1483,12 @@ class SwiftFileBackend extends FileBackendStore {
                        }
                        $this->conn = new CF_Connection( $this->auth );
                }
+
                return $this->conn;
        }
 
        /**
         * Close the connection to the Swift proxy
-        *
-        * @return void
         */
        protected function closeConnection() {
                if ( $this->conn ) {
@@ -1448,6 +1535,7 @@ class SwiftFileBackend extends FileBackendStore {
                                );
                        }
                }
+
                return $this->connContainerCache->get( $container, 'obj' );
        }
 
@@ -1469,7 +1557,6 @@ class SwiftFileBackend extends FileBackendStore {
         * Delete a Swift container
         *
         * @param string $container Container name
-        * @return void
         * @throws CloudFilesException
         */
        protected function deleteContainer( $container ) {
@@ -1496,10 +1583,9 @@ class SwiftFileBackend extends FileBackendStore {
         * This also sets the Status object to have a fatal error.
         *
         * @param Exception $e
-        * @param Status $status|null
+        * @param Status $status null
         * @param string $func
         * @param array $params
-        * @return void
         */
        protected function handleException( Exception $e, $status, $func, array $params ) {
                if ( $status instanceof Status ) {
@@ -1529,7 +1615,8 @@ class SwiftFileBackend extends FileBackendStore {
 class SwiftFileOpHandle extends FileBackendStoreOpHandle {
        /** @var CF_Async_Op */
        public $cfOp;
-       /** @var Array */
+
+       /** @var array */
        public $affectedObjects = array();
 
        /**
@@ -1556,18 +1643,29 @@ class SwiftFileOpHandle extends FileBackendStoreOpHandle {
  * @ingroup FileBackend
  */
 abstract class SwiftFileBackendList implements Iterator {
-       /** @var Array */
+       /** @var array List of path or (path,stat array) entries */
        protected $bufferIter = array();
-       protected $bufferAfter = null; // string; list items *after* this path
-       protected $pos = 0; // integer
-       /** @var Array */
+
+       /** @var string List items *after* this path */
+       protected $bufferAfter = null;
+
+       /** @var int */
+       protected $pos = 0;
+
+       /** @var array */
        protected $params = array();
 
        /** @var SwiftFileBackend */
        protected $backend;
-       protected $container; // string; container name
-       protected $dir; // string; storage directory
-       protected $suffixStart; // integer
+
+       /** @var string Container name */
+       protected $container;
+
+       /** @var string Storage directory */
+       protected $dir;
+
+       /** @var int */
+       protected $suffixStart;
 
        const PAGE_SIZE = 9000; // file listing buffer size
 
@@ -1594,7 +1692,7 @@ abstract class SwiftFileBackendList implements Iterator {
 
        /**
         * @see Iterator::key()
-        * @return integer
+        * @return int
         */
        public function key() {
                return $this->pos;
@@ -1602,7 +1700,6 @@ abstract class SwiftFileBackendList implements Iterator {
 
        /**
         * @see Iterator::next()
-        * @return void
         */
        public function next() {
                // Advance to the next file in the page
@@ -1619,7 +1716,6 @@ abstract class SwiftFileBackendList implements Iterator {
 
        /**
         * @see Iterator::rewind()
-        * @return void
         */
        public function rewind() {
                $this->pos = 0;
@@ -1646,10 +1742,10 @@ abstract class SwiftFileBackendList implements Iterator {
         *
         * @param string $container Resolved container name
         * @param string $dir Resolved path relative to container
-        * @param string $after|null
-        * @param integer $limit
+        * @param string $after null
+        * @param int $limit
         * @param array $params
-        * @return Traversable|Array
+        * @return Traversable|array
         */
        abstract protected function pageFromList( $container, $dir, &$after, $limit, array $params );
 }
@@ -1668,7 +1764,12 @@ class SwiftFileBackendDirList extends SwiftFileBackendList {
 
        /**
         * @see SwiftFileBackendList::pageFromList()
-        * @return Array
+        * @param string $container
+        * @param string $dir
+        * @param string $after
+        * @param int $limit
+        * @param array $params
+        * @return array
         */
        protected function pageFromList( $container, $dir, &$after, $limit, array $params ) {
                return $this->backend->getDirListPageInternal( $container, $dir, $after, $limit, $params );
@@ -1684,12 +1785,24 @@ class SwiftFileBackendFileList extends SwiftFileBackendList {
         * @return string|bool String (relative path) or false
         */
        public function current() {
-               return substr( current( $this->bufferIter ), $this->suffixStart );
+               list( $path, $stat ) = current( $this->bufferIter );
+               $relPath = substr( $path, $this->suffixStart );
+               if ( is_array( $stat ) ) {
+                       $storageDir = rtrim( $this->params['dir'], '/' );
+                       $this->backend->loadListingStatInternal( "$storageDir/$relPath", $stat );
+               }
+
+               return $relPath;
        }
 
        /**
         * @see SwiftFileBackendList::pageFromList()
-        * @return Array
+        * @param string $container
+        * @param string $dir
+        * @param string $after
+        * @param int $limit
+        * @param array $params
+        * @return array
         */
        protected function pageFromList( $container, $dir, &$after, $limit, array $params ) {
                return $this->backend->getFileListPageInternal( $container, $dir, $after, $limit, $params );