2007-06-03 17:10:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to represent a file in the oldimage table
|
|
|
|
|
*
|
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 FileRepo
|
2007-06-03 17:10:45 +00:00
|
|
|
*/
|
|
|
|
|
class OldLocalFile extends LocalFile {
|
|
|
|
|
var $requestedTime, $archive_name;
|
|
|
|
|
|
|
|
|
|
const CACHE_VERSION = 1;
|
|
|
|
|
const MAX_CACHE_ROWS = 20;
|
|
|
|
|
|
2008-04-05 12:26:10 +00:00
|
|
|
static function newFromTitle( $title, $repo, $time = null ) {
|
|
|
|
|
# The null default value is only here to avoid an E_STRICT
|
|
|
|
|
if( $time === null )
|
|
|
|
|
throw new MWException( __METHOD__.' got null for $time parameter' );
|
2007-06-03 17:10:45 +00:00
|
|
|
return new self( $title, $repo, $time, null );
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-05 18:44:49 +00:00
|
|
|
static function newFromArchiveName( $title, $repo, $archiveName ) {
|
2007-06-03 17:10:45 +00:00
|
|
|
return new self( $title, $repo, null, $archiveName );
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-05 18:44:49 +00:00
|
|
|
static function newFromRow( $row, $repo ) {
|
2008-12-01 17:14:30 +00:00
|
|
|
$title = Title::makeTitle( NS_FILE, $row->oi_name );
|
2007-06-03 17:10:45 +00:00
|
|
|
$file = new self( $title, $repo, null, $row->oi_archive_name );
|
|
|
|
|
$file->loadFromRow( $row, 'oi_' );
|
|
|
|
|
return $file;
|
|
|
|
|
}
|
2008-05-20 02:58:40 +00:00
|
|
|
|
|
|
|
|
static function newFromKey( $sha1, $repo, $timestamp = false ) {
|
|
|
|
|
# Polymorphic function name to distinguish foreign and local fetches
|
|
|
|
|
$fname = get_class( $this ) . '::' . __FUNCTION__;
|
|
|
|
|
|
|
|
|
|
$conds = array( 'oi_sha1' => $sha1 );
|
|
|
|
|
if( $timestamp ) {
|
|
|
|
|
$conds['oi_timestamp'] = $timestamp;
|
|
|
|
|
}
|
|
|
|
|
$row = $dbr->selectRow( 'oldimage', $this->getCacheFields( 'oi_' ), $conds, $fname );
|
|
|
|
|
if( $row ) {
|
|
|
|
|
return self::newFromRow( $row, $repo );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-08 17:39:24 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fields in the oldimage table
|
|
|
|
|
*/
|
|
|
|
|
static function selectFields() {
|
|
|
|
|
return array(
|
|
|
|
|
'oi_name',
|
|
|
|
|
'oi_archive_name',
|
|
|
|
|
'oi_size',
|
|
|
|
|
'oi_width',
|
|
|
|
|
'oi_height',
|
|
|
|
|
'oi_metadata',
|
|
|
|
|
'oi_bits',
|
|
|
|
|
'oi_media_type',
|
|
|
|
|
'oi_major_mime',
|
|
|
|
|
'oi_minor_mime',
|
|
|
|
|
'oi_description',
|
|
|
|
|
'oi_user',
|
|
|
|
|
'oi_user_text',
|
|
|
|
|
'oi_timestamp',
|
2008-08-29 12:28:26 +00:00
|
|
|
'oi_deleted',
|
2008-06-08 17:39:24 +00:00
|
|
|
'oi_sha1',
|
|
|
|
|
);
|
|
|
|
|
}
|
2007-06-03 17:10:45 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param FileRepo $repo
|
|
|
|
|
* @param string $time Timestamp or null to load by archive name
|
|
|
|
|
* @param string $archiveName Archive name or null to load by timestamp
|
|
|
|
|
*/
|
|
|
|
|
function __construct( $title, $repo, $time, $archiveName ) {
|
|
|
|
|
parent::__construct( $title, $repo );
|
|
|
|
|
$this->requestedTime = $time;
|
|
|
|
|
$this->archive_name = $archiveName;
|
|
|
|
|
if ( is_null( $time ) && is_null( $archiveName ) ) {
|
|
|
|
|
throw new MWException( __METHOD__.': must specify at least one of $time or $archiveName' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCacheKey() {
|
2008-04-05 16:46:22 +00:00
|
|
|
return false;
|
2007-06-03 17:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getArchiveName() {
|
|
|
|
|
if ( !isset( $this->archive_name ) ) {
|
|
|
|
|
$this->load();
|
|
|
|
|
}
|
|
|
|
|
return $this->archive_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isOld() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
|
|
|
|
function isVisible() {
|
2008-03-15 00:27:57 +00:00
|
|
|
return $this->exists() && !$this->isDeleted(File::DELETED_FILE);
|
|
|
|
|
}
|
2007-06-03 17:10:45 +00:00
|
|
|
|
|
|
|
|
function loadFromDB() {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$this->dataLoaded = true;
|
2007-06-03 17:10:45 +00:00
|
|
|
$dbr = $this->repo->getSlaveDB();
|
|
|
|
|
$conds = array( 'oi_name' => $this->getName() );
|
|
|
|
|
if ( is_null( $this->requestedTime ) ) {
|
|
|
|
|
$conds['oi_archive_name'] = $this->archive_name;
|
|
|
|
|
} else {
|
2008-03-28 00:32:48 +00:00
|
|
|
$conds[] = 'oi_timestamp = ' . $dbr->addQuotes( $dbr->timestamp( $this->requestedTime ) );
|
2007-06-03 17:10:45 +00:00
|
|
|
}
|
|
|
|
|
$row = $dbr->selectRow( 'oldimage', $this->getCacheFields( 'oi_' ),
|
|
|
|
|
$conds, __METHOD__, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
|
|
|
|
|
if ( $row ) {
|
|
|
|
|
$this->loadFromRow( $row, 'oi_' );
|
|
|
|
|
} else {
|
|
|
|
|
$this->fileExists = false;
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2007-06-03 17:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCacheFields( $prefix = 'img_' ) {
|
|
|
|
|
$fields = parent::getCacheFields( $prefix );
|
|
|
|
|
$fields[] = $prefix . 'archive_name';
|
2008-03-15 00:27:57 +00:00
|
|
|
$fields[] = $prefix . 'deleted';
|
2007-06-03 17:10:45 +00:00
|
|
|
return $fields;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getRel() {
|
|
|
|
|
return 'archive/' . $this->getHashPath() . $this->getArchiveName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getUrlRel() {
|
|
|
|
|
return 'archive/' . $this->getHashPath() . urlencode( $this->getArchiveName() );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-06-03 17:10:45 +00:00
|
|
|
function upgradeRow() {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
$this->loadFromFile();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
# Don't destroy file info of missing files
|
|
|
|
|
if ( !$this->fileExists ) {
|
|
|
|
|
wfDebug( __METHOD__.": file does not exist, aborting\n" );
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-06-03 17:10:45 +00:00
|
|
|
|
|
|
|
|
$dbw = $this->repo->getMasterDB();
|
|
|
|
|
list( $major, $minor ) = self::splitMime( $this->mime );
|
|
|
|
|
|
|
|
|
|
wfDebug(__METHOD__.': upgrading '.$this->archive_name." to the current schema\n");
|
|
|
|
|
$dbw->update( 'oldimage',
|
|
|
|
|
array(
|
|
|
|
|
'oi_width' => $this->width,
|
|
|
|
|
'oi_height' => $this->height,
|
|
|
|
|
'oi_bits' => $this->bits,
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
'oi_media_type' => $this->media_type,
|
|
|
|
|
'oi_major_mime' => $major,
|
|
|
|
|
'oi_minor_mime' => $minor,
|
|
|
|
|
'oi_metadata' => $this->metadata,
|
2007-07-22 14:45:12 +00:00
|
|
|
'oi_sha1' => $this->sha1,
|
2008-04-14 07:45:50 +00:00
|
|
|
), array(
|
|
|
|
|
'oi_name' => $this->getName(),
|
2007-07-22 14:45:12 +00:00
|
|
|
'oi_archive_name' => $this->archive_name ),
|
2007-06-03 17:10:45 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-03-15 00:27:57 +00:00
|
|
|
/**
|
|
|
|
|
* int $field one of DELETED_* bitfield constants
|
|
|
|
|
* for file or revision rows
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function isDeleted( $field ) {
|
2009-10-15 10:20:19 +00:00
|
|
|
$this->load();
|
2008-03-15 00:27:57 +00:00
|
|
|
return ($this->deleted & $field) == $field;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-09-12 22:02:51 +00:00
|
|
|
/**
|
|
|
|
|
* Returns bitfield value
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
function getVisibility() {
|
2009-10-15 10:20:19 +00:00
|
|
|
$this->load();
|
2009-09-12 22:02:51 +00:00
|
|
|
return (int)$this->deleted;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-15 00:27:57 +00:00
|
|
|
/**
|
|
|
|
|
* Determine if the current user is allowed to view a particular
|
2009-07-20 05:19:40 +00:00
|
|
|
* field of this image file, if it's marked as deleted.
|
2008-04-14 07:45:50 +00:00
|
|
|
* @param int $field
|
2008-03-15 00:27:57 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function userCan( $field ) {
|
2009-10-15 10:20:19 +00:00
|
|
|
$this->load();
|
2009-10-15 11:31:33 +00:00
|
|
|
return Revision::userCanBitfield( $this->deleted, $field );
|
2008-03-15 00:27:57 +00:00
|
|
|
}
|
|
|
|
|
}
|