MediaWiki  master
ArchivedFile Class Reference

Deleted file in the 'filearchive' table. More...

Collaboration diagram for ArchivedFile:

Public Member Functions

 __construct ( $title, $id=0, $key='', $sha1='')
 
 exists ()
 
 getBits ()
 Return the bits of the image file, in bytes. More...
 
 getDescription (int $audience=self::FOR_PUBLIC, Authority $performer=null)
 Return upload description. More...
 
 getGroup ()
 Return the FileStore storage group. More...
 
 getHeight ()
 Return the height of the image. More...
 
 getID ()
 
 getKey ()
 Return the FileStore key. More...
 
 getMediaType ()
 Return the type of the media in the file. More...
 
 getMetadata ()
 Get handler-specific metadata as a serialized string. More...
 
 getMetadataArray ()
 Get unserialized handler-specific metadata. More...
 
 getMetadataForDb (IDatabase $db)
 Serialize the metadata array for insertion into img_metadata, oi_metadata or fa_metadata. More...
 
 getMetadataItems (array $itemNames)
 
 getMimeType ()
 Returns the MIME type of the file. More...
 
 getName ()
 Return the file name. More...
 
 getSha1 ()
 Get the SHA-1 base 36 hash of the file. More...
 
 getSize ()
 Return the size of the image file, in bytes. More...
 
 getStorageKey ()
 Return the FileStore key (overriding base File class) More...
 
 getTimestamp ()
 Return upload timestamp. More...
 
 getTitle ()
 Return the associated title object. More...
 
 getUploader (int $audience=self::FOR_PUBLIC, Authority $performer=null)
 
 getVisibility ()
 Returns the deletion bitfield. More...
 
 getWidth ()
 Return the width of the image. More...
 
 isDeleted ( $field)
 for file or revision rows More...
 
 load ()
 Loads a file object from the filearchive table. More...
 
 loadFromRow ( $row)
 Load ArchivedFile object fields from a DB row. More...
 
 pageCount ()
 Returns the number of pages of a multipage document, or false for documents which aren't multipage documents. More...
 
 userCan ( $field, Authority $performer)
 Determine if the current user is allowed to view a particular field of this FileStore image file, if it's marked as deleted. More...
 

Static Public Member Functions

static getQueryInfo ()
 Return the tables, fields, and join conditions to be selected to create a new archivedfile object. More...
 
static newFromRow ( $row)
 Loads a file object from the filearchive table. More...
 

Public Attributes

const FOR_PUBLIC = 1
 
const FOR_THIS_USER = 2
 
const RAW = 3
 

Protected Member Functions

 loadMetadataFromDbFieldValue (IDatabase $db, $metadataBlob)
 Unserialize a metadata blob which came from the database and store it in $this. More...
 
 loadMetadataFromString ( $metadataString)
 Unserialize a metadata string which came from some non-DB source, or is the return value of IDatabase::decodeBlob(). More...
 

Protected Attributes

bool $exists
 
bool $extraDataLoaded = false
 Whether or not lazy-loaded data has been loaded from the database. More...
 
MediaHandler $handler
 
array $metadataArray = []
 Unserialized metadata. More...
 
string[] $metadataBlobs = []
 Map of metadata item name to blob address. More...
 
string null $metadataSerializationFormat
 One of the MDS_* constants, giving the format of the metadata as stored in the DB, or null if the data was not loaded from the DB. More...
 
Title null $title
 
string[] $unloadedMetadataBlobs = []
 Map of metadata item name to blob address for items that exist but have not yet been loaded into $this->metadataArray. More...
 

Private Member Functions

 getHandler ()
 Get a MediaHandler instance for this file. More...
 
 getJsonMetadata ()
 Get metadata in JSON format ready for DB insertion, optionally splitting items out to BlobStore. More...
 

Private Attributes

string $archive_name
 Original base filename. More...
 
int $bits
 Size in bytes. More...
 
bool $dataLoaded
 Whether or not all this has been loaded from the database (loadFromXxx) More...
 
int $deleted
 Bitfield akin to rev_deleted. More...
 
