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
|
|
|
* Deleted file in the 'filearchive' table.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
2012-02-08 15:51:16 +00:00
|
|
|
* @ingroup FileAbstraction
|
2010-09-04 18:13:18 +00:00
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2010-09-04 18:13:18 +00:00
|
|
|
* Class representing a row of the 'filearchive' table
|
|
|
|
|
*
|
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 {
|
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
|
|
|
|
2013-11-24 08:34:22 +00:00
|
|
|
/** @var string File name */
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/** @var string Metadata string */
|
|
|
|
|
private $metadata;
|
|
|
|
|
|
|
|
|
|
/** @var string MIME type */
|
|
|
|
|
private $mime;
|
|
|
|
|
|
|
|
|
|
/** @var string Media type */
|
|
|
|
|
private $media_type;
|
|
|
|
|
|
|
|
|
|
/** @var string Upload description */
|
|
|
|
|
private $description;
|
|
|
|
|
|
|
|
|
|
/** @var int User ID of uploader */
|
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
|
|
/** @var string User name of uploader */
|
|
|
|
|
private $user_text;
|
|
|
|
|
|
|
|
|
|
/** @var string Time of upload */
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/** @var string Number of pages of a multipage document, or false for
|
|
|
|
|
* 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
|
|
|
|
2013-11-24 08:34:22 +00:00
|
|
|
/** @var Title */
|
|
|
|
|
protected $title; # image title
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-03-14 01:04:16 +00:00
|
|
|
/**
|
|
|
|
|
* @throws MWException
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @param string $key
|
|
|
|
|
*/
|
2013-02-03 19:42:08 +00:00
|
|
|
function __construct( $title, $id = 0, $key = '' ) {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->id = -1;
|
2008-11-18 02:20:55 +00:00
|
|
|
$this->title = false;
|
|
|
|
|
$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->metadata = '';
|
|
|
|
|
$this->mime = "unknown/unknown";
|
|
|
|
|
$this->media_type = '';
|
|
|
|
|
$this->description = '';
|
|
|
|
|
$this->user = 0;
|
|
|
|
|
$this->user_text = '';
|
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
|
|
|
|
2011-11-04 23:49:03 +00:00
|
|
|
if ( !$id && !$key && !( $title instanceof Title ) ) {
|
2008-11-18 02:20:55 +00:00
|
|
|
throw new MWException( "No specifications provided to ArchivedFile constructor." );
|
2011-03-14 01:04:16 +00:00
|
|
|
}
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loads a file object from the filearchive table
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
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;
|
|
|
|
|
}
|
2008-11-18 02:20:55 +00:00
|
|
|
$conds = array();
|
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
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( !count( $conds ) ) {
|
2008-11-18 02:20:55 +00:00
|
|
|
throw new MWException( "No specific information for retrieving archived file" );
|
2011-03-14 01:04:16 +00:00
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2013-04-20 17:18:13 +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
|
2007-05-30 21:02:32 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2013-02-09 14:59:13 +00:00
|
|
|
$row = $dbr->selectRow(
|
|
|
|
|
'filearchive',
|
|
|
|
|
self::selectFields(),
|
2008-11-18 02:20:55 +00:00
|
|
|
$conds,
|
2007-05-30 21:02:32 +00:00
|
|
|
__METHOD__,
|
2013-02-09 22:03:53 +00:00
|
|
|
array( 'ORDER BY' => 'fa_timestamp DESC' )
|
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 {
|
|
|
|
|
throw new MWException( 'This title does not correspond to an image page.' );
|
|
|
|
|
}
|
2009-09-30 19:35:39 +00:00
|
|
|
$this->exists = true;
|
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
|
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
|
|
|
|
2013-02-09 14:59:13 +00:00
|
|
|
/**
|
|
|
|
|
* Fields in the filearchive table
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
static function selectFields() {
|
|
|
|
|
return array(
|
|
|
|
|
'fa_id',
|
|
|
|
|
'fa_name',
|
|
|
|
|
'fa_archive_name',
|
|
|
|
|
'fa_storage_key',
|
|
|
|
|
'fa_storage_group',
|
|
|
|
|
'fa_size',
|
|
|
|
|
'fa_bits',
|
|
|
|
|
'fa_width',
|
|
|
|
|
'fa_height',
|
|
|
|
|
'fa_metadata',
|
|
|
|
|
'fa_media_type',
|
|
|
|
|
'fa_major_mime',
|
|
|
|
|
'fa_minor_mime',
|
|
|
|
|
'fa_description',
|
|
|
|
|
'fa_user',
|
|
|
|
|
'fa_user_text',
|
|
|
|
|
'fa_timestamp',
|
|
|
|
|
'fa_deleted',
|
2013-07-09 16:41:48 +00:00
|
|
|
'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
|
2013-02-09 14:59:13 +00:00
|
|
|
'fa_sha1',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-14 18:58:25 +00:00
|
|
|
/**
|
|
|
|
|
* Load ArchivedFile object fields from a DB row.
|
|
|
|
|
*
|
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;
|
|
|
|
|
$this->metadata = $row->fa_metadata;
|
|
|
|
|
$this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
|
|
|
|
|
$this->media_type = $row->fa_media_type;
|
|
|
|
|
$this->description = $row->fa_description;
|
|
|
|
|
$this->user = $row->fa_user;
|
|
|
|
|
$this->user_text = $row->fa_user_text;
|
|
|
|
|
$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 );
|
|
|
|
|
}
|
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
|
|
|
/**
|
|
|
|
|
* Get handler-specific metadata
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getMetadata() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->metadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
function getHandler() {
|
|
|
|
|
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
|
2014-08-23 20:34:25 +00:00
|
|
|
* @return bool|int
|
2011-03-13 22:58:41 +00:00
|
|
|
*/
|
|
|
|
|
function pageCount() {
|
|
|
|
|
if ( !isset( $this->pageCount ) ) {
|
|
|
|
|
if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
|
|
|
|
|
$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
|
|
|
|
|
*/
|
|
|
|
|
function getSha1() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2012-10-14 18:58:25 +00:00
|
|
|
return $this->sha1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
2013-12-12 20:01:50 +00:00
|
|
|
* Returns ID or name of user who uploaded the file
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2013-12-12 20:01:50 +00:00
|
|
|
* @note Prior to MediaWiki 1.23, this method always
|
|
|
|
|
* returned the user id, and was inconsistent with
|
|
|
|
|
* the rest of the file classes.
|
|
|
|
|
* @param string $type 'text' or 'id'
|
|
|
|
|
* @return int|string
|
2013-12-27 17:00:39 +00:00
|
|
|
* @throws MWException
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
2013-12-12 20:01:50 +00:00
|
|
|
public function getUser( $type = 'text' ) {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->load();
|
2013-12-12 20:01:50 +00:00
|
|
|
|
|
|
|
|
if ( $type == 'text' ) {
|
|
|
|
|
return $this->user_text;
|
|
|
|
|
} elseif ( $type == 'id' ) {
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->user;
|
|
|
|
|
}
|
2013-12-27 17:00:39 +00:00
|
|
|
|
|
|
|
|
throw new MWException( "Unknown type '$type'." );
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return the user name of the uploader.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2014-04-15 20:18:19 +00:00
|
|
|
* @deprecated since 1.23 Use getUser( 'text' ) instead.
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getUserText() {
|
2013-12-12 20:01:50 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.23' );
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->load();
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $this->isDeleted( File::DELETED_USER ) ) {
|
2007-11-23 21:47:00 +00:00
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->user_text;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return upload description.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getDescription() {
|
|
|
|
|
$this->load();
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $this->isDeleted( File::DELETED_COMMENT ) ) {
|
2007-11-23 21:47:00 +00:00
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->description;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return the user ID of the uploader.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return int
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getRawUser() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->user;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return the user name of the uploader.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getRawUserText() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->user_text;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return upload description.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-11-23 21:47:00 +00:00
|
|
|
*/
|
|
|
|
|
public function getRawDescription() {
|
|
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->description;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
* @param null|User $user User object to check, or null to use $wgUser
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-10-12 15:09:04 +00:00
|
|
|
public function userCan( $field, User $user = null ) {
|
2009-09-30 19:16:37 +00:00
|
|
|
$this->load();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2014-08-18 18:13:25 +00:00
|
|
|
$title = $this->getTitle();
|
|
|
|
|
return Revision::userCanBitfield( $this->deleted, $field, $user, $title ? : null );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|