2007-05-30 21:02:32 +00:00
|
|
|
<?php
|
2010-09-04 18:13:18 +00:00
|
|
|
/**
|
2012-05-07 07:11:33 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-09-04 18:13:18 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2023-08-01 21:04:32 +00:00
|
|
|
use MediaWiki\FileRepo\File\FileSelectQueryBuilder;
|
2018-05-04 13:39:33 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-04-05 19:43:12 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
2020-02-23 21:48:54 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2021-06-02 16:48:33 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2022-04-07 08:18:10 +00:00
|
|
|
use Wikimedia\Rdbms\Blob;
|
2023-05-03 10:41:45 +00:00
|
|
|
use Wikimedia\Rdbms\IReadableDatabase;
|
2023-08-01 21:04:32 +00:00
|
|
|
use Wikimedia\Rdbms\SelectQueryBuilder;
|
2018-05-04 13:39:33 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2022-04-07 01:20:40 +00:00
|
|
|
* Deleted file in the 'filearchive' table.
|
2010-09-04 18:13:18 +00:00
|
|
|
*
|
2020-07-13 09:00:30 +00:00
|
|
|
* @stable to extend
|
2012-02-08 15:51:16 +00:00
|
|
|
* @ingroup FileAbstraction
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2010-09-04 18:13:18 +00:00
|
|
|
class ArchivedFile {
|
2021-06-02 16:48:33 +00:00
|
|
|
|
|
|
|
|
// Audience options for ::getDescription() and ::getUploader()
|
|
|
|
|
public const FOR_PUBLIC = 1;
|
|
|
|
|
public const FOR_THIS_USER = 2;
|
|
|
|
|
public const RAW = 3;
|
|
|
|
|
|
2022-04-07 08:18:10 +00:00
|
|
|
/** @var string Metadata serialization: empty string. This is a compact non-legacy format. */
|
|
|
|
|
private const MDS_EMPTY = 'empty';
|
|
|
|
|
|
|
|
|
|
/** @var string Metadata serialization: some other string */
|
|
|
|
|
private const MDS_LEGACY = 'legacy';
|
|
|
|
|
|
|
|
|
|
/** @var string Metadata serialization: PHP serialize() */
|
|
|
|
|
private const MDS_PHP = 'php';
|
|
|
|
|
|
|
|
|
|
/** @var string Metadata serialization: JSON */
|
|
|
|
|
private const MDS_JSON = 'json';
|
|
|
|
|
|
2014-07-24 17:43:03 +00:00
|
|
|
/** @var int Filearchive row ID */
|
2013-11-24 08:34:22 +00:00
|
|
|
private $id;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2022-03-03 20:33:11 +00:00
|
|
|
/** @var string|false File name */
|
2013-11-24 08:34:22 +00:00
|
|
|
private $name;
|
|
|
|
|
|
|
|
|
|
/** @var string FileStore storage group */
|
|
|
|
|
private $group;
|
|
|
|
|
|
|
|
|
|
/** @var string FileStore SHA-1 key */
|
|
|
|
|
private $key;
|
|
|
|
|
|
|
|
|
|
/** @var int File size in bytes */
|
|
|
|
|
private $size;
|
|
|
|
|
|
2014-07-24 17:43:03 +00:00
|
|
|
/** @var int Size in bytes */
|
2013-11-24 08:34:22 +00:00
|
|
|
private $bits;
|
|
|
|
|
|
|
|
|
|
/** @var int Width */
|
|
|
|
|
private $width;
|
|
|
|
|
|
|
|
|
|
/** @var int Height */
|
|
|
|
|
private $height;
|
|
|
|
|
|
2022-04-07 08:18:10 +00:00
|
|
|
/** @var array Unserialized metadata */
|
|
|
|
|
protected $metadataArray = [];
|
|
|
|
|
|
|
|
|
|
/** @var bool Whether or not lazy-loaded data has been loaded from the database */
|
|
|
|
|
protected $extraDataLoaded = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* @var string|null
|
|
|
|
|
*/
|
|
|
|
|
protected $metadataSerializationFormat;
|
|
|
|
|
|
|
|
|
|
/** @var string[] Map of metadata item name to blob address */
|
|
|
|
|
protected $metadataBlobs = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Map of metadata item name to blob address for items that exist but
|
|
|
|
|
* have not yet been loaded into $this->metadataArray
|
|
|
|
|
*
|
|
|
|
|
* @var string[]
|
|
|
|
|
*/
|
|
|
|
|
protected $unloadedMetadataBlobs = [];
|
2013-11-24 08:34:22 +00:00
|
|
|
|
|
|
|
|
/** @var string MIME type */
|
|
|
|
|
private $mime;
|
|
|
|
|
|
|
|
|
|
/** @var string Media type */
|
|
|
|
|
private $media_type;
|
|
|
|
|
|
|
|
|
|
/** @var string Upload description */
|
|
|
|
|
private $description;
|
|
|
|
|
|
2021-06-02 16:48:33 +00:00
|
|
|
/** @var UserIdentity|null Uploader */
|
2013-11-24 08:34:22 +00:00
|
|
|
private $user;
|
|
|
|
|
|
2022-02-26 07:54:16 +00:00
|
|
|
/** @var string|null Time of upload */
|
2013-11-24 08:34:22 +00:00
|
|
|
private $timestamp;
|
|
|
|
|
|
|
|
|
|
/** @var bool Whether or not all this has been loaded from the database (loadFromXxx) */
|
|
|
|
|
private $dataLoaded;
|
|
|
|
|
|
|
|
|
|
/** @var int Bitfield akin to rev_deleted */
|
|
|
|
|
private $deleted;
|
|
|
|
|
|
|
|
|
|
/** @var string SHA-1 hash of file content */
|
|
|
|
|
private $sha1;
|
|
|
|
|
|
2016-12-08 05:04:53 +00:00
|
|
|
/** @var int|false Number of pages of a multipage document, or false for
|
2013-11-24 08:34:22 +00:00
|
|
|
* documents which aren't multipage documents
|
2011-02-18 23:56:08 +00:00
|
|
|
*/
|
2013-11-24 08:34:22 +00:00
|
|
|
private $pageCount;
|
|
|
|
|
|
|
|
|
|
/** @var string Original base filename */
|
|
|
|
|
private $archive_name;
|
|
|
|
|
|
|
|
|
|
/** @var MediaHandler */
|
|
|
|
|
protected $handler;
|
2011-02-18 23:56:08 +00:00
|
|
|
|
2021-10-16 21:05:28 +00:00
|
|
|
/** @var Title|null */
|
2013-11-24 08:34:22 +00:00
|
|
|
protected $title; # image title
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2019-09-11 09:30:12 +00:00
|
|
|
/** @var bool */
|
2020-02-28 15:35:01 +00:00
|
|
|
protected $exists;
|
2019-09-11 09:30:12 +00:00
|
|
|
|
2022-04-07 08:18:10 +00:00
|
|
|
/** @var LocalRepo */
|
|
|
|
|
private $repo;
|
|
|
|
|
|
|
|
|
|
/** @var MetadataStorageHelper */
|
|
|
|
|
private $metadataStorageHelper;
|
|
|
|
|
|
2011-03-14 01:04:16 +00:00
|
|
|
/**
|
2020-07-13 08:53:06 +00:00
|
|
|
* @stable to call
|
2021-10-16 21:05:28 +00:00
|
|
|
* @param Title|null $title
|
2011-03-14 01:04:16 +00:00
|
|
|
* @param int $id
|
|
|
|
|
* @param string $key
|
2015-02-13 18:10:36 +00:00
|
|
|
* @param string $sha1
|
2011-03-14 01:04:16 +00:00
|
|
|
*/
|
2020-02-28 15:35:01 +00:00
|
|
|
public function __construct( $title, $id = 0, $key = '', $sha1 = '' ) {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->id = -1;
|
2021-10-16 21:05:28 +00:00
|
|
|
$this->title = null;
|
2008-11-18 02:20:55 +00:00
|
|
|
$this->name = false;
|
2009-09-30 19:46:53 +00:00
|
|
|
$this->group = 'deleted'; // needed for direct use of constructor
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->key = '';
|
|
|
|
|
$this->size = 0;
|
|
|
|
|
$this->bits = 0;
|
|
|
|
|
$this->width = 0;
|
|
|
|
|
$this->height = 0;
|
|
|
|
|
$this->mime = "unknown/unknown";
|
|
|
|
|
$this->media_type = '';
|
|
|
|
|
$this->description = '';
|
2017-09-12 17:12:29 +00:00
|
|
|
$this->user = null;
|
2009-12-11 21:07:27 +00:00
|
|
|
$this->timestamp = null;
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->deleted = 0;
|
|
|
|
|
$this->dataLoaded = false;
|
2009-09-30 19:35:39 +00:00
|
|
|
$this->exists = false;
|
2012-10-14 18:58:25 +00:00
|
|
|
$this->sha1 = '';
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $title instanceof Title ) {
|
2011-11-04 23:49:03 +00:00
|
|
|
$this->title = File::normalizeTitle( $title, 'exception' );
|
2008-11-18 02:20:55 +00:00
|
|
|
$this->name = $title->getDBkey();
|
|
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2013-02-03 19:42:08 +00:00
|
|
|
if ( $id ) {
|
2008-11-18 02:20:55 +00:00
|
|
|
$this->id = $id;
|
2011-03-14 01:04:16 +00:00
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2013-02-03 19:42:08 +00:00
|
|
|
if ( $key ) {
|
2008-11-18 02:20:55 +00:00
|
|
|
$this->key = $key;
|
2011-03-14 01:04:16 +00:00
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2015-02-13 18:10:36 +00:00
|
|
|
if ( $sha1 ) {
|
|
|
|
|
$this->sha1 = $sha1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$id && !$key && !( $title instanceof Title ) && !$sha1 ) {
|
2023-06-09 21:50:08 +00:00
|
|
|
throw new BadMethodCallException( "No specifications provided to ArchivedFile constructor." );
|
2011-03-14 01:04:16 +00:00
|
|
|
}
|
2022-04-07 08:18:10 +00:00
|
|
|
|
|
|
|
|
$this->repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
|
|
|
|
|
$this->metadataStorageHelper = new MetadataStorageHelper( $this->repo );
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loads a file object from the filearchive table
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2012-02-10 15:37:33 +00:00
|
|
|
* @return bool|null True on success or null
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function load() {
|
|
|
|
|
if ( $this->dataLoaded ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$conds = [];
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $this->id > 0 ) {
|
2008-11-18 02:20:55 +00:00
|
|
|
$conds['fa_id'] = $this->id;
|
2011-03-14 01:04:16 +00:00
|
|
|
}
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $this->key ) {
|
2010-02-12 06:44:16 +00:00
|
|
|
$conds['fa_storage_group'] = $this->group;
|
2009-03-20 20:39:13 +00:00
|
|
|
$conds['fa_storage_key'] = $this->key;
|
|
|
|
|
}
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $this->title ) {
|
2008-11-18 02:20:55 +00:00
|
|
|
$conds['fa_name'] = $this->title->getDBkey();
|
2011-03-14 01:04:16 +00:00
|
|
|
}
|
2015-02-13 18:10:36 +00:00
|
|
|
if ( $this->sha1 ) {
|
|
|
|
|
$conds['fa_sha1'] = $this->sha1;
|
|
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2019-01-09 16:24:36 +00:00
|
|
|
if ( $conds === [] ) {
|
2023-06-10 16:13:20 +00:00
|
|
|
throw new RuntimeException( "No specific information for retrieving archived file" );
|
2011-03-14 01:04:16 +00:00
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2020-07-22 17:29:48 +00:00
|
|
|
if ( !$this->title || $this->title->getNamespace() === NS_FILE ) {
|
2012-10-26 17:51:18 +00:00
|
|
|
$this->dataLoaded = true; // set it here, to have also true on miss
|
2023-05-03 10:41:45 +00:00
|
|
|
$dbr = $this->repo->getReplicaDB();
|
2023-08-01 21:04:32 +00:00
|
|
|
$queryBuilder = FileSelectQueryBuilder::newForArchivedFile( $dbr );
|
|
|
|
|
$row = $queryBuilder->where( $conds )
|
|
|
|
|
->orderBy( 'fa_timestamp', SelectQueryBuilder::SORT_DESC )
|
|
|
|
|
->caller( __METHOD__ )->fetchRow();
|
2012-10-26 17:51:18 +00:00
|
|
|
if ( !$row ) {
|
|
|
|
|
// this revision does not exist?
|
2012-04-27 15:40:14 +00:00
|
|
|
return null;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
// initialize fields for filestore image object
|
2012-10-14 18:58:25 +00:00
|
|
|
$this->loadFromRow( $row );
|
2007-05-30 21:02:32 +00:00
|
|
|
} else {
|
2023-06-10 16:13:20 +00:00
|
|
|
throw new UnexpectedValueException( 'This title does not correspond to an image page.' );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Loads a file object from the filearchive table
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param stdClass $row
|
2010-02-15 22:06:18 +00:00
|
|
|
* @return ArchivedFile
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
|
|
|
|
public static function newFromRow( $row ) {
|
2008-12-01 17:14:30 +00:00
|
|
|
$file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
|
2012-10-14 18:58:25 +00:00
|
|
|
$file->loadFromRow( $row );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $file;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2017-10-06 17:03:55 +00:00
|
|
|
/**
|
|
|
|
|
* Return the tables, fields, and join conditions to be selected to create
|
|
|
|
|
* a new archivedfile object.
|
2021-04-19 00:55:24 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2017-10-06 17:03:55 +00:00
|
|
|
* @since 1.31
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2023-08-01 21:04:32 +00:00
|
|
|
* @deprecated since 1.41 use FileSelectQueryBuilder instead
|
2018-04-19 08:30:33 +00:00
|
|
|
* @return array[] With three keys:
|
2022-08-02 21:58:19 +00:00
|
|
|
* - tables: (string[]) to include in the `$table` to `IDatabase->select()` or `SelectQueryBuilder::tables`
|
|
|
|
|
* - fields: (string[]) to include in the `$vars` to `IDatabase->select()` or `SelectQueryBuilder::fields`
|
|
|
|
|
* - joins: (array) to include in the `$join_conds` to `IDatabase->select()` or `SelectQueryBuilder::joinConds`
|
|
|
|
|
* @phan-return array{tables:string[],fields:string[],joins:array}
|
2017-10-06 17:03:55 +00:00
|
|
|
*/
|
|
|
|
|
public static function getQueryInfo() {
|
2024-01-22 21:27:45 +00:00
|
|
|
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
|
2023-08-01 21:04:32 +00:00
|
|
|
$queryInfo = ( FileSelectQueryBuilder::newForArchivedFile( $dbr ) )->getQueryInfo();
|
2017-10-06 17:03:55 +00:00
|
|
|
return [
|
2023-08-01 21:04:32 +00:00
|
|
|
'tables' => $queryInfo['tables'],
|
|
|
|
|
'fields' => $queryInfo['fields'],
|
|
|
|
|
'joins' => $queryInfo['join_conds'],
|
2017-10-06 17:03:55 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-14 18:58:25 +00:00
|
|
|
/**
|
|
|
|
|
* Load ArchivedFile object fields from a DB row.
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2012-10-14 18:58:25 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param stdClass $row Object database row
|
2012-10-14 18:58:25 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
|
|
|
|
public function loadFromRow( $row ) {
|
2013-02-03 19:42:08 +00:00
|
|
|
$this->id = intval( $row->fa_id );
|
2012-10-14 18:58:25 +00:00
|
|
|
$this->name = $row->fa_name;
|
|
|
|
|
$this->archive_name = $row->fa_archive_name;
|
|
|
|
|
$this->group = $row->fa_storage_group;
|
|
|
|
|
$this->key = $row->fa_storage_key;
|
|
|
|
|
$this->size = $row->fa_size;
|
|
|
|
|
$this->bits = $row->fa_bits;
|
|
|
|
|
$this->width = $row->fa_width;
|
|
|
|
|
$this->height = $row->fa_height;
|
2022-04-07 08:18:10 +00:00
|
|
|
$this->loadMetadataFromDbFieldValue(
|
|
|
|
|
$this->repo->getReplicaDB(), $row->fa_metadata );
|
2012-10-14 18:58:25 +00:00
|
|
|
$this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
|
|
|
|
|
$this->media_type = $row->fa_media_type;
|
2021-12-19 13:25:00 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$this->description = $services->getCommentStore()
|
2017-10-06 17:03:55 +00:00
|
|
|
// Legacy because $row may have come from self::selectFields()
|
2023-05-03 10:41:45 +00:00
|
|
|
->getCommentLegacy( $this->repo->getReplicaDB(), 'fa_description', $row )->text;
|
2021-12-19 13:25:00 +00:00
|
|
|
$this->user = $services->getUserFactory()
|
|
|
|
|
->newFromAnyId( $row->fa_user, $row->fa_user_text, $row->fa_actor );
|
2012-10-14 18:58:25 +00:00
|
|
|
$this->timestamp = $row->fa_timestamp;
|
|
|
|
|
$this->deleted = $row->fa_deleted;
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( isset( $row->fa_sha1 ) ) {
|
2012-10-14 18:58:25 +00:00
|
|
|
$this->sha1 = $row->fa_sha1;
|
|
|
|
|
} else {
|
|
|
|
|
// old row, populate from key
|
|
|
|
|
$this->sha1 = LocalRepo::getHashFromKey( $this->key );
|
|
|
|
|
}
|
2014-09-18 19:11:42 +00:00
|
|
|
if ( !$this->title ) {
|
|
|
|
|
$this->title = Title::makeTitleSafe( NS_FILE, $row->fa_name );
|
|
|
|
|
}
|
2023-05-12 20:28:47 +00:00
|
|
|
$this->exists = $row->fa_archive_name !== '';
|
2012-10-14 18:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return the associated title object
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return Title
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
public function getTitle() {
|
2014-09-18 19:11:42 +00:00
|
|
|
if ( !$this->title ) {
|
|
|
|
|
$this->load();
|
|
|
|
|
}
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->title;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
/**
|
|
|
|
|
* Return the file name
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
|
|
|
|
public function getName() {
|
2014-05-22 20:46:13 +00:00
|
|
|
if ( $this->name === false ) {
|
|
|
|
|
$this->load();
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
return $this->name;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 12:00:58 +00:00
|
|
|
/**
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
public function getID() {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->id;
|
|
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2011-09-07 12:00:58 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2009-09-30 19:35:39 +00:00
|
|
|
public function exists() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2009-09-30 19:35:39 +00:00
|
|
|
return $this->exists;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
/**
|
|
|
|
|
* Return the FileStore key
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
|
|
|
|
public function getKey() {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->key;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
In Special:RevisionDelete:
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.
Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText
FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
|
|
|
/**
|
|
|
|
|
* Return the FileStore key (overriding base File class)
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
In Special:RevisionDelete:
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.
Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText
FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
|
|
|
*/
|
|
|
|
|
public function getStorageKey() {
|
|
|
|
|
return $this->getKey();
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
/**
|
|
|
|
|
* Return the FileStore storage group
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
2007-12-08 00:04:58 +00:00
|
|
|
public function getGroup() {
|
2010-09-02 22:11:32 +00:00
|
|
|
return $this->group;
|
2007-12-08 00:04:58 +00:00
|
|
|
}
|
2007-11-23 21:47:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the width of the image
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return int
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getWidth() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
return $this->width;
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the height of the image
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return int
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getHeight() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
return $this->height;
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
2022-04-07 08:18:10 +00:00
|
|
|
* Get handler-specific metadata as a serialized string
|
|
|
|
|
*
|
|
|
|
|
* @deprecated since 1.37 use getMetadataArray() or getMetadataItem()
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getMetadata() {
|
2022-04-07 08:18:10 +00:00
|
|
|
$data = $this->getMetadataArray();
|
|
|
|
|
if ( !$data ) {
|
|
|
|
|
return '';
|
|
|
|
|
} elseif ( array_keys( $data ) === [ '_error' ] ) {
|
|
|
|
|
// Legacy error encoding
|
|
|
|
|
return $data['_error'];
|
|
|
|
|
} else {
|
|
|
|
|
return serialize( $this->getMetadataArray() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get unserialized handler-specific metadata
|
|
|
|
|
*
|
|
|
|
|
* @since 1.39
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getMetadataArray(): array {
|
|
|
|
|
$this->load();
|
|
|
|
|
if ( $this->unloadedMetadataBlobs ) {
|
|
|
|
|
return $this->getMetadataItems(
|
|
|
|
|
array_unique( array_merge(
|
|
|
|
|
array_keys( $this->metadataArray ),
|
|
|
|
|
array_keys( $this->unloadedMetadataBlobs )
|
|
|
|
|
) )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return $this->metadataArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getMetadataItems( array $itemNames ): array {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->load();
|
2022-04-07 08:18:10 +00:00
|
|
|
$result = [];
|
|
|
|
|
$addresses = [];
|
|
|
|
|
foreach ( $itemNames as $itemName ) {
|
|
|
|
|
if ( array_key_exists( $itemName, $this->metadataArray ) ) {
|
|
|
|
|
$result[$itemName] = $this->metadataArray[$itemName];
|
|
|
|
|
} elseif ( isset( $this->unloadedMetadataBlobs[$itemName] ) ) {
|
|
|
|
|
$addresses[$itemName] = $this->unloadedMetadataBlobs[$itemName];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $addresses ) {
|
|
|
|
|
$resultFromBlob = $this->metadataStorageHelper->getMetadataFromBlobStore( $addresses );
|
|
|
|
|
foreach ( $addresses as $itemName => $address ) {
|
|
|
|
|
unset( $this->unloadedMetadataBlobs[$itemName] );
|
|
|
|
|
$value = $resultFromBlob[$itemName] ?? null;
|
|
|
|
|
if ( $value !== null ) {
|
|
|
|
|
$result[$itemName] = $value;
|
|
|
|
|
$this->metadataArray[$itemName] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2022-04-07 08:18:10 +00:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* @internal
|
2024-05-23 20:34:21 +00:00
|
|
|
* @param IReadableDatabase $db
|
2022-04-07 08:18:10 +00:00
|
|
|
* @return string|Blob
|
|
|
|
|
*/
|
2024-05-23 20:34:21 +00:00
|
|
|
public function getMetadataForDb( IReadableDatabase $db ) {
|
2022-04-07 08:18:10 +00:00
|
|
|
$this->load();
|
|
|
|
|
if ( !$this->metadataArray && !$this->metadataBlobs ) {
|
|
|
|
|
$s = '';
|
|
|
|
|
} elseif ( $this->repo->isJsonMetadataEnabled() ) {
|
|
|
|
|
$s = $this->getJsonMetadata();
|
|
|
|
|
} else {
|
|
|
|
|
$s = serialize( $this->getMetadataArray() );
|
|
|
|
|
}
|
|
|
|
|
if ( !is_string( $s ) ) {
|
2023-06-10 16:13:20 +00:00
|
|
|
throw new RuntimeException( 'Could not serialize image metadata value for DB' );
|
2022-04-07 08:18:10 +00:00
|
|
|
}
|
|
|
|
|
return $db->encodeBlob( $s );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get metadata in JSON format ready for DB insertion, optionally splitting
|
|
|
|
|
* items out to BlobStore.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getJsonMetadata() {
|
|
|
|
|
// Directly store data that is not already in BlobStore
|
|
|
|
|
$envelope = [
|
|
|
|
|
'data' => array_diff_key( $this->metadataArray, $this->metadataBlobs )
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Also store the blob addresses
|
|
|
|
|
if ( $this->metadataBlobs ) {
|
|
|
|
|
$envelope['blobs'] = $this->metadataBlobs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ $s, $blobAddresses ] = $this->metadataStorageHelper->getJsonMetadata( $this, $envelope );
|
|
|
|
|
|
|
|
|
|
// Repeated calls to this function should not keep inserting more blobs
|
|
|
|
|
$this->metadataBlobs += $blobAddresses;
|
|
|
|
|
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unserialize a metadata blob which came from the database and store it
|
|
|
|
|
* in $this.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.39
|
2023-05-03 10:41:45 +00:00
|
|
|
* @param IReadableDatabase $db
|
2022-04-07 08:18:10 +00:00
|
|
|
* @param string|Blob $metadataBlob
|
|
|
|
|
*/
|
2023-05-03 10:41:45 +00:00
|
|
|
protected function loadMetadataFromDbFieldValue( IReadableDatabase $db, $metadataBlob ) {
|
2022-04-07 08:18:10 +00:00
|
|
|
$this->loadMetadataFromString( $db->decodeBlob( $metadataBlob ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unserialize a metadata string which came from some non-DB source, or is
|
2024-05-23 20:34:21 +00:00
|
|
|
* the return value of IReadableDatabase::decodeBlob().
|
2022-04-07 08:18:10 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @param string $metadataString
|
|
|
|
|
*/
|
|
|
|
|
protected function loadMetadataFromString( $metadataString ) {
|
|
|
|
|
$this->extraDataLoaded = true;
|
|
|
|
|
$this->metadataArray = [];
|
|
|
|
|
$this->metadataBlobs = [];
|
|
|
|
|
$this->unloadedMetadataBlobs = [];
|
|
|
|
|
$metadataString = (string)$metadataString;
|
|
|
|
|
if ( $metadataString === '' ) {
|
|
|
|
|
$this->metadataSerializationFormat = self::MDS_EMPTY;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( $metadataString[0] === '{' ) {
|
|
|
|
|
$envelope = $this->metadataStorageHelper->jsonDecode( $metadataString );
|
|
|
|
|
if ( !$envelope ) {
|
|
|
|
|
// Legacy error encoding
|
|
|
|
|
$this->metadataArray = [ '_error' => $metadataString ];
|
|
|
|
|
$this->metadataSerializationFormat = self::MDS_LEGACY;
|
|
|
|
|
} else {
|
|
|
|
|
$this->metadataSerializationFormat = self::MDS_JSON;
|
|
|
|
|
if ( isset( $envelope['data'] ) ) {
|
|
|
|
|
$this->metadataArray = $envelope['data'];
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $envelope['blobs'] ) ) {
|
|
|
|
|
$this->metadataBlobs = $this->unloadedMetadataBlobs = $envelope['blobs'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
|
|
|
|
|
$data = @unserialize( $metadataString );
|
|
|
|
|
if ( !is_array( $data ) ) {
|
|
|
|
|
// Legacy error encoding
|
|
|
|
|
$data = [ '_error' => $metadataString ];
|
|
|
|
|
$this->metadataSerializationFormat = self::MDS_LEGACY;
|
|
|
|
|
} else {
|
|
|
|
|
$this->metadataSerializationFormat = self::MDS_PHP;
|
|
|
|
|
}
|
|
|
|
|
$this->metadataArray = $data;
|
|
|
|
|
}
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the size of the image file, in bytes
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return int
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getSize() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->size;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
/**
|
|
|
|
|
* Return the bits of the image file, in bytes
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return int
|
2007-12-08 00:04:58 +00:00
|
|
|
*/
|
|
|
|
|
public function getBits() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
return $this->bits;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
2014-07-24 14:04:48 +00:00
|
|
|
* Returns the MIME type of the file.
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getMimeType() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->mime;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
2011-03-13 22:58:41 +00:00
|
|
|
* Get a MediaHandler instance for this file
|
|
|
|
|
* @return MediaHandler
|
|
|
|
|
*/
|
2020-05-17 23:02:18 +00:00
|
|
|
private function getHandler() {
|
2011-03-13 22:58:41 +00:00
|
|
|
if ( !isset( $this->handler ) ) {
|
|
|
|
|
$this->handler = MediaHandler::getHandler( $this->getMimeType() );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-03-13 22:58:41 +00:00
|
|
|
return $this->handler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of pages of a multipage document, or false for
|
|
|
|
|
* documents which aren't multipage documents
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2019-12-28 19:51:21 +00:00
|
|
|
* @return int|false
|
2011-03-13 22:58:41 +00:00
|
|
|
*/
|
2020-05-17 23:02:18 +00:00
|
|
|
public function pageCount() {
|
2011-03-13 22:58:41 +00:00
|
|
|
if ( !isset( $this->pageCount ) ) {
|
2016-09-18 05:29:06 +00:00
|
|
|
// @FIXME: callers expect File objects
|
2019-06-18 20:26:00 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
2011-03-13 22:58:41 +00:00
|
|
|
if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
|
2019-06-18 20:26:00 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
2011-03-13 22:58:41 +00:00
|
|
|
$this->pageCount = $this->handler->pageCount( $this );
|
|
|
|
|
} else {
|
|
|
|
|
$this->pageCount = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-03-13 22:58:41 +00:00
|
|
|
return $this->pageCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-11-23 21:47:00 +00:00
|
|
|
* Return the type of the media in the file.
|
|
|
|
|
* Use the value returned by this function with the MEDIATYPE_xxx constants.
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getMediaType() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->media_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return upload timestamp.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getTimestamp() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-11-07 21:19:34 +00:00
|
|
|
return wfTimestamp( TS_MW, $this->timestamp );
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-14 18:58:25 +00:00
|
|
|
/**
|
|
|
|
|
* Get the SHA-1 base 36 hash of the file
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*/
|
2020-05-17 23:02:18 +00:00
|
|
|
public function getSha1() {
|
2012-10-14 18:58:25 +00:00
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2012-10-14 18:58:25 +00:00
|
|
|
return $this->sha1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 16:48:33 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @stable to override
|
|
|
|
|
* @param int $audience One 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
|
|
|
|
|
* @param Authority|null $performer to check for, only if FOR_THIS_USER is
|
|
|
|
|
* passed to the $audience parameter
|
|
|
|
|
* @return UserIdentity|null
|
|
|
|
|
*/
|
2024-10-16 18:58:33 +00:00
|
|
|
public function getUploader( int $audience = self::FOR_PUBLIC, ?Authority $performer = null ): ?UserIdentity {
|
2021-06-02 16:48:33 +00:00
|
|
|
$this->load();
|
|
|
|
|
if ( $audience === self::FOR_PUBLIC && $this->isDeleted( File::DELETED_USER ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
} elseif ( $audience === self::FOR_THIS_USER && !$this->userCan( File::DELETED_USER, $performer ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->user;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return upload description.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2021-06-02 16:48:33 +00:00
|
|
|
* @since 1.37 the method takes $audience and $performer parameters.
|
|
|
|
|
* @param int $audience One 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
|
|
|
|
|
* @param Authority|null $performer to check for, only if FOR_THIS_USER is
|
|
|
|
|
* passed to the $audience parameter
|
|
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
2024-10-16 18:58:33 +00:00
|
|
|
public function getDescription( int $audience = self::FOR_PUBLIC, ?Authority $performer = null ): string {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->load();
|
2021-06-02 16:48:33 +00:00
|
|
|
if ( $audience === self::FOR_PUBLIC && $this->isDeleted( File::DELETED_COMMENT ) ) {
|
|
|
|
|
return '';
|
|
|
|
|
} elseif ( $audience === self::FOR_THIS_USER && !$this->userCan( File::DELETED_COMMENT, $performer ) ) {
|
|
|
|
|
return '';
|
2007-11-23 21:47:00 +00:00
|
|
|
} else {
|
|
|
|
|
return $this->description;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-09-19 16:28:25 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the deletion bitfield
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getVisibility() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2009-09-19 16:28:25 +00:00
|
|
|
return $this->deleted;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* for file or revision rows
|
2010-02-15 22:06:18 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $field One of DELETED_* bitfield constants
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-11-23 21:47:00 +00:00
|
|
|
public function isDeleted( $field ) {
|
2009-09-30 19:16:37 +00:00
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2013-05-17 14:47:00 +00:00
|
|
|
return ( $this->deleted & $field ) == $field;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Determine if the current user is allowed to view a particular
|
|
|
|
|
* field of this FileStore image file, if it's marked as deleted.
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $field
|
2021-04-05 19:43:12 +00:00
|
|
|
* @param Authority $performer
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2021-04-05 19:43:12 +00:00
|
|
|
public function userCan( $field, Authority $performer ) {
|
2009-09-30 19:16:37 +00:00
|
|
|
$this->load();
|
2014-08-18 18:13:25 +00:00
|
|
|
$title = $this->getTitle();
|
2020-02-23 21:48:54 +00:00
|
|
|
|
|
|
|
|
return RevisionRecord::userCanBitfield(
|
|
|
|
|
$this->deleted,
|
|
|
|
|
$field,
|
2021-04-05 19:43:12 +00:00
|
|
|
$performer,
|
2020-02-23 21:48:54 +00:00
|
|
|
$title ?: null
|
|
|
|
|
);
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|