3 * Deleted file in the 'filearchive' table
10 * Class representing a row of the 'filearchive' table
18 var $id, # filearchive row ID
21 $group, # FileStore storage group
22 $key, # FileStore sha1 key
23 $size, # file dimensions
24 $bits, # size in bytes
27 $metadata, # metadata string
29 $media_type, # media type
30 $description, # upload description
31 $user, # user ID of uploader
32 $user_text, # user name of uploader
33 $timestamp, # time of upload
34 $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
35 $deleted; # Bitfield akin to rev_deleted
39 function __construct( $title, $id=0, $key='' ) {
43 $this->group
= 'deleted'; // needed for direct use of constructor
50 $this->mime
= "unknown/unknown";
51 $this->media_type
= '';
52 $this->description
= '';
54 $this->user_text
= '';
55 $this->timestamp
= null;
57 $this->dataLoaded
= false;
58 $this->exists
= false;
60 if( is_object($title) ) {
61 $this->title
= $title;
62 $this->name
= $title->getDBkey();
71 if (!$id && !$key && !is_object($title))
72 throw new MWException( "No specifications provided to ArchivedFile constructor." );
76 * Loads a file object from the filearchive table
77 * @return true on success or null
79 public function load() {
80 if ( $this->dataLoaded
) {
86 $conds['fa_id'] = $this->id
;
88 $conds['fa_storage_group'] = $this->group
;
89 $conds['fa_storage_key'] = $this->key
;
92 $conds['fa_name'] = $this->title
->getDBkey();
95 throw new MWException( "No specific information for retrieving archived file" );
97 if( !$this->title ||
$this->title
->getNamespace() == NS_FILE
) {
98 $dbr = wfGetDB( DB_SLAVE
);
99 $res = $dbr->select( 'filearchive',
121 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
122 if ( $res == false ||
$dbr->numRows( $res ) == 0 ) {
123 // this revision does not exist?
126 $ret = $dbr->resultObject( $res );
127 $row = $ret->fetchObject();
129 // initialize fields for filestore image object
130 $this->id
= intval($row->fa_id
);
131 $this->name
= $row->fa_name
;
132 $this->archive_name
= $row->fa_archive_name
;
133 $this->group
= $row->fa_storage_group
;
134 $this->key
= $row->fa_storage_key
;
135 $this->size
= $row->fa_size
;
136 $this->bits
= $row->fa_bits
;
137 $this->width
= $row->fa_width
;
138 $this->height
= $row->fa_height
;
139 $this->metadata
= $row->fa_metadata
;
140 $this->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
141 $this->media_type
= $row->fa_media_type
;
142 $this->description
= $row->fa_description
;
143 $this->user
= $row->fa_user
;
144 $this->user_text
= $row->fa_user_text
;
145 $this->timestamp
= $row->fa_timestamp
;
146 $this->deleted
= $row->fa_deleted
;
148 throw new MWException( 'This title does not correspond to an image page.' );
150 $this->dataLoaded
= true;
151 $this->exists
= true;
157 * Loads a file object from the filearchive table
158 * @return ArchivedFile
160 public static function newFromRow( $row ) {
161 $file = new ArchivedFile( Title
::makeTitle( NS_FILE
, $row->fa_name
) );
163 $file->id
= intval($row->fa_id
);
164 $file->name
= $row->fa_name
;
165 $file->archive_name
= $row->fa_archive_name
;
166 $file->group
= $row->fa_storage_group
;
167 $file->key
= $row->fa_storage_key
;
168 $file->size
= $row->fa_size
;
169 $file->bits
= $row->fa_bits
;
170 $file->width
= $row->fa_width
;
171 $file->height
= $row->fa_height
;
172 $file->metadata
= $row->fa_metadata
;
173 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
174 $file->media_type
= $row->fa_media_type
;
175 $file->description
= $row->fa_description
;
176 $file->user
= $row->fa_user
;
177 $file->user_text
= $row->fa_user_text
;
178 $file->timestamp
= $row->fa_timestamp
;
179 $file->deleted
= $row->fa_deleted
;
185 * Return the associated title object
187 public function getTitle() {
192 * Return the file name
194 public function getName() {
198 public function getID() {
203 public function exists() {
205 return $this->exists
;
209 * Return the FileStore key
211 public function getKey() {
217 * Return the FileStore key (overriding base File class)
219 public function getStorageKey() {
220 return $this->getKey();
224 * Return the FileStore storage group
226 public function getGroup() {
231 * Return the width of the image
233 public function getWidth() {
239 * Return the height of the image
241 public function getHeight() {
243 return $this->height
;
247 * Get handler-specific metadata
249 public function getMetadata() {
251 return $this->metadata
;
255 * Return the size of the image file, in bytes
257 public function getSize() {
263 * Return the bits of the image file, in bytes
265 public function getBits() {
271 * Returns the mime type of the file.
273 public function getMimeType() {
279 * Return the type of the media in the file.
280 * Use the value returned by this function with the MEDIATYPE_xxx constants.
282 public function getMediaType() {
284 return $this->media_type
;
288 * Return upload timestamp.
290 public function getTimestamp() {
292 return wfTimestamp( TS_MW
, $this->timestamp
);
296 * Return the user ID of the uploader.
298 public function getUser() {
300 if( $this->isDeleted( File
::DELETED_USER
) ) {
308 * Return the user name of the uploader.
310 public function getUserText() {
312 if( $this->isDeleted( File
::DELETED_USER
) ) {
315 return $this->user_text
;
320 * Return upload description.
322 public function getDescription() {
324 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
327 return $this->description
;
332 * Return the user ID of the uploader.
334 public function getRawUser() {
340 * Return the user name of the uploader.
342 public function getRawUserText() {
344 return $this->user_text
;
348 * Return upload description.
350 public function getRawDescription() {
352 return $this->description
;
356 * Returns the deletion bitfield
359 public function getVisibility() {
361 return $this->deleted
;
365 * for file or revision rows
367 * @param $field Integer: one of DELETED_* bitfield constants
370 public function isDeleted( $field ) {
372 return ($this->deleted
& $field) == $field;
376 * Determine if the current user is allowed to view a particular
377 * field of this FileStore image file, if it's marked as deleted.
378 * @param $field Integer
381 public function userCan( $field ) {
383 return Revision
::userCanBitfield( $this->deleted
, $field );