MediaWiki  REL1_22
UploadStash Class Reference

UploadStash is intended to accomplish a few things: More...

Collaboration diagram for UploadStash:

List of all members.

Public Member Functions

 __construct (FileRepo $repo, $user=null)
 Represents a temporary filestore, with metadata in the database.
 clear ()
 Remove all files from the stash.
 getFile ($key, $noAuth=false)
 Get a file and its metadata from the stash.
 getFileProps ($key)
 Getter for fileProps.
 getMetadata ($key)
 Getter for file metadata.
 listFiles ()
 List all files in the stash.
 removeFile ($key)
 Remove a particular file from the stash.
 removeFileNoAuth ($key)
 Remove a file (see removeFile), but doesn't check ownership first.
 stashFile ($path, $sourceType=null)
 Stash a file in a temp directory and record that we did this in the database, along with other metadata.

Static Public Member Functions

static getExtensionForPath ($path)
 Find or guess extension -- ensuring that our extension matches our mime type.

Public Attributes

 $isLoggedIn
LocalRepo $repo
 repository that this uses to store temp files public because we sometimes need to get a LocalFile within the same repo.
 $userId
const KEY_FORMAT_REGEX = '/^[\w-\.]+\.\w*$/'

Protected Member Functions

 fetchFileMetadata ($key, $readFromDB=DB_SLAVE)
 Helper function: do the actual database query to fetch file metadata.
 initFile ($key)
 Helper function: Initialize the UploadStashFile for a given file.

Protected Attributes

 $fileMetadata = array()
 $fileProps = array()
 $files = array()
 $user

Detailed Description

UploadStash is intended to accomplish a few things:

  • enable applications to temporarily stash files without publishing them to the wiki.
    • Several parts of MediaWiki do this in similar ways: UploadBase, UploadWizard, and FirefoggChunkedExtension And there are several that reimplement stashing from scratch, in idiosyncratic ways. The idea is to unify them all here. Mostly all of them are the same except for storing some custom fields, which we subsume into the data array.
  • enable applications to find said files later, as long as the db table or temp files haven't been purged.
  • enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL. We accomplish this using a database table, with ownership checking as you might expect. See SpecialUploadStash, which implements a web interface to some files stored this way.

UploadStash right now is *mostly* intended to show you one user's slice of the entire stash. The user parameter is only optional because there are few cases where we clean out the stash from an automated script. In the future we might refactor this.

UploadStash represents the entire stash of temporary files. UploadStashFile is a filestore for the actual physical disk files. UploadFromStash extends UploadBase, and represents a single stashed file as it is moved from the stash to the regular file repository

Definition at line 44 of file UploadStash.php.


Constructor & Destructor Documentation

UploadStash::__construct ( FileRepo repo,
user = null 
)

Represents a temporary filestore, with metadata in the database.

Designed to be compatible with the session stashing code in UploadBase (should replace it eventually).

Parameters:
$repoFileRepo
$userUser (default null)

Definition at line 76 of file UploadStash.php.


Member Function Documentation

Remove all files from the stash.

Does not clean up files in the repo, just the record of them.

Exceptions:
UploadStashNotLoggedInException
Returns:
boolean: success

Definition at line 297 of file UploadStash.php.

UploadStash::fetchFileMetadata ( key,
readFromDB = DB_SLAVE 
) [protected]

Helper function: do the actual database query to fetch file metadata.

Parameters:
string$keykey
$readFromDB,:constant (default: DB_SLAVE)
Returns:
boolean

Definition at line 462 of file UploadStash.php.

static UploadStash::getExtensionForPath ( path) [static]

Find or guess extension -- ensuring that our extension matches our mime type.

Since these files are constructed from php tempnames they may not start off with an extension. XXX this is somewhat redundant with the checks that ApiUpload.php does with incoming uploads versus the desired filename. Maybe we can get that passed to us...

Parameters:
$path
Exceptions:
UploadStashFileException
Returns:
string

Definition at line 423 of file UploadStash.php.

UploadStash::getFile ( key,
noAuth = false 
)

Get a file and its metadata from the stash.

The noAuth param is a bit janky but is required for automated scripts which clean out the stash.

Parameters:
string$keykey under which file information is stored
$noAuthBoolean (optional) Don't check authentication. Used by maintenance scripts.
Exceptions:
UploadStashFileNotFoundException
UploadStashNotLoggedInException
UploadStashWrongOwnerException
UploadStashBadPathException
Returns:
UploadStashFile

Definition at line 107 of file UploadStash.php.

Getter for fileProps.

Parameters:
string$keykey under which file information is stored
Returns:
Array

Definition at line 171 of file UploadStash.php.

Getter for file metadata.

Parameters:
string$keykey under which file information is stored
Returns:
Array

Definition at line 160 of file UploadStash.php.

UploadStash::initFile ( key) [protected]

Helper function: Initialize the UploadStashFile for a given file.

Parameters:
string$keykey under which to store the object
Exceptions:
UploadStashZeroLengthFileException
Returns:
bool

Definition at line 496 of file UploadStash.php.

List all files in the stash.

Exceptions:
UploadStashNotLoggedInException
Returns:
Array

Definition at line 386 of file UploadStash.php.

Remove a particular file from the stash.

Also removes it from the repo.

Parameters:
$key
Exceptions:
UploadStashNoSuchKeyException|UploadStashNotLoggedInException|UploadStashWrongOwnerException
Returns:
boolean: success

Definition at line 324 of file UploadStash.php.

Remove a file (see removeFile), but doesn't check ownership first.

Returns:
boolean: success

Definition at line 356 of file UploadStash.php.

UploadStash::stashFile ( path,
sourceType = null 
)

Stash a file in a temp directory and record that we did this in the database, along with other metadata.

Parameters:
string$pathpath to file you want stashed
string$sourceTypethe type of upload that generated this file (currently, I believe, 'file' or null)
Exceptions:
UploadStashBadPathException
UploadStashFileException
UploadStashNotLoggedInException
Returns:
UploadStashFile: file, or null on failure

Definition at line 186 of file UploadStash.php.


Member Data Documentation

UploadStash::$fileMetadata = array() [protected]

Definition at line 60 of file UploadStash.php.

UploadStash::$fileProps = array() [protected]

Definition at line 63 of file UploadStash.php.

UploadStash::$files = array() [protected]

Definition at line 57 of file UploadStash.php.

UploadStash::$isLoggedIn

Definition at line 66 of file UploadStash.php.

LocalRepo UploadStash::$repo

repository that this uses to store temp files public because we sometimes need to get a LocalFile within the same repo.

Definition at line 54 of file UploadStash.php.

UploadStash::$user [protected]

Definition at line 66 of file UploadStash.php.

UploadStash::$userId

Definition at line 66 of file UploadStash.php.

const UploadStash::KEY_FORMAT_REGEX = '/^[\w-\.]+\.\w*$/'

Definition at line 47 of file UploadStash.php.

Referenced by UploadFromStash\isValidKey().


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