string $description
 Upload description. More...
 
string $group
 FileStore storage group. More...
 
int $height
 Height. More...
 
int $id
 Filearchive row ID. More...
 
string $key
 FileStore SHA-1 key. More...
 
string $media_type
 Media type. More...
 
MetadataStorageHelper $metadataStorageHelper
 
string $mime
 MIME type. More...
 
string false $name
 File name. More...
 
int false $pageCount
 Number of pages of a multipage document, or false for documents which aren't multipage documents. More...
 
LocalRepo $repo
 
string $sha1
 SHA-1 hash of file content. More...
 
int $size
 File size in bytes. More...
 
string null $timestamp
 Time of upload. More...
 
UserIdentity null $user
 Uploader. More...
 
int $width
 Width. More...
 

Detailed Description

Deleted file in the 'filearchive' table.

Stability: stable
to extend

Definition at line 34 of file ArchivedFile.php.

Constructor & Destructor Documentation

◆ __construct()

ArchivedFile::__construct (   $title,
  $id = 0,
  $key = '',
  $sha1 = '' 
)
Stability: stable
to call
Exceptions
MWException
Parameters
Title | null$title
int$id
string$key
string$sha1

Definition at line 157 of file ArchivedFile.php.

References $id, $key, $sha1, $title, exists(), Title\getDBkey(), and File\normalizeTitle().

Member Function Documentation

◆ exists()

ArchivedFile::exists ( )
Returns
bool

Definition at line 400 of file ArchivedFile.php.

References $exists, and load().

Referenced by __construct(), and load().

◆ getBits()

ArchivedFile::getBits ( )

Return the bits of the image file, in bytes.

Returns
int

Definition at line 638 of file ArchivedFile.php.

◆ getDescription()

ArchivedFile::getDescription ( int  $audience = self::FOR_PUBLIC,
Authority  $performer = null 
)

Return upload description.

Since
1.37 the method takes $audience and $performer parameters.
Parameters
int$audienceOne of: File::FOR_PUBLIC to be displayed to all users File::FOR_THIS_USER to be displayed to the given user File::RAW get the description regardless of permissions
Authority | null$performerto check for, only if FOR_THIS_USER is passed to the $audience parameter
Returns
string

Definition at line 755 of file ArchivedFile.php.

◆ getGroup()

ArchivedFile::getGroup ( )

Return the FileStore storage group.

Returns
string

Definition at line 428 of file ArchivedFile.php.

References $group.

◆ getHandler()

ArchivedFile::getHandler ( )
private

Get a MediaHandler instance for this file.

Returns
MediaHandler

Definition at line 658 of file ArchivedFile.php.

References MediaHandler\getHandler().

◆ getHeight()

ArchivedFile::getHeight ( )

Return the height of the image.

Returns
int

Definition at line 446 of file ArchivedFile.php.

References $height, and load().

◆ getID()

ArchivedFile::getID ( )
Returns
int

Definition at line 391 of file ArchivedFile.php.

References $id, and load().

◆ getJsonMetadata()

ArchivedFile::getJsonMetadata ( )
private

Get metadata in JSON format ready for DB insertion, optionally splitting items out to BlobStore.

Returns
string

Definition at line 547 of file ArchivedFile.php.

References $s.

◆ getKey()

ArchivedFile::getKey ( )

Return the FileStore key.

Returns
string

Definition at line 410 of file ArchivedFile.php.

References $key, and load().

Referenced by getStorageKey().

◆ getMediaType()

ArchivedFile::getMediaType ( )

Return the type of the media in the file.

Use the value returned by this function with the MEDIATYPE_xxx constants.

Returns
string

Definition at line 692 of file ArchivedFile.php.

◆ getMetadata()

ArchivedFile::getMetadata ( )

Get handler-specific metadata as a serialized string.

Deprecated:
since 1.37 use getMetadataArray() or getMetadataItem()
Returns
string

Definition at line 458 of file ArchivedFile.php.

References getMetadataArray(), and serialize().

◆ getMetadataArray()

ArchivedFile::getMetadataArray ( )

