3 * Old file in the in the oldimage table
10 * Class to represent a file in the oldimage table
14 class OldLocalFile
extends LocalFile
{
15 var $requestedTime, $archive_name;
17 const CACHE_VERSION
= 1;
18 const MAX_CACHE_ROWS
= 20;
20 static function newFromTitle( $title, $repo, $time = null ) {
21 # The null default value is only here to avoid an E_STRICT
23 throw new MWException( __METHOD__
.' got null for $time parameter' );
24 return new self( $title, $repo, $time, null );
27 static function newFromArchiveName( $title, $repo, $archiveName ) {
28 return new self( $title, $repo, null, $archiveName );
31 static function newFromRow( $row, $repo ) {
32 $title = Title
::makeTitle( NS_FILE
, $row->oi_name
);
33 $file = new self( $title, $repo, null, $row->oi_archive_name
);
34 $file->loadFromRow( $row, 'oi_' );
38 static function newFromKey( $sha1, $repo, $timestamp = false ) {
39 $conds = array( 'oi_sha1' => $sha1 );
41 $conds['oi_timestamp'] = $timestamp;
43 $dbr = $repo->getSlaveDB();
44 $row = $dbr->selectRow( 'oldimage', self
::selectFields(), $conds, __METHOD__
);
46 return self
::newFromRow( $row, $repo );
53 * Fields in the oldimage table
55 static function selectFields() {
78 * @param $repo FileRepo
79 * @param $time String: timestamp or null to load by archive name
80 * @param $archiveName String: archive name or null to load by timestamp
82 function __construct( $title, $repo, $time, $archiveName ) {
83 parent
::__construct( $title, $repo );
84 $this->requestedTime
= $time;
85 $this->archive_name
= $archiveName;
86 if ( is_null( $time ) && is_null( $archiveName ) ) {
87 throw new MWException( __METHOD__
.': must specify at least one of $time or $archiveName' );
91 function getCacheKey() {
95 function getArchiveName() {
96 if ( !isset( $this->archive_name
) ) {
99 return $this->archive_name
;
106 function isVisible() {
107 return $this->exists() && !$this->isDeleted(File
::DELETED_FILE
);
110 function loadFromDB() {
111 wfProfileIn( __METHOD__
);
112 $this->dataLoaded
= true;
113 $dbr = $this->repo
->getSlaveDB();
114 $conds = array( 'oi_name' => $this->getName() );
115 if ( is_null( $this->requestedTime
) ) {
116 $conds['oi_archive_name'] = $this->archive_name
;
118 $conds[] = 'oi_timestamp = ' . $dbr->addQuotes( $dbr->timestamp( $this->requestedTime
) );
120 $row = $dbr->selectRow( 'oldimage', $this->getCacheFields( 'oi_' ),
121 $conds, __METHOD__
, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
123 $this->loadFromRow( $row, 'oi_' );
125 $this->fileExists
= false;
127 wfProfileOut( __METHOD__
);
130 function getCacheFields( $prefix = 'img_' ) {
131 $fields = parent
::getCacheFields( $prefix );
132 $fields[] = $prefix . 'archive_name';
133 $fields[] = $prefix . 'deleted';
138 return 'archive/' . $this->getHashPath() . $this->getArchiveName();
141 function getUrlRel() {
142 return 'archive/' . $this->getHashPath() . rawurlencode( $this->getArchiveName() );
145 function upgradeRow() {
146 wfProfileIn( __METHOD__
);
147 $this->loadFromFile();
149 # Don't destroy file info of missing files
150 if ( !$this->fileExists
) {
151 wfDebug( __METHOD__
.": file does not exist, aborting\n" );
152 wfProfileOut( __METHOD__
);
156 $dbw = $this->repo
->getMasterDB();
157 list( $major, $minor ) = self
::splitMime( $this->mime
);
159 wfDebug(__METHOD__
.': upgrading '.$this->archive_name
." to the current schema\n");
160 $dbw->update( 'oldimage',
162 'oi_width' => $this->width
,
163 'oi_height' => $this->height
,
164 'oi_bits' => $this->bits
,
165 'oi_media_type' => $this->media_type
,
166 'oi_major_mime' => $major,
167 'oi_minor_mime' => $minor,
168 'oi_metadata' => $this->metadata
,
169 'oi_sha1' => $this->sha1
,
171 'oi_name' => $this->getName(),
172 'oi_archive_name' => $this->archive_name
),
175 wfProfileOut( __METHOD__
);
179 * @param $field Integer: one of DELETED_* bitfield constants
180 * for file or revision rows
183 function isDeleted( $field ) {
185 return ($this->deleted
& $field) == $field;
189 * Returns bitfield value
192 function getVisibility() {
194 return (int)$this->deleted
;
198 * Determine if the current user is allowed to view a particular
199 * field of this image file, if it's marked as deleted.
201 * @param $field Integer
204 function userCan( $field ) {
206 return Revision
::userCanBitfield( $this->deleted
, $field );