MediaWiki master
MediaWiki\Upload\UploadStash Class Reference

UploadStash provides temporary file storage for users, persisting across multiple requests. More...

Collaboration diagram for MediaWiki\Upload\UploadStash:

Public Member Functions

 __construct (LocalRepo $repo, ?UserIdentity $user=null)
 
 clear ()
 Remove all files from the stash.
 
 getFile ( $key, $noAuth=false)
 Get a file and its metadata from the stash.
 
 getFileProps ( $key)
 Get file properties.
 
 getMetadata ( $key)
 Get file metadata.
 
 listFiles ()
 List all files in the stash.
 
 removeFile ( $key)
 Remove a particular file from the stash and the repo.
 
 removeFileNoAuth ( $key)
 Remove a file, but doesn't check ownership first.
 
 stashFile ( $path, $sourceType=null, $fileProps=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

LocalRepo $repo
 Repository that this uses to store temp files.
 
const KEY_FORMAT_REGEX = '/^[\w\-\.]+\.\w*$/'
 

Protected Member Functions

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

Protected Attributes

array $fileMetadata = []
 Cache of uploadstash rows indexed by stash key.
 
array $fileProps = []
 Cache of unserialized file properties (us_props) indexed by stash key.
 
UploadStashFile[] $files = []
 Array of initialized file objects.
 

Detailed Description

UploadStash provides temporary file storage for users, persisting across multiple requests.

Files are stored in FileRepo and tracked in the database.

Stashed files are private. Read access is only provided to the creator.

Definition at line 36 of file UploadStash.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Upload\UploadStash::__construct ( LocalRepo $repo,
?UserIdentity $user = null )
Parameters
LocalRepo$repoThe repo to use for file storage
UserIdentity | null$userThe user whose stash this is, or null to use the request context user

Definition at line 66 of file UploadStash.php.

References MediaWiki\Upload\UploadStash\$repo.

Member Function Documentation

◆ clear()

MediaWiki\Upload\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 297 of file UploadStash.php.

References wfDebug(), and wfMessage().

◆ fetchFileMetadata()

MediaWiki\Upload\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 449 of file UploadStash.php.

References DB_PRIMARY.

Referenced by MediaWiki\Upload\UploadStash\getFile().

◆ getExtensionForPath()

static MediaWiki\Upload\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
Returns
string

Definition at line 416 of file UploadStash.php.

References $path, MediaWiki\MediaWikiServices\getInstance(), and MediaWiki\MainConfigNames\ProhibitedFileExtensions.

Referenced by MediaWiki\Upload\UploadStash\stashFile().

◆ getFile()

MediaWiki\Upload\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$keyThe stash key from UploadStashFile::getFileKey()
bool$noAuth(optional) Don't check authentication. Used by maintenance scripts.
Exceptions
UploadStashNotLoggedInException
UploadStashWrongOwnerException
UploadStashBadPathException
UploadStashFileNotFoundException
Returns
UploadStashFile

Definition at line 84 of file UploadStash.php.

References $path, DB_PRIMARY, MediaWiki\Upload\UploadStash\fetchFileMetadata(), MediaWiki\Upload\UploadStash\initFile(), wfDebug(), and wfMessage().

Referenced by MediaWiki\Upload\UploadStash\getFileProps(), MediaWiki\Upload\UploadStash\getMetadata(), MediaWiki\Upload\UploadStash\removeFileNoAuth(), and MediaWiki\Upload\UploadStash\stashFile().

◆ getFileProps()

MediaWiki\Upload\UploadStash::getFileProps ( $key)

Get file properties.

Parameters
string$keyThe stash key
Returns
array

Definition at line 154 of file UploadStash.php.

References MediaWiki\Upload\UploadStash\getFile().

◆ getMetadata()

MediaWiki\Upload\UploadStash::getMetadata ( $key)

Get file metadata.

Parameters
string$keyThe stash key
Returns
array

Definition at line 142 of file UploadStash.php.

References MediaWiki\Upload\UploadStash\getFile().

◆ initFile()

MediaWiki\Upload\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 485 of file UploadStash.php.

Referenced by MediaWiki\Upload\UploadStash\getFile(), and MediaWiki\Upload\UploadStash\stashFile().

◆ listFiles()

MediaWiki\Upload\UploadStash::listFiles ( )

List all files in the stash.

Exceptions
UploadStashNotLoggedInException
Returns
string[]

Definition at line 390 of file UploadStash.php.

References wfMessage().

◆ removeFile()

MediaWiki\Upload\UploadStash::removeFile ( $key)

Remove a particular file from the stash and the repo.

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

Definition at line 326 of file UploadStash.php.

References MediaWiki\Upload\UploadStash\removeFileNoAuth(), and wfMessage().

◆ removeFileNoAuth()

MediaWiki\Upload\UploadStash::removeFileNoAuth ( $key)

Remove a file, but doesn't check ownership first.

Parameters
string$key
Returns
bool Success

Definition at line 363 of file UploadStash.php.

References $success, MediaWiki\Upload\UploadStash\getFile(), and wfDebug().

Referenced by MediaWiki\Upload\UploadStash\removeFile().

◆ stashFile()

MediaWiki\Upload\UploadStash::stashFile ( $path,
$sourceType = null,
$fileProps = 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 source type from UploadBase::getSourceType()
array | null$filePropsFile props or null to regenerate
Exceptions
UploadStashFileException
UploadStashNotLoggedInException
UploadStashBadPathException
UploadStashZeroLengthFileException
Returns
UploadStashFile|null File, or null on failure

Definition at line 173 of file UploadStash.php.

References MediaWiki\Upload\UploadStash\$fileProps, $path, MediaWiki\Upload\UploadStash\getExtensionForPath(), MediaWiki\Upload\UploadStash\getFile(), MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Upload\UploadStash\initFile(), wfDebug(), and wfMessage().

Member Data Documentation

◆ $fileMetadata

array MediaWiki\Upload\UploadStash::$fileMetadata = []
protected

Cache of uploadstash rows indexed by stash key.

Definition at line 53 of file UploadStash.php.

◆ $fileProps

array MediaWiki\Upload\UploadStash::$fileProps = []
protected

Cache of unserialized file properties (us_props) indexed by stash key.

Definition at line 56 of file UploadStash.php.

Referenced by MediaWiki\Upload\UploadStash\stashFile().

◆ $files

UploadStashFile [] MediaWiki\Upload\UploadStash::$files = []
protected

Array of initialized file objects.

Definition at line 50 of file UploadStash.php.

◆ $repo

LocalRepo MediaWiki\Upload\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 47 of file UploadStash.php.

Referenced by MediaWiki\Upload\UploadStash\__construct().

◆ KEY_FORMAT_REGEX

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

Definition at line 38 of file UploadStash.php.

Referenced by MediaWiki\Upload\UploadFromStash\isValidKey().


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