Get unserialized handler-specific metadata.

Since
1.39
Returns
array

Definition at line 476 of file ArchivedFile.php.

References getMetadataItems().

Referenced by getMetadata().

◆ getMetadataForDb()

ArchivedFile::getMetadataForDb ( IDatabase  $db)

Serialize the metadata array for insertion into img_metadata, oi_metadata or fa_metadata.

If metadata splitting is enabled, this may write blobs to the database, returning their addresses.

Access: internal
Parameters
IDatabase$db
Returns
string|Blob

Definition at line 526 of file ArchivedFile.php.

References $s, Wikimedia\Rdbms\IDatabase\encodeBlob(), and serialize().

◆ getMetadataItems()

ArchivedFile::getMetadataItems ( array  $itemNames)

Definition at line 489 of file ArchivedFile.php.

Referenced by getMetadataArray().

◆ getMimeType()

ArchivedFile::getMimeType ( )

Returns the MIME type of the file.

Returns
string

Definition at line 648 of file ArchivedFile.php.

References $mime.

◆ getName()

ArchivedFile::getName ( )

Return the file name.

Returns
string

Definition at line 380 of file ArchivedFile.php.

References $name, and load().

Referenced by EraseArchivedFile\scrubVersion().

◆ getQueryInfo()

static ArchivedFile::getQueryInfo ( )
static

Return the tables, fields, and join conditions to be selected to create a new archivedfile object.

Since 1.34, fa_user and fa_user_text have not been present in the database, but they continue to be available in query results as an alias.

Since
1.31
Stability: stable
to override
Returns
array[] With three keys:
  • tables: (string[]) to include in the $table to IDatabase->select()
  • fields: (string[]) to include in the $vars to IDatabase->select()
  • joins: (array) to include in the $join_conds to IDatabase->select()

Definition at line 288 of file ArchivedFile.php.

Referenced by RevDelArchivedFileList\doQuery(), ApiQueryFilearchive\execute(), LocalFileRestoreBatch\execute(), EraseArchivedFile\execute(), PageArchive\listFiles(), load(), and EraseArchivedFile\scrubAllVersions().

◆ getSha1()

ArchivedFile::getSha1 ( )

Get the SHA-1 base 36 hash of the file.

Returns
string
Since
1.21

Definition at line 715 of file ArchivedFile.php.

◆ getSize()

ArchivedFile::getSize ( )

Return the size of the image file, in bytes.

Returns
int

Definition at line 628 of file ArchivedFile.php.

◆ getStorageKey()

ArchivedFile::getStorageKey ( )

Return the FileStore key (overriding base File class)

Returns
string

Definition at line 420 of file ArchivedFile.php.

References getKey().

Referenced by EraseArchivedFile\scrubVersion().

◆ getTimestamp()

ArchivedFile::getTimestamp ( )

Return upload timestamp.

Returns
string

Definition at line 703 of file ArchivedFile.php.

References wfTimestamp().

Referenced by EraseArchivedFile\scrubVersion().

◆ getTitle()

ArchivedFile::getTitle ( )

Return the associated title object.

Returns
Title

Definition at line 368 of file ArchivedFile.php.

References $title, and load().

◆ getUploader()

ArchivedFile::getUploader ( int  $audience = self::FOR_PUBLIC,
Authority  $performer = null 
)
Since
1.37
Stability: stable
to override
Parameters
int$audienceOne of: File::FOR_PUBLIC to be displayed to all users File::FOR_THIS_USER to be displayed to the given user File::RAW get the description regardless of permissions
Authority | null$performerto check for, only if FOR_THIS_USER is passed to the $audience parameter
Returns
UserIdentity|null

Definition at line 732 of file ArchivedFile.php.

◆ getVisibility()

ArchivedFile::getVisibility ( )

Returns the deletion bitfield.

Returns
int

Definition at line 770 of file ArchivedFile.php.

◆ getWidth()

ArchivedFile::getWidth ( )

Return the width of the image.

Returns
int

Definition at line 436 of file ArchivedFile.php.

References $width, and load().

