aboutsummaryrefslogtreecommitdiffstats
path: root/includes/filebackend
diff options
context:
space:
mode:
authorAaron Schulz <aschulz@wikimedia.org>2012-11-06 12:49:40 -0800
committerGerrit Code Review <gerrit@wikimedia.org>2012-11-08 23:01:19 +0000
commit9f95bddda711da1567be0e4ad2781eefba320e1e (patch)
tree40c20d3b288bd87bcd2ef4e7e44683aa5b20f8e2 /includes/filebackend
parent700e0ee0669fc267c597a12d5a1f30c0454b1d95 (diff)
downloadmediawikicore-9f95bddda711da1567be0e4ad2781eefba320e1e.tar.gz
mediawikicore-9f95bddda711da1567be0e4ad2781eefba320e1e.zip
[FileBackend] Added getFileHttpUrl() function.
* This can speed up certain video file operations for scripts that support specifying source files via URLs and support HTTP Range headers. * Updated unit tests. Change-Id: I60cb95c2e3dd9f7df1f740e9182be7c79af69d6e
Diffstat (limited to 'includes/filebackend')
-rw-r--r--includes/filebackend/FileBackend.php18
-rw-r--r--includes/filebackend/FileBackendMultiWrite.php9
-rw-r--r--includes/filebackend/FileBackendStore.php8
-rw-r--r--includes/filebackend/SwiftFileBackend.php28
4 files changed, 63 insertions, 0 deletions
diff --git a/includes/filebackend/FileBackend.php b/includes/filebackend/FileBackend.php
index e01bfc2e5bb0..b5e231540b5d 100644
--- a/includes/filebackend/FileBackend.php
+++ b/includes/filebackend/FileBackend.php
@@ -905,6 +905,24 @@ abstract class FileBackend {
abstract public function getLocalCopyMulti( array $params );
/**
+ * Return an HTTP URL to a given file that requires no authentication to use.
+ * The URL may be pre-authenticated (via some token in the URL) and temporary.
+ * This will return null if the backend cannot make an HTTP URL for the file.
+ *
+ * This is useful for key/value stores when using scripts that seek around
+ * large files and those scripts (and the backend) support HTTP Range headers.
+ * Otherwise, one would need to use getLocalReference(), which involves loading
+ * the entire file on to local disk.
+ *
+ * @param $params Array
+ * $params include:
+ * - src : source storage path
+ * @return string|null
+ * @since 1.21
+ */
+ abstract public function getFileHttpUrl( array $params );
+
+ /**
* Check if a directory exists at a given storage path.
* Backends using key/value stores will check if the path is a
* virtual directory, meaning there are files under the given directory.
diff --git a/includes/filebackend/FileBackendMultiWrite.php b/includes/filebackend/FileBackendMultiWrite.php
index 90292ee0270a..a443a3aadd92 100644
--- a/includes/filebackend/FileBackendMultiWrite.php
+++ b/includes/filebackend/FileBackendMultiWrite.php
@@ -652,6 +652,15 @@ class FileBackendMultiWrite extends FileBackend {
}
/**
+ * @see FileBackend::getFileHttpUrl()
+ * @return string|null
+ */
+ public function getFileHttpUrl( array $params ) {
+ $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+ return $this->backends[$this->masterIndex]->getFileHttpUrl( $realParams );
+ }
+
+ /**
* @see FileBackend::directoryExists()
* @param $params array
* @return bool|null
diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php
index 7e91949e68d5..97e49a5a0925 100644
--- a/includes/filebackend/FileBackendStore.php
+++ b/includes/filebackend/FileBackendStore.php
@@ -805,6 +805,14 @@ abstract class FileBackendStore extends FileBackend {
abstract protected function doGetLocalCopyMulti( array $params );
/**
+ * @see FileBackend::getFileHttpUrl()
+ * @return string|null
+ */
+ public function getFileHttpUrl( array $params ) {
+ return null; // not supported
+ }
+
+ /**
* @see FileBackend::streamFile()
* @return Status
*/
diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php
index 8441f8fc8ec9..48db9d3c3f12 100644
--- a/includes/filebackend/SwiftFileBackend.php
+++ b/includes/filebackend/SwiftFileBackend.php
@@ -40,6 +40,7 @@ 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
@@ -66,6 +67,8 @@ class SwiftFileBackend extends FileBackendStore {
* - swiftUser : Swift user used by MediaWiki (account:username)
* - swiftKey : Swift authentication key for the above user
* - swiftAuthTTL : Swift authentication TTL (seconds)
+ * - swiftTempUrlKey : Swift "X-Account-Meta-Temp-URL-Key" value on the account.
+ * Do not set this until it has been set in the backend.
* - swiftAnonUser : Swift user used for end-user requests (account:username).
* If set, then views of public containers are assumed to go
* through this user. If not set, then public containers are
@@ -104,6 +107,9 @@ class SwiftFileBackend extends FileBackendStore {
$this->swiftAnonUser = isset( $config['swiftAnonUser'] )
? $config['swiftAnonUser']
: '';
+ $this->swiftTempUrlKey = isset( $config['swiftTempUrlKey'] )
+ ? $config['swiftTempUrlKey']
+ : '';
$this->shardViaHashLevels = isset( $config['shardViaHashLevels'] )
? $config['shardViaHashLevels']
: '';
@@ -1120,6 +1126,28 @@ class SwiftFileBackend extends FileBackendStore {
}
/**
+ * @see FileBackendStore::getFileHttpUrl()
+ * @return string|null
+ */
+ public function getFileHttpUrl( array $params ) {
+ if ( $this->swiftTempUrlKey != '' ) { // temp urls enabled
+ list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
+ if ( $srcRel === null ) {
+ return null; // invalid path
+ }
+ try {
+ $sContObj = $this->getContainer( $srcCont );
+ $obj = new CF_Object( $sContObj, $srcRel, false, false ); // skip HEAD
+ return $obj->get_temp_url( $this->swiftTempUrlKey, 86400, "GET" );
+ } catch ( NoSuchContainerException $e ) {
+ } catch ( CloudFilesException $e ) { // some other exception?
+ $this->handleException( $e, null, __METHOD__, $params );
+ }
+ }
+ return null;
+ }
+
+ /**
* @see FileBackendStore::directoriesAreVirtual()
* @return bool
*/