MediaWiki  master
UploadStash Class Reference

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

Collaboration diagram for UploadStash:

Public Member Functions

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

Static Public Member Functions

static getExtensionForPath ( $path)
 Find or guess extension – ensuring that our extension matches our MIME type. More...
 

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. More...
 
 $userId
 
const KEY_FORMAT_REGEX = '/^[\w\-\.]+\.\w*$/'
 
const MAX_US_PROPS_SIZE = 65535
 

Protected Member Functions

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

Protected Attributes

 $fileMetadata = []
 
 $fileProps = []
 
 $files = []
 
 $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 53 of file UploadStash.php.

Constructor & Destructor Documentation

◆ __construct()

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
FileRepo$repo
User | null$user

Definition at line 86 of file UploadStash.php.

References $repo, $user, and user.

Member Function Documentation

◆ clear()

UploadStash::clear ( )

Remove all files from the stash.

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

Exceptions
UploadStashNotLoggedInException
Returns
bool Success

Definition at line 338 of file UploadStash.php.

References files(), wfDebug(), and wfMessage().

◆ fetchFileMetadata()

UploadStash::fetchFileMetadata (   $key,
  $readFromDB = DB_REPLICA 
)
protected

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

Parameters
string$key
int$readFromDBConstant (default: DB_REPLICA)
Returns
bool

Definition at line 519 of file UploadStash.php.

References $dbr, DB_MASTER, and null.

Referenced by getFile().

◆ getExtensionForPath()

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
string$path
Exceptions
UploadStashFileException
Returns
string

Definition at line 477 of file UploadStash.php.

References $path, $wgFileBlacklist, MediaWiki\MediaWikiServices\getInstance(), File\normalizeExtension(), null, and wfMessage().

◆ getFile()

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
bool$noAuth(optional) Don't check authentication. Used by maintenance scripts.
Exceptions
UploadStashFileNotFoundException
UploadStashNotLoggedInException
UploadStashWrongOwnerException
UploadStashBadPathException
Returns
UploadStashFile

Definition at line 114 of file UploadStash.php.

References $path, DB_MASTER, fetchFileMetadata(), files(), initFile(), unserialize(), wfDebug(), and wfMessage().

Referenced by getFileProps(), getMetadata(), removeFileNoAuth(), and stashFile().

◆ getFileProps()

UploadStash::getFileProps (   $key)

Getter for fileProps.

Parameters
string$keyKey under which file information is stored
Returns
array

Definition at line 188 of file UploadStash.php.

References getFile().

◆ getMetadata()

UploadStash::getMetadata (   $key)

Getter for file metadata.

Parameters
string$keyKey under which file information is stored
Returns
array

Definition at line 176 of file UploadStash.php.

References getFile().

◆ initFile()

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 559 of file UploadStash.php.

References $file, files(), and wfMessage().

Referenced by getFile(), and stashFile().

◆ listFiles()

UploadStash::listFiles ( )

List all files in the stash.

Exceptions
UploadStashNotLoggedInException
Returns
array|false

Definition at line 438 of file UploadStash.php.

References $dbr, $keys, $res, as, and wfMessage().

◆ removeFile()

UploadStash::removeFile (   $key)

Remove a particular file from the stash.

Also removes it from the repo.

Parameters
string$key
Exceptions
UploadStashNoSuchKeyException|UploadStashNotLoggedInException
UploadStashWrongOwnerException
Returns
bool Success

Definition at line 368 of file UploadStash.php.

References removeFileNoAuth(), and wfMessage().

◆ removeFileNoAuth()

UploadStash::removeFileNoAuth (   $key)

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

Parameters
string$key
Returns
bool Success

Definition at line 407 of file UploadStash.php.

References files(), getFile(), and wfDebug().

Referenced by removeFile().

◆ stashFile()

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 | null$sourceTypeThe type of upload that generated this file (currently, I believe, 'file' or null)
Exceptions
UploadStashBadPathException
UploadStashFileException
UploadStashNotLoggedInException
Returns
UploadStashFile|null File, or null on failure

Definition at line 206 of file UploadStash.php.

References $fileProps, $path, $userId, getFile(), initFile(), list, serialize(), wfDebug(), and wfMessage().

Member Data Documentation

◆ $fileMetadata

UploadStash::$fileMetadata = []
protected

Definition at line 70 of file UploadStash.php.

◆ $fileProps

UploadStash::$fileProps = []
protected

Definition at line 73 of file UploadStash.php.

Referenced by stashFile().

◆ $files

UploadStash::$files = []
protected

Definition at line 67 of file UploadStash.php.

◆ $isLoggedIn

UploadStash::$isLoggedIn

Definition at line 76 of file UploadStash.php.

◆ $repo

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 64 of file UploadStash.php.

Referenced by __construct().

◆ $user

UploadStash::$user
protected

Definition at line 76 of file UploadStash.php.

Referenced by __construct().

◆ $userId

UploadStash::$userId

Definition at line 76 of file UploadStash.php.

Referenced by stashFile().

◆ KEY_FORMAT_REGEX

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

Definition at line 55 of file UploadStash.php.

Referenced by UploadFromStash\isValidKey().

◆ MAX_US_PROPS_SIZE

const UploadStash::MAX_US_PROPS_SIZE = 65535

Definition at line 56 of file UploadStash.php.


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