◆ isDeleted()

ArchivedFile::isDeleted (   $field)

for file or revision rows

Parameters
int$fieldOne of DELETED_* bitfield constants
Returns
bool

Definition at line 782 of file ArchivedFile.php.

◆ load()

ArchivedFile::load ( )

Loads a file object from the filearchive table.

Stability: stable
to override
Exceptions
MWException
Returns
bool|null True on success or null

Definition at line 208 of file ArchivedFile.php.

References $dbr, $group, $id, $key, $sha1, DB_REPLICA, exists(), getQueryInfo(), loadFromRow(), NS_FILE, and wfGetDB().

Referenced by exists(), getHeight(), getID(), getKey(), getName(), getTitle(), and getWidth().

◆ loadFromRow()

ArchivedFile::loadFromRow (   $row)

Load ArchivedFile object fields from a DB row.

Stability: stable
to override
Parameters
stdClass$rowObject database row
Since
1.21

Definition at line 330 of file ArchivedFile.php.

References DB_REPLICA, LocalRepo\getHashFromKey(), loadMetadataFromDbFieldValue(), Title\makeTitleSafe(), NS_FILE, and wfGetDB().

Referenced by load().

◆ loadMetadataFromDbFieldValue()

ArchivedFile::loadMetadataFromDbFieldValue ( IDatabase  $db,
  $metadataBlob 
)
protected

Unserialize a metadata blob which came from the database and store it in $this.

Since
1.39
Parameters
IDatabase$db
string | Blob$metadataBlob

Definition at line 574 of file ArchivedFile.php.

References Wikimedia\Rdbms\IDatabase\decodeBlob().

Referenced by loadFromRow().

◆ loadMetadataFromString()

ArchivedFile::loadMetadataFromString (   $metadataString)
protected

Unserialize a metadata string which came from some non-DB source, or is the return value of IDatabase::decodeBlob().

Since
1.37
Parameters
string$metadataString

Definition at line 585 of file ArchivedFile.php.

References unserialize().

◆ newFromRow()

static ArchivedFile::newFromRow (   $row)
static

Loads a file object from the filearchive table.

Stability: stable
to override
Parameters
stdClass$row
Returns
ArchivedFile

Definition at line 266 of file ArchivedFile.php.

References $file, Title\makeTitle(), and NS_FILE.

Referenced by ApiQueryFilearchive\execute(), EraseArchivedFile\execute(), SpecialUndelete\formatFileRow(), RevDelArchivedFileItem\initFile(), and EraseArchivedFile\scrubAllVersions().

◆ pageCount()

ArchivedFile::pageCount ( )

Returns the number of pages of a multipage document, or false for documents which aren't multipage documents.

Stability: stable
to override
Returns
int|false

Definition at line 672 of file ArchivedFile.php.

◆ userCan()

ArchivedFile::userCan (   $field,
Authority  $performer 
)

Determine if the current user is allowed to view a particular field of this FileStore image file, if it's marked as deleted.

Parameters
int$field
Authority$performer
Returns
bool

Definition at line 795 of file ArchivedFile.php.

References $title, and getTitle().

Member Data Documentation

◆ $archive_name

string ArchivedFile::$archive_name
private

Original base filename.

Definition at line 132 of file ArchivedFile.php.

◆ $bits

int ArchivedFile::$bits
private

Size in bytes.

Definition at line 69 of file ArchivedFile.php.

◆ $dataLoaded

bool ArchivedFile::$dataLoaded
private

Whether or not all this has been loaded from the database (loadFromXxx)

Definition at line 118 of file ArchivedFile.php.

◆ $deleted

int ArchivedFile::$deleted
private

Bitfield akin to rev_deleted.

Definition at line 121 of file ArchivedFile.php.

◆ $description

string ArchivedFile::$description
private

Upload description.

Definition at line 109 of file ArchivedFile.php.

◆ $exists

bool ArchivedFile::$exists
protected

Definition at line 141 of file ArchivedFile.php.

Referenced by exists().

◆ $extraDataLoaded

