2007-05-30 21:02:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Media
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
class ArchivedFile
|
|
|
|
|
{
|
2007-11-23 21:47:00 +00:00
|
|
|
/**#@+
|
|
|
|
|
* @private
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-11-23 21:47:00 +00:00
|
|
|
var $id, # filearchive row ID
|
|
|
|
|
$title, # image title
|
|
|
|
|
$name, # image name
|
|
|
|
|
$group, # FileStore storage group
|
|
|
|
|
$key, # FileStore sha1 key
|
|
|
|
|
$size, # file dimensions
|
|
|
|
|
$bits, # size in bytes
|
|
|
|
|
$width, # width
|
|
|
|
|
$height, # height
|
|
|
|
|
$metadata, # metadata string
|
|
|
|
|
$mime, # mime type
|
|
|
|
|
$media_type, # media type
|
|
|
|
|
$description, # upload description
|
|
|
|
|
$user, # user ID of uploader
|
|
|
|
|
$user_text, # user name of uploader
|
|
|
|
|
$timestamp, # time of upload
|
|
|
|
|
$dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
|
|
|
|
|
$deleted; # Bitfield akin to rev_deleted
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
|
|
|
/**#@-*/
|
|
|
|
|
|
2010-08-30 16:52:51 +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;
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2008-11-18 02:20:55 +00:00
|
|
|
if( is_object($title) ) {
|
|
|
|
|
$this->title = $title;
|
|
|
|
|
$this->name = $title->getDBkey();
|
|
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2008-11-18 02:20:55 +00:00
|
|
|
if ($id)
|
|
|
|
|
$this->id = $id;
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2008-11-18 02:20:55 +00:00
|
|
|
if ($key)
|
|
|
|
|
$this->key = $key;
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2008-11-18 02:20:55 +00:00
|
|
|
if (!$id && !$key && !is_object($title))
|
|
|
|
|
throw new MWException( "No specifications provided to ArchivedFile constructor." );
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loads a file object from the filearchive table
|
2010-02-15 22:06:18 +00:00
|
|
|
* @return 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
|
|
|
|
2009-03-20 20:39:13 +00:00
|
|
|
if( $this->id > 0 )
|
2008-11-18 02:20:55 +00:00
|
|
|
$conds['fa_id'] = $this->id;
|
2009-03-20 20:39: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;
|
|
|
|
|
}
|
|
|
|
|
if( $this->title )
|
2008-11-18 02:20:55 +00:00
|
|
|
$conds['fa_name'] = $this->title->getDBkey();
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2009-03-20 20:39:13 +00:00
|
|
|
if( !count($conds))
|
2008-11-18 02:20:55 +00:00
|
|
|
throw new MWException( "No specific information for retrieving archived file" );
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2008-12-01 17:14:30 +00:00
|
|
|
if( !$this->title || $this->title->getNamespace() == NS_FILE ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
$res = $dbr->select( 'filearchive',
|
|
|
|
|
array(
|
|
|
|
|
'fa_id',
|
|
|
|
|
'fa_name',
|
2007-11-23 21:47:00 +00:00
|
|
|
'fa_archive_name',
|
2007-05-30 21:02:32 +00:00
|
|
|
'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' ),
|
2008-11-18 02:20:55 +00:00
|
|
|
$conds,
|
2007-05-30 21:02:32 +00:00
|
|
|
__METHOD__,
|
|
|
|
|
array( 'ORDER BY' => 'fa_timestamp DESC' ) );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $dbr->numRows( $res ) == 0 ) {
|
|
|
|
|
// this revision does not exist?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$ret = $dbr->resultObject( $res );
|
|
|
|
|
$row = $ret->fetchObject();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
// initialize fields for filestore image object
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->id = intval($row->fa_id);
|
|
|
|
|
$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;
|
2007-05-30 21:02:32 +00:00
|
|
|
} else {
|
|
|
|
|
throw new MWException( 'This title does not correspond to an image page.' );
|
|
|
|
|
}
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->dataLoaded = true;
|
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
|
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 ) );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
$file->id = intval($row->fa_id);
|
|
|
|
|
$file->name = $row->fa_name;
|
|
|
|
|
$file->archive_name = $row->fa_archive_name;
|
|
|
|
|
$file->group = $row->fa_storage_group;
|
|
|
|
|
$file->key = $row->fa_storage_key;
|
|
|
|
|
$file->size = $row->fa_size;
|
|
|
|
|
$file->bits = $row->fa_bits;
|
|
|
|
|
$file->width = $row->fa_width;
|
|
|
|
|
$file->height = $row->fa_height;
|
|
|
|
|
$file->metadata = $row->fa_metadata;
|
|
|
|
|
$file->mime = "$row->fa_major_mime/$row->fa_minor_mime";
|
|
|
|
|
$file->media_type = $row->fa_media_type;
|
|
|
|
|
$file->description = $row->fa_description;
|
|
|
|
|
$file->user = $row->fa_user;
|
|
|
|
|
$file->user_text = $row->fa_user_text;
|
|
|
|
|
$file->timestamp = $row->fa_timestamp;
|
|
|
|
|
$file->deleted = $row->fa_deleted;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
return $file;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return the associated title object
|
|
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
public function getTitle() {
|
2007-11-23 21:47:00 +00:00
|
|
|
return $this->title;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
/**
|
|
|
|
|
* Return the file name
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
|
|
|
|
public function getName() {
|
2007-12-08 00:04:58 +00:00
|
|
|
return $this->name;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
public function getID() {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->load();
|
|
|
|
|
return $this->id;
|
|
|
|
|
}
|
2010-02-12 06:44:16 +00:00
|
|
|
|
2009-09-30 19:35:39 +00:00
|
|
|
public function exists() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->exists;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
/**
|
|
|
|
|
* Return the FileStore key
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
|
|
|
|
public function getKey() {
|
2007-11-23 21:47:00 +00:00
|
|
|
$this->load();
|
|
|
|
|
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)
|
|
|
|
|
*/
|
|
|
|
|
public function getStorageKey() {
|
|
|
|
|
return $this->getKey();
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-08 00:04:58 +00:00
|
|
|
/**
|
|
|
|
|
* Return the FileStore storage group
|
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
|
|
|
|
|
*/
|
|
|
|
|
public function getWidth() {
|
|
|
|
|
$this->load();
|
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
|
|
|
|
|
*/
|
|
|
|
|
public function getHeight() {
|
|
|
|
|
$this->load();
|
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
|
|
|
|
|
*/
|
|
|
|
|
public function getMetadata() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->metadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the size of the image file, in bytes
|
|
|
|
|
*/
|
|
|
|
|
public function getSize() {
|
|
|
|
|
$this->load();
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
public function getBits() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->bits;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the mime type of the file.
|
|
|
|
|
*/
|
|
|
|
|
public function getMimeType() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->mime;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
public function getMediaType() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->media_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return upload timestamp.
|
|
|
|
|
*/
|
|
|
|
|
public function getTimestamp() {
|
|
|
|
|
$this->load();
|
2008-11-07 21:19:34 +00:00
|
|
|
return wfTimestamp( TS_MW, $this->timestamp );
|
2007-11-23 21:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the user ID of the uploader.
|
|
|
|
|
*/
|
|
|
|
|
public function getUser() {
|
|
|
|
|
$this->load();
|
|
|
|
|
if( $this->isDeleted( File::DELETED_USER ) ) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
public function getUserText() {
|
|
|
|
|
$this->load();
|
|
|
|
|
if( $this->isDeleted( File::DELETED_USER ) ) {
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
public function getDescription() {
|
|
|
|
|
$this->load();
|
|
|
|
|
if( $this->isDeleted( File::DELETED_COMMENT ) ) {
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
public function getRawUser() {
|
|
|
|
|
$this->load();
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
public function getRawUserText() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->user_text;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-23 21:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* Return upload description.
|
|
|
|
|
*/
|
|
|
|
|
public function getRawDescription() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->description;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-19 16:28:25 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the deletion bitfield
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getVisibility() {
|
|
|
|
|
$this->load();
|
|
|
|
|
return $this->deleted;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* for file or revision rows
|
2010-02-15 22:06:18 +00:00
|
|
|
*
|
|
|
|
|
* @param $field Integer: 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();
|
2007-11-23 21: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.
|
2010-02-15 22:06:18 +00:00
|
|
|
* @param $field Integer
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-11-23 21:47:00 +00:00
|
|
|
public function userCan( $field ) {
|
2009-09-30 19:16:37 +00:00
|
|
|
$this->load();
|
2009-10-15 11:31:33 +00:00
|
|
|
return Revision::userCanBitfield( $this->deleted, $field );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|