4 * Class to represent a file in the oldimage table
8 class OldLocalFile
extends LocalFile
{
9 var $requestedTime, $archive_name;
11 const CACHE_VERSION
= 1;
12 const MAX_CACHE_ROWS
= 20;
14 static function newFromTitle( $title, $repo, $time = null ) {
15 # The null default value is only here to avoid an E_STRICT
17 throw new MWException( __METHOD__
.' got null for $time parameter' );
18 return new self( $title, $repo, $time, null );
21 static function newFromArchiveName( $title, $repo, $archiveName ) {
22 return new self( $title, $repo, null, $archiveName );
25 static function newFromRow( $row, $repo ) {
26 $title = Title
::makeTitle( NS_FILE
, $row->oi_name
);
27 $file = new self( $title, $repo, null, $row->oi_archive_name
);
28 $file->loadFromRow( $row, 'oi_' );
32 static function newFromKey( $sha1, $repo, $timestamp = false ) {
33 $conds = array( 'oi_sha1' => $sha1 );
35 $conds['oi_timestamp'] = $timestamp;
37 $dbr = $repo->getSlaveDB();
38 $row = $dbr->selectRow( 'oldimage', self
::selectFields(), $conds, __METHOD__
);
40 return self
::newFromRow( $row, $repo );
47 * Fields in the oldimage table
49 static function selectFields() {
72 * @param $repo FileRepo
73 * @param $time String: timestamp or null to load by archive name
74 * @param $archiveName String: archive name or null to load by timestamp
76 function __construct( $title, $repo, $time, $archiveName ) {
77 parent
::__construct( $title, $repo );
78 $this->requestedTime
= $time;
79 $this->archive_name
= $archiveName;
80 if ( is_null( $time ) && is_null( $archiveName ) ) {
81 throw new MWException( __METHOD__
.': must specify at least one of $time or $archiveName' );
85 function getCacheKey() {
89 function getArchiveName() {
90 if ( !isset( $this->archive_name
) ) {
93 return $this->archive_name
;
100 function isVisible() {
101 return $this->exists() && !$this->isDeleted(File
::DELETED_FILE
);
104 function loadFromDB() {
105 wfProfileIn( __METHOD__
);
106 $this->dataLoaded
= true;
107 $dbr = $this->repo
->getSlaveDB();
108 $conds = array( 'oi_name' => $this->getName() );
109 if ( is_null( $this->requestedTime
) ) {
110 $conds['oi_archive_name'] = $this->archive_name
;
112 $conds[] = 'oi_timestamp = ' . $dbr->addQuotes( $dbr->timestamp( $this->requestedTime
) );
114 $row = $dbr->selectRow( 'oldimage', $this->getCacheFields( 'oi_' ),
115 $conds, __METHOD__
, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
117 $this->loadFromRow( $row, 'oi_' );
119 $this->fileExists
= false;
121 wfProfileOut( __METHOD__
);
124 function getCacheFields( $prefix = 'img_' ) {
125 $fields = parent
::getCacheFields( $prefix );
126 $fields[] = $prefix . 'archive_name';
127 $fields[] = $prefix . 'deleted';
132 return 'archive/' . $this->getHashPath() . $this->getArchiveName();
135 function getUrlRel() {
136 return 'archive/' . $this->getHashPath() . urlencode( $this->getArchiveName() );
139 function upgradeRow() {
140 wfProfileIn( __METHOD__
);
141 $this->loadFromFile();
143 # Don't destroy file info of missing files
144 if ( !$this->fileExists
) {
145 wfDebug( __METHOD__
.": file does not exist, aborting\n" );
146 wfProfileOut( __METHOD__
);
150 $dbw = $this->repo
->getMasterDB();
151 list( $major, $minor ) = self
::splitMime( $this->mime
);
153 wfDebug(__METHOD__
.': upgrading '.$this->archive_name
." to the current schema\n");
154 $dbw->update( 'oldimage',
156 'oi_width' => $this->width
,
157 'oi_height' => $this->height
,
158 'oi_bits' => $this->bits
,
159 'oi_media_type' => $this->media_type
,
160 'oi_major_mime' => $major,
161 'oi_minor_mime' => $minor,
162 'oi_metadata' => $this->metadata
,
163 'oi_sha1' => $this->sha1
,
165 'oi_name' => $this->getName(),
166 'oi_archive_name' => $this->archive_name
),
169 wfProfileOut( __METHOD__
);
173 * @param $field Integer: one of DELETED_* bitfield constants
174 * for file or revision rows
177 function isDeleted( $field ) {
179 return ($this->deleted
& $field) == $field;
183 * Returns bitfield value
186 function getVisibility() {
188 return (int)$this->deleted
;
192 * Determine if the current user is allowed to view a particular
193 * field of this image file, if it's marked as deleted.
195 * @param $field Integer
198 function userCan( $field ) {
200 return Revision
::userCanBitfield( $this->deleted
, $field );