https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112958
Revision: 112958
Author: aaron
Date: 2012-03-03 19:14:50 +0000 (Sat, 03 Mar 2012)
Log Message:
-----------
[FileBackend]
* Various documentation improvements.
* Moved a few protected FileBackendStoreShardListIterator functions down. Same
with normalizeContainerPath().
Modified Paths:
--------------
trunk/phase3/includes/filerepo/backend/FSFileBackend.php
trunk/phase3/includes/filerepo/backend/FileBackend.php
trunk/phase3/includes/filerepo/backend/FileBackendStore.php
trunk/phase3/includes/filerepo/backend/SwiftFileBackend.php
trunk/phase3/includes/filerepo/backend/lockmanager/FSLockManager.php
trunk/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php
trunk/phase3/includes/filerepo/backend/lockmanager/LockManager.php
Modified: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
===================================================================
--- trunk/phase3/includes/filerepo/backend/FSFileBackend.php 2012-03-03
19:13:40 UTC (rev 112957)
+++ trunk/phase3/includes/filerepo/backend/FSFileBackend.php 2012-03-03
19:14:50 UTC (rev 112958)
@@ -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 @@
}
}
+ /**
+ * @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 @@
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 @@
++$this->pos;
}
+ /**
+ * @see Iterator::rewind()
+ * @return void
+ */
public function rewind() {
$this->pos = 0;
try {
@@ -608,6 +624,10 @@
}
}
+ /**
+ * @see Iterator::valid()
+ * @return bool
+ */
public function valid() {
return $this->iter && $this->iter->valid();
}
Modified: trunk/phase3/includes/filerepo/backend/FileBackend.php
===================================================================
--- trunk/phase3/includes/filerepo/backend/FileBackend.php 2012-03-03
19:13:40 UTC (rev 112957)
+++ trunk/phase3/includes/filerepo/backend/FileBackend.php 2012-03-03
19:14:50 UTC (rev 112958)
@@ -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.
@@ -658,6 +658,31 @@
}
/**
+ * 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.
* Traversal is insecure for FS backends and broken for others.
@@ -687,29 +712,4 @@
}
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 ) : '' );
- }
}
Modified: trunk/phase3/includes/filerepo/backend/FileBackendStore.php
===================================================================
--- trunk/phase3/includes/filerepo/backend/FileBackendStore.php 2012-03-03
19:13:40 UTC (rev 112957)
+++ trunk/phase3/includes/filerepo/backend/FileBackendStore.php 2012-03-03
19:14:50 UTC (rev 112958)
@@ -997,6 +997,10 @@
$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 @@
}
}
+ /**
+ * @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 @@
}
/**
- * 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 @@
$this->nextShardIteratorIfNotValid();
}
+ /**
+ * @see Iterator::valid()
+ * @return bool
+ */
public function valid() {
if ( $this->iter == null ) {
return false; // some failure?
@@ -1057,4 +1057,27 @@
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 );
+ }
}
Modified: trunk/phase3/includes/filerepo/backend/SwiftFileBackend.php
===================================================================
--- trunk/phase3/includes/filerepo/backend/SwiftFileBackend.php 2012-03-03
19:13:40 UTC (rev 112957)
+++ trunk/phase3/includes/filerepo/backend/SwiftFileBackend.php 2012-03-03
19:14:50 UTC (rev 112958)
@@ -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 @@
}
}
+ /**
+ * @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 @@
}
}
+ /**
+ * @see Iterator::rewind()
+ * @return void
+ */
public function rewind() {
$this->pos = 0;
$this->bufferAfter = null;
@@ -886,6 +902,10 @@
);
}
+ /**
+ * @see Iterator::valid()
+ * @return bool
+ */
public function valid() {
return ( current( $this->bufferIter ) !== false ); // no paths
can have this value
}
Modified: trunk/phase3/includes/filerepo/backend/lockmanager/FSLockManager.php
===================================================================
--- trunk/phase3/includes/filerepo/backend/lockmanager/FSLockManager.php
2012-03-03 19:13:40 UTC (rev 112957)
+++ trunk/phase3/includes/filerepo/backend/lockmanager/FSLockManager.php
2012-03-03 19:14:50 UTC (rev 112958)
@@ -38,6 +38,10 @@
$this->lockDir = $config['lockDirectory'];
}
+ /**
+ * @see LockManager::doLock()
+ * @return Status
+ */
protected function doLock( array $paths, $type ) {
$status = Status::newGood();
@@ -56,6 +60,10 @@
return $status;
}
+ /**
+ * @see LockManager::doUnlock()
+ * @return Status
+ */
protected function doUnlock( array $paths, $type ) {
$status = Status::newGood();
Modified: trunk/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php
===================================================================
--- trunk/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php
2012-03-03 19:13:40 UTC (rev 112957)
+++ trunk/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php
2012-03-03 19:14:50 UTC (rev 112958)
@@ -68,6 +68,10 @@
$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 @@
return $status;
}
+ /**
+ * @see LockManager::doUnlock()
+ * @return Status
+ */
protected function doUnlock( array $paths, $type ) {
$status = Status::newGood();
Modified: trunk/phase3/includes/filerepo/backend/lockmanager/LockManager.php
===================================================================
--- trunk/phase3/includes/filerepo/backend/lockmanager/LockManager.php
2012-03-03 19:13:40 UTC (rev 112957)
+++ trunk/phase3/includes/filerepo/backend/lockmanager/LockManager.php
2012-03-03 19:14:50 UTC (rev 112958)
@@ -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 @@
* @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();
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs