[FileBackend]
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 3 Mar 2012 19:14:50 +0000 (19:14 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 3 Mar 2012 19:14:50 +0000 (19:14 +0000)
* Various documentation improvements.
* Moved a few protected FileBackendStoreShardListIterator functions down. Same with normalizeContainerPath().

includes/filerepo/backend/FSFileBackend.php
includes/filerepo/backend/FileBackend.php
includes/filerepo/backend/FileBackendStore.php
includes/filerepo/backend/SwiftFileBackend.php
includes/filerepo/backend/lockmanager/FSLockManager.php
includes/filerepo/backend/lockmanager/LSLockManager.php
includes/filerepo/backend/lockmanager/LockManager.php

index b863d32..4a27ca1 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 /**
- * Class for a file system (FS) based file backend.
+ * @brief Class for a file system (FS) based file backend.
  * 
  * All "containers" each map to a directory under the backend's base directory.
  * For backwards-compatibility, some container paths can be set to custom paths.
@@ -579,6 +579,10 @@ class FSFileBackendFileList implements Iterator {
                }
        }
 
+       /**
+        * @see Iterator::current()
+        * @return string|bool String or false
+        */
        public function current() {
                // Return only the relative path and normalize slashes to FileBackend-style
                // Make sure to use the realpath since the suffix is based upon that
@@ -586,10 +590,18 @@ class FSFileBackendFileList implements Iterator {
                        substr( realpath( $this->iter->current() ), $this->suffixStart ) );
        }
 
+       /**
+        * @see Iterator::key()
+        * @return integer
+        */
        public function key() {
                return $this->pos;
        }
 
+       /**
+        * @see Iterator::next()
+        * @return void
+        */
        public function next() {
                try {
                        $this->iter->next();
@@ -599,6 +611,10 @@ class FSFileBackendFileList implements Iterator {
                ++$this->pos;
        }
 
+       /**
+        * @see Iterator::rewind()
+        * @return void
+        */
        public function rewind() {
                $this->pos = 0;
                try {
@@ -608,6 +624,10 @@ class FSFileBackendFileList implements Iterator {
                }
        }
 
+       /**
+        * @see Iterator::valid()
+        * @return bool
+        */
        public function valid() {
                return $this->iter && $this->iter->valid();
        }
index 35539c5..227941e 100644 (file)
@@ -14,7 +14,7 @@
  */
 
 /**
- * Base class for all file backend classes (including multi-write backends).
+ * @brief Base class for all file backend classes (including multi-write backends).
  *
  * This class defines the methods as abstract that subclasses must implement.
  * Outside callers can assume that all backends will have these functions.
@@ -657,6 +657,31 @@ abstract class FileBackend {
                return null;
        }
 
+       /**
+        * Get the parent storage directory of a storage path.
+        * This returns a path like "mwstore://backend/container",
+        * "mwstore://backend/container/...", or null if there is no parent.
+        * 
+        * @param $storagePath string
+        * @return string|null
+        */
+       final public static function parentStoragePath( $storagePath ) {
+               $storagePath = dirname( $storagePath );
+               list( $b, $cont, $rel ) = self::splitStoragePath( $storagePath );
+               return ( $rel === null ) ? null : $storagePath;
+       }
+
+       /**
+        * Get the final extension from a storage or FS path
+        * 
+        * @param $path string
+        * @return string
+        */
+       final public static function extensionFromPath( $path ) {
+               $i = strrpos( $path, '.' );
+               return strtolower( $i ? substr( $path, $i + 1 ) : '' );
+       }
+
        /**
         * Validate and normalize a relative storage path.
         * Null is returned if the path involves directory traversal.
@@ -687,29 +712,4 @@ abstract class FileBackend {
                }
                return $path;
        }
-
-       /**
-        * Get the parent storage directory of a storage path.
-        * This returns a path like "mwstore://backend/container",
-        * "mwstore://backend/container/...", or null if there is no parent.
-        * 
-        * @param $storagePath string
-        * @return string|null
-        */
-       final public static function parentStoragePath( $storagePath ) {
-               $storagePath = dirname( $storagePath );
-               list( $b, $cont, $rel ) = self::splitStoragePath( $storagePath );
-               return ( $rel === null ) ? null : $storagePath;
-       }
-
-       /**
-        * Get the final extension from a storage or FS path
-        * 
-        * @param $path string
-        * @return string
-        */
-       final public static function extensionFromPath( $path ) {
-               $i = strrpos( $path, '.' );
-               return strtolower( $i ? substr( $path, $i + 1 ) : '' );
-       }
 }
index d395eac..4f4a185 100644 (file)
@@ -997,6 +997,10 @@ class FileBackendStoreShardListIterator implements Iterator {
                $this->params = $params;
        }
 
+       /**
+        * @see Iterator::current()
+        * @return string|bool String or false
+        */
        public function current() {
                if ( is_array( $this->iter ) ) {
                        return current( $this->iter );
@@ -1005,10 +1009,18 @@ class FileBackendStoreShardListIterator implements Iterator {
                }
        }
 
+       /**
+        * @see Iterator::key()
+        * @return integer
+        */
        public function key() {
                return $this->pos;
        }
 
+       /**
+        * @see Iterator::next()
+        * @return void
+        */
        public function next() {
                ++$this->pos;
                if ( is_array( $this->iter ) ) {
@@ -1021,25 +1033,9 @@ class FileBackendStoreShardListIterator implements Iterator {
        }
 
        /**
-        * If the iterator for this container shard is out of items,
-        * then move on to the next container that has items.
-        * If there are none, then it advances to the last container.
+        * @see Iterator::rewind()
+        * @return void
         */
-       protected function nextShardIteratorIfNotValid() {
-               while ( !$this->valid() ) {
-                       if ( ++$this->curShard >= count( $this->shardSuffixes ) ) {
-                               break; // no more container shards
-                       }
-                       $this->setIteratorFromCurrentShard();
-               }
-       }
-
-       protected function setIteratorFromCurrentShard() {
-               $suffix = $this->shardSuffixes[$this->curShard];
-               $this->iter = $this->backend->getFileListInternal(
-                       "{$this->container}{$suffix}", $this->directory, $this->params );
-       }
-
        public function rewind() {
                $this->pos = 0;
                $this->curShard = 0;
@@ -1048,6 +1044,10 @@ class FileBackendStoreShardListIterator implements Iterator {
                $this->nextShardIteratorIfNotValid();
        }
 
+       /**
+        * @see Iterator::valid()
+        * @return bool
+        */
        public function valid() {
                if ( $this->iter == null ) {
                        return false; // some failure?
@@ -1057,4 +1057,27 @@ class FileBackendStoreShardListIterator implements Iterator {
                        return $this->iter->valid();
                }
        }
+
+       /**
+        * If the list iterator for this container shard is out of items,
+        * then move on to the next container that has items.
+        * If there are none, then it advances to the last container.
+        */
+       protected function nextShardIteratorIfNotValid() {
+               while ( !$this->valid() ) {
+                       if ( ++$this->curShard >= count( $this->shardSuffixes ) ) {
+                               break; // no more container shards
+                       }
+                       $this->setIteratorFromCurrentShard();
+               }
+       }
+
+       /**
+        * Set the list iterator to that of the current container shard
+        */
+       protected function setIteratorFromCurrentShard() {
+               $suffix = $this->shardSuffixes[$this->curShard];
+               $this->iter = $this->backend->getFileListInternal(
+                       "{$this->container}{$suffix}", $this->directory, $this->params );
+       }
 }
index 86ab1be..3ad78e3 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 /**
- * Class for an OpenStack Swift based file backend.
+ * @brief Class for an OpenStack Swift based file backend.
  *
  * This requires the SwiftCloudFiles MediaWiki extension, which includes
  * the php-cloudfiles library (https://github.com/rackspace/php-cloudfiles).
@@ -856,14 +856,26 @@ class SwiftFileBackendFileList implements Iterator {
                }
        }
 
+       /**
+        * @see Iterator::current()
+        * @return string|bool String or false
+        */
        public function current() {
                return substr( current( $this->bufferIter ), $this->suffixStart );
        }
 
+       /**
+        * @see Iterator::key()
+        * @return integer
+        */
        public function key() {
                return $this->pos;
        }
 
+       /**
+        * @see Iterator::next()
+        * @return void
+        */
        public function next() {
                // Advance to the next file in the page
                next( $this->bufferIter );
@@ -878,6 +890,10 @@ class SwiftFileBackendFileList implements Iterator {
                }
        }
 
+       /**
+        * @see Iterator::rewind()
+        * @return void
+        */
        public function rewind() {
                $this->pos = 0;
                $this->bufferAfter = null;
@@ -886,6 +902,10 @@ class SwiftFileBackendFileList implements Iterator {
                );
        }
 
+       /**
+        * @see Iterator::valid()
+        * @return bool
+        */
        public function valid() {
                return ( current( $this->bufferIter ) !== false ); // no paths can have this value
        }
index 42074fd..c14b8d0 100644 (file)
@@ -38,6 +38,10 @@ class FSLockManager extends LockManager {
                $this->lockDir = $config['lockDirectory'];
        }
 
+       /**
+        * @see LockManager::doLock()
+        * @return Status
+        */
        protected function doLock( array $paths, $type ) {
                $status = Status::newGood();
 
@@ -56,6 +60,10 @@ class FSLockManager extends LockManager {
                return $status;
        }
 
+       /**
+        * @see LockManager::doUnlock()
+        * @return Status
+        */
        protected function doUnlock( array $paths, $type ) {
                $status = Status::newGood();
 
index c1b741f..a77c3a2 100644 (file)
@@ -68,6 +68,10 @@ class LSLockManager extends LockManager {
                $this->session = wfBaseConvert( sha1( $this->session ), 16, 36, 31 );
        }
 
+       /**
+        * @see LockManager::doLock()
+        * @return Status
+        */
        protected function doLock( array $paths, $type ) {
                $status = Status::newGood();
 
@@ -117,6 +121,10 @@ class LSLockManager extends LockManager {
                return $status;
        }
 
+       /**
+        * @see LockManager::doUnlock()
+        * @return Status
+        */
        protected function doUnlock( array $paths, $type ) {
                $status = Status::newGood();
 
index be071c5..506d850 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 /**
- * Class for handling resource locking.
+ * @brief Class for handling resource locking.
  *
  * Locks on resource keys can either be shared or exclusive.
  *
@@ -178,10 +178,18 @@ class ScopedLock {
  * @since 1.19
  */
 class NullLockManager extends LockManager {
+       /**
+        * @see LockManager::doLock()
+        * @return Status
+        */
        protected function doLock( array $paths, $type ) {
                return Status::newGood();
        }
 
+       /**
+        * @see LockManager::doUnlock()
+        * @return Status
+        */
        protected function doUnlock( array $paths, $type ) {
                return Status::newGood();
        }