FileStore Class Reference

List of all members.

Public Member Functions

 insert ($key, $sourcePath, $flags=0)
 Copy a file into the file store from elsewhere in the filesystem.
 export ($key, $destPath, $flags=0)
 Copy a file from the file store to elsewhere in the filesystem.
 delete ($key)
 Delete a file from the file store.
 stream ($key)
 Stream a contained file directly to HTTP output.
 filePath ($key)
 Return filesystem path to the given file.
 urlPath ($key)
 Return URL path to the given file, if the store is public.

Static Public Member Functions

static get ($group)
 Fetch the FileStore object for a given storage group.
static lock ()
 Acquire a lock; use when performing write operations on a store.
static unlock ()
 Release the global file store lock.
static deleteFile ($path)
 Delete a non-managed file on a transactional basis.
static validKey ($key)
 Confirm that the given file key is valid.
static calculateKey ($path, $extension)
 Calculate file storage key from a file on disk.

Public Attributes

const DELETE_ORIGINAL = 1

Private Member Functions

 __construct ($group, $directory, $path, $hash)
 copyFile ($sourcePath, $destPath, $flags=0)
 hashPath ($key, $separator)

Static Private Member Functions

static lockName ()


Detailed Description

Todo:
document (needs one-sentence top-level class description).

Definition at line 6 of file FileStore.php.


Constructor & Destructor Documentation

FileStore::__construct ( group,
directory,
path,
hash 
) [private]

Definition at line 26 of file FileStore.php.

References $path.


Member Function Documentation

static FileStore::calculateKey ( path,
extension 
) [static]

Calculate file storage key from a file on disk.

You must pass an extension to it, as some files may be calculated out of a temporary file etc.

Parameters:
$path to file
$extension 
Returns:
string or false if could not open file or bad extension

Definition at line 226 of file FileStore.php.

References $key, $path, wfBaseConvert(), wfDebug(), wfRestoreWarnings(), and wfSuppressWarnings().

FileStore::copyFile ( sourcePath,
destPath,
flags = 0 
) [private]

FileStore::delete ( key  ) 

Delete a file from the file store.

Caller's responsibility to make sure it's not being used by another row.

File is not actually removed until transaction commit. Should be protected by FileStore::lock() to avoid race conditions.

Parameters:
$key storage key string
Exceptions:
FSException if file can't be deleted
Returns:
FSTransaction

Definition at line 145 of file FileStore.php.

References $key, deleteFile(), and filePath().

static FileStore::deleteFile ( path  )  [static]

Delete a non-managed file on a transactional basis.

File is not actually removed until transaction commit. Should be protected by FileStore::lock() to avoid race conditions.

Parameters:
$path file to remove
Exceptions:
FSException if file can't be deleted
Returns:
FSTransaction
Todo:
Might be worth preliminary permissions check

Definition at line 166 of file FileStore.php.

References $path, and FSTransaction::DELETE_FILE.

Referenced by delete().

FileStore::export ( key,
destPath,
flags = 0 
)

Copy a file from the file store to elsewhere in the filesystem.

Should be protected by FileStore::lock() to avoid race conditions.

Parameters:
$key storage key string
$flags DELETE_ORIGINAL - remove the source file on transaction commit.
Exceptions:
FSException if copy can't be completed
Returns:
FSTransaction on success

Definition at line 87 of file FileStore.php.

References $flags, $key, copyFile(), and filePath().

FileStore::filePath ( key  ) 

Return filesystem path to the given file.

Note that the file may or may not exist.

Returns:
string or false if an invalid key

Definition at line 256 of file FileStore.php.

References $key, and hashPath().

Referenced by delete(), export(), insert(), and stream().

static FileStore::get ( group  )  [static]

FileStore::hashPath ( key,
separator 
) [private]

Definition at line 277 of file FileStore.php.

References $i, and $key.

Referenced by filePath(), and urlPath().

FileStore::insert ( key,
sourcePath,
flags = 0 
)

Copy a file into the file store from elsewhere in the filesystem.

Should be protected by FileStore::lock() to avoid race conditions.

Parameters:
$key storage key string
$flags DELETE_ORIGINAL - remove the source file on transaction commit.
Exceptions:
FSException if copy can't be completed
Returns:
FSTransaction

Definition at line 71 of file FileStore.php.

References $flags, $key, copyFile(), and filePath().

static FileStore::lock (  )  [static]

Acquire a lock; use when performing write operations on a store.

This is attached to your master database connection, so if you suffer an uncaught error the lock will be released when the connection is closed.

See also:
Database::lock()

Definition at line 40 of file FileStore.php.

References $dbw, lockName(), and wfGetDB().

Referenced by DeleteArchivedFiles(), RevisionDeleter::makeOldImagePrivate(), and RevisionDeleter::makeOldImagePublic().

static FileStore::lockName (  )  [static, private]

Definition at line 56 of file FileStore.php.

References wfWikiID().

Referenced by lock(), and unlock().

FileStore::stream ( key  ) 

Stream a contained file directly to HTTP output.

Will throw a 404 if file is missing; 400 if invalid key.

Returns:
true on success, false on failure

Definition at line 181 of file FileStore.php.

References $key, $path, filePath(), wfHttpError(), and wfStreamFile().

static FileStore::unlock (  )  [static]

Release the global file store lock.

See also:
Database::unlock()

Definition at line 50 of file FileStore.php.

References $dbw, lockName(), and wfGetDB().

Referenced by RevisionDeleter::makeOldImagePrivate(), and RevisionDeleter::makeOldImagePublic().

FileStore::urlPath ( key  ) 

Return URL path to the given file, if the store is public.

Returns:
string or false if not public

Definition at line 269 of file FileStore.php.

References $key, and hashPath().

static FileStore::validKey ( key  )  [static]

Confirm that the given file key is valid.

Note that a valid key may refer to a file that does not exist.

Key should consist of a 31-digit base-36 SHA-1 hash and an optional alphanumeric extension, all lowercase. The whole must not exceed 64 characters.

Parameters:
$key 
Returns:
boolean

Definition at line 212 of file FileStore.php.

References $key.


Member Data Documentation


The documentation for this class was generated from the following file:

Generated on Sat Sep 5 02:08:37 2009 for MediaWiki by  doxygen 1.5.9