42 private const MDS_EMPTY =
'empty';
45 private const MDS_LEGACY =
'legacy';
48 private const MDS_PHP =
'php';
51 private const MDS_JSON =
'json';
109 private $description;
132 private $archive_name;
147 private $metadataStorageHelper;
161 $this->group =
'deleted';
167 $this->mime =
"unknown/unknown";
168 $this->media_type =
'';
169 $this->description =
'';
171 $this->timestamp =
null;
173 $this->dataLoaded =
false;
178 $this->title = File::normalizeTitle(
$title,
'exception' );
194 if ( !$id && !$key && !(
$title instanceof
Title ) && !$sha1 ) {
195 throw new MWException(
"No specifications provided to ArchivedFile constructor." );
198 $this->repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
209 if ( $this->dataLoaded ) {
214 if ( $this->
id > 0 ) {
215 $conds[
'fa_id'] = $this->id;
218 $conds[
'fa_storage_group'] = $this->group;
219 $conds[
'fa_storage_key'] = $this->key;
221 if ( $this->title ) {
222 $conds[
'fa_name'] = $this->title->getDBkey();
225 $conds[
'fa_sha1'] = $this->sha1;
228 if ( $conds === [] ) {
229 throw new MWException(
"No specific information for retrieving archived file" );
232 if ( !$this->title || $this->title->getNamespace() ===
NS_FILE ) {
233 $this->dataLoaded =
true;
236 $row =
$dbr->selectRow(
237 $fileQuery[
'tables'],
238 $fileQuery[
'fields'],
241 [
'ORDER BY' =>
'fa_timestamp DESC' ],
252 throw new MWException(
'This title does not correspond to an image page.' );
268 $file->loadFromRow( $row );
290 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin(
'fa_description' );
294 'filearchive_actor' =>
'actor'
295 ] + $commentQuery[
'tables'],
312 'fa_deleted_timestamp',
315 'fa_user' =>
'filearchive_actor.actor_user',
316 'fa_user_text' =>
'filearchive_actor.actor_name'
317 ] + $commentQuery[
'fields'],
319 'filearchive_actor' => [
'JOIN',
'actor_id=fa_actor' ]
320 ] + $commentQuery[
'joins'],
332 $this->
id = intval( $row->fa_id );
333 $this->name = $row->fa_name;
334 $this->archive_name = $row->fa_archive_name;
335 $this->group = $row->fa_storage_group;
336 $this->key = $row->fa_storage_key;
337 $this->size = $row->fa_size;
338 $this->bits = $row->fa_bits;
339 $this->width = $row->fa_width;
340 $this->height = $row->fa_height;
342 $this->repo->getReplicaDB(), $row->fa_metadata );
343 $this->mime =
"$row->fa_major_mime/$row->fa_minor_mime";
344 $this->media_type = $row->fa_media_type;
345 $services = MediaWikiServices::getInstance();
346 $this->description = $services->getCommentStore()
349 $this->user = $services->getUserFactory()
350 ->newFromAnyId( $row->fa_user, $row->fa_user_text, $row->fa_actor );
351 $this->timestamp = $row->fa_timestamp;
352 $this->deleted = $row->fa_deleted;
353 if ( isset( $row->fa_sha1 ) ) {
354 $this->sha1 = $row->fa_sha1;
357 $this->sha1 = LocalRepo::getHashFromKey( $this->key );
359 if ( !$this->title ) {
360 $this->title = Title::makeTitleSafe(
NS_FILE, $row->fa_name );
370 if ( !$this->title ) {
382 if ( $this->name ===
false ) {
450 return $this->height;
463 } elseif ( array_keys( $data ) === [
'_error' ] ) {
465 return $data[
'_error'];
479 if ( $this->unloadedMetadataBlobs ) {
481 array_unique( array_merge(
482 array_keys( $this->metadataArray ),
483 array_keys( $this->unloadedMetadataBlobs )
494 foreach ( $itemNames as $itemName ) {
495 if ( array_key_exists( $itemName, $this->metadataArray ) ) {
496 $result[$itemName] = $this->metadataArray[$itemName];
497 } elseif ( isset( $this->unloadedMetadataBlobs[$itemName] ) ) {
498 $addresses[$itemName] = $this->unloadedMetadataBlobs[$itemName];
503 $resultFromBlob = $this->metadataStorageHelper->getMetadataFromBlobStore( $addresses );
504 foreach ( $addresses as $itemName => $address ) {
505 unset( $this->unloadedMetadataBlobs[$itemName] );
506 $value = $resultFromBlob[$itemName] ??
null;
507 if ( $value !==
null ) {
508 $result[$itemName] = $value;
509 $this->metadataArray[$itemName] = $value;
529 if ( !$this->metadataArray && !$this->metadataBlobs ) {
531 } elseif ( $this->repo->isJsonMetadataEnabled() ) {
532 $s = $this->getJsonMetadata();
536 if ( !is_string(
$s ) ) {
537 throw new MWException(
'Could not serialize image metadata value for DB' );
548 private function getJsonMetadata() {
551 'data' => array_diff_key( $this->metadataArray, $this->metadataBlobs )
555 if ( $this->metadataBlobs ) {
556 $envelope[
'blobs'] = $this->metadataBlobs;
559 list(
$s, $blobAddresses ) = $this->metadataStorageHelper->getJsonMetadata( $this, $envelope );
562 $this->metadataBlobs += $blobAddresses;
576 $this->loadMetadataFromString( $db->
decodeBlob( $metadataBlob ) );
587 $this->extraDataLoaded =
true;
588 $this->metadataArray = [];
589 $this->metadataBlobs = [];
590 $this->unloadedMetadataBlobs = [];
591 $metadataString = (string)$metadataString;
592 if ( $metadataString ===
'' ) {
593 $this->metadataSerializationFormat = self::MDS_EMPTY;
596 if ( $metadataString[0] ===
'{' ) {
597 $envelope = $this->metadataStorageHelper->jsonDecode( $metadataString );
600 $this->metadataArray = [
'_error' => $metadataString ];
601 $this->metadataSerializationFormat = self::MDS_LEGACY;
603 $this->metadataSerializationFormat = self::MDS_JSON;
604 if ( isset( $envelope[
'data'] ) ) {
605 $this->metadataArray = $envelope[
'data'];
607 if ( isset( $envelope[
'blobs'] ) ) {
608 $this->metadataBlobs = $this->unloadedMetadataBlobs = $envelope[
'blobs'];
614 if ( !is_array( $data ) ) {
616 $data = [
'_error' => $metadataString ];
617 $this->metadataSerializationFormat = self::MDS_LEGACY;
619 $this->metadataSerializationFormat = self::MDS_PHP;
621 $this->metadataArray = $data;
659 private function getHandler() {
660 if ( !isset( $this->handler ) ) {
664 return $this->handler;
674 if ( !isset( $this->pageCount ) ) {
677 if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
679 $this->pageCount = $this->handler->pageCount( $this );
681 $this->pageCount =
false;
685 return $this->pageCount;
696 return $this->media_type;
735 if ( $audience === self::FOR_PUBLIC && $this->isDeleted( File::DELETED_USER ) ) {
737 } elseif ( $audience === self::FOR_THIS_USER && !$this->userCan( File::DELETED_USER, $performer ) ) {
758 if ( $audience === self::FOR_PUBLIC && $this->isDeleted( File::DELETED_COMMENT ) ) {
760 } elseif ( $audience === self::FOR_THIS_USER && !$this->userCan( File::DELETED_COMMENT, $performer ) ) {
763 return $this->description;
774 return $this->deleted;
786 return ( $this->deleted & $field ) == $field;
800 return RevisionRecord::userCanBitfield(
unserialize( $serialized)
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Deleted file in the 'filearchive' table.
getTimestamp()
Return upload timestamp.
getSize()
Return the size of the image file, in bytes.
isDeleted( $field)
for file or revision rows
getHeight()
Return the height of the image.
string[] $metadataBlobs
Map of metadata item name to blob address.
getBits()
Return the bits of the image file, in bytes.
array $metadataArray
Unserialized metadata.
getMetadataForDb(IDatabase $db)
Serialize the metadata array for insertion into img_metadata, oi_metadata or fa_metadata.
string[] $unloadedMetadataBlobs
Map of metadata item name to blob address for items that exist but have not yet been loaded into $thi...
getSha1()
Get the SHA-1 base 36 hash of the file.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archivedfile object.
loadFromRow( $row)
Load ArchivedFile object fields from a DB row.
loadMetadataFromDbFieldValue(IDatabase $db, $metadataBlob)
Unserialize a metadata blob which came from the database and store it in $this.
string null $metadataSerializationFormat
One of the MDS_* constants, giving the format of the metadata as stored in the DB,...
getMetadataItems(array $itemNames)
__construct( $title, $id=0, $key='', $sha1='')
getUploader(int $audience=self::FOR_PUBLIC, Authority $performer=null)
load()
Loads a file object from the filearchive table.
pageCount()
Returns the number of pages of a multipage document, or false for documents which aren't multipage do...
getGroup()
Return the FileStore storage group.
static newFromRow( $row)
Loads a file object from the filearchive table.
getTitle()
Return the associated title object.
getWidth()
Return the width of the image.
getStorageKey()
Return the FileStore key (overriding base File class)
getDescription(int $audience=self::FOR_PUBLIC, Authority $performer=null)
Return upload description.
getMimeType()
Returns the MIME type of the file.
getKey()
Return the FileStore key.
userCan( $field, Authority $performer)
Determine if the current user is allowed to view a particular field of this FileStore image file,...
getMetadataArray()
Get unserialized handler-specific metadata.
loadMetadataFromString( $metadataString)
Unserialize a metadata string which came from some non-DB source, or is the return value of IDatabase...
getName()
Return the file name.
getMediaType()
Return the type of the media in the file.
getVisibility()
Returns the deletion bitfield.
getMetadata()
Get handler-specific metadata as a serialized string.
bool $extraDataLoaded
Whether or not lazy-loaded data has been loaded from the database.
Local repository that stores files in the local filesystem and registers them in the wiki's own datab...
Represents a title within MediaWiki.
getDBkey()
Get the main part with underscores.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.