bool ArchivedFile::$extraDataLoaded = false
protected

Whether or not lazy-loaded data has been loaded from the database.

Definition at line 81 of file ArchivedFile.php.

◆ $group

string ArchivedFile::$group
private

FileStore storage group.

Definition at line 60 of file ArchivedFile.php.

Referenced by getGroup(), and load().

◆ $handler

MediaHandler ArchivedFile::$handler
protected

Definition at line 135 of file ArchivedFile.php.

◆ $height

int ArchivedFile::$height
private

Height.

Definition at line 75 of file ArchivedFile.php.

Referenced by getHeight().

◆ $id

int ArchivedFile::$id
private
Initial value:
=
private const MDS_JSON 'json'

Filearchive row ID.

Definition at line 54 of file ArchivedFile.php.

Referenced by __construct(), getID(), and load().

◆ $key

string ArchivedFile::$key
private

FileStore SHA-1 key.

Definition at line 63 of file ArchivedFile.php.

Referenced by __construct(), getKey(), and load().

◆ $media_type

string ArchivedFile::$media_type
private

Media type.

Definition at line 106 of file ArchivedFile.php.

◆ $metadataArray

array ArchivedFile::$metadataArray = []
protected

Unserialized metadata.

Definition at line 78 of file ArchivedFile.php.

◆ $metadataBlobs

string [] ArchivedFile::$metadataBlobs = []
protected

Map of metadata item name to blob address.

Definition at line 92 of file ArchivedFile.php.

◆ $metadataSerializationFormat

string null ArchivedFile::$metadataSerializationFormat
protected

One of the MDS_* constants, giving the format of the metadata as stored in the DB, or null if the data was not loaded from the DB.

Definition at line 89 of file ArchivedFile.php.

◆ $metadataStorageHelper

MetadataStorageHelper ArchivedFile::$metadataStorageHelper
private

Definition at line 147 of file ArchivedFile.php.

◆ $mime

string ArchivedFile::$mime
private

MIME type.

Definition at line 103 of file ArchivedFile.php.

◆ $name

string false ArchivedFile::$name
private

File name.

Definition at line 57 of file ArchivedFile.php.

Referenced by getName().

◆ $pageCount

int false ArchivedFile::$pageCount
private

Number of pages of a multipage document, or false for documents which aren't multipage documents.

Definition at line 129 of file ArchivedFile.php.

◆ $repo

LocalRepo ArchivedFile::$repo
private

Definition at line 144 of file ArchivedFile.php.

◆ $sha1

string ArchivedFile::$sha1
private

SHA-1 hash of file content.

Definition at line 124 of file ArchivedFile.php.

Referenced by __construct(), and load().

◆ $size

int ArchivedFile::$size
private

File size in bytes.

Definition at line 66 of file ArchivedFile.php.

◆ $timestamp

string null ArchivedFile::$timestamp
private

Time of upload.

Definition at line 115 of file ArchivedFile.php.

◆ $title

Title null ArchivedFile::$title
protected

Definition at line 138 of file ArchivedFile.php.

Referenced by __construct(), and getTitle().

◆ $unloadedMetadataBlobs

string [] ArchivedFile::$unloadedMetadataBlobs = []
protected

Map of metadata item name to blob address for items that exist but have not yet been loaded into $this->metadataArray.

Definition at line 100 of file ArchivedFile.php.

◆ $user

UserIdentity null ArchivedFile::$user
private

Uploader.

Definition at line 112 of file ArchivedFile.php.

◆ $width

int ArchivedFile::$width
private

Width.

Definition at line 72 of file ArchivedFile.php.

Referenced by getWidth().

◆ FOR_PUBLIC

const ArchivedFile::FOR_PUBLIC = 1

Definition at line 37 of file ArchivedFile.php.

◆ FOR_THIS_USER

const ArchivedFile::FOR_THIS_USER = 2

Definition at line 38 of file ArchivedFile.php.

Referenced by RevDelArchivedFileItem\getApiData().

◆ RAW

const ArchivedFile::RAW = 3

Definition at line 39 of file ArchivedFile.php.


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