3 * Deleted file in the 'filearchive' table
10 * Class representing a row of the 'filearchive' table
18 var $id, # filearchive row ID
20 $group, # FileStore storage group
21 $key, # FileStore sha1 key
22 $size, # file dimensions
23 $bits, # size in bytes
26 $metadata, # metadata string
28 $media_type, # media type
29 $description, # upload description
30 $user, # user ID of uploader
31 $user_text, # user name of uploader
32 $timestamp, # time of upload
33 $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
34 $deleted, # Bitfield akin to rev_deleted
45 var $title; # image title
55 function __construct( $title, $id=0, $key='' ) {
59 $this->group
= 'deleted'; // needed for direct use of constructor
66 $this->mime
= "unknown/unknown";
67 $this->media_type
= '';
68 $this->description
= '';
70 $this->user_text
= '';
71 $this->timestamp
= null;
73 $this->dataLoaded
= false;
74 $this->exists
= false;
76 if( is_object( $title ) ) {
77 $this->title
= $title;
78 $this->name
= $title->getDBkey();
89 if ( !$id && !$key && !is_object( $title ) ) {
90 throw new MWException( "No specifications provided to ArchivedFile constructor." );
95 * Loads a file object from the filearchive table
96 * @return true on success or null
98 public function load() {
99 if ( $this->dataLoaded
) {
104 if( $this->id
> 0 ) {
105 $conds['fa_id'] = $this->id
;
108 $conds['fa_storage_group'] = $this->group
;
109 $conds['fa_storage_key'] = $this->key
;
112 $conds['fa_name'] = $this->title
->getDBkey();
115 if( !count($conds)) {
116 throw new MWException( "No specific information for retrieving archived file" );
119 if( !$this->title ||
$this->title
->getNamespace() == NS_FILE
) {
120 $dbr = wfGetDB( DB_SLAVE
);
121 $res = $dbr->select( 'filearchive',
143 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
144 if ( $res == false ||
$dbr->numRows( $res ) == 0 ) {
145 // this revision does not exist?
148 $ret = $dbr->resultObject( $res );
149 $row = $ret->fetchObject();
151 // initialize fields for filestore image object
152 $this->id
= intval($row->fa_id
);
153 $this->name
= $row->fa_name
;
154 $this->archive_name
= $row->fa_archive_name
;
155 $this->group
= $row->fa_storage_group
;
156 $this->key
= $row->fa_storage_key
;
157 $this->size
= $row->fa_size
;
158 $this->bits
= $row->fa_bits
;
159 $this->width
= $row->fa_width
;
160 $this->height
= $row->fa_height
;
161 $this->metadata
= $row->fa_metadata
;
162 $this->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
163 $this->media_type
= $row->fa_media_type
;
164 $this->description
= $row->fa_description
;
165 $this->user
= $row->fa_user
;
166 $this->user_text
= $row->fa_user_text
;
167 $this->timestamp
= $row->fa_timestamp
;
168 $this->deleted
= $row->fa_deleted
;
170 throw new MWException( 'This title does not correspond to an image page.' );
172 $this->dataLoaded
= true;
173 $this->exists
= true;
179 * Loads a file object from the filearchive table
180 * @return ArchivedFile
182 public static function newFromRow( $row ) {
183 $file = new ArchivedFile( Title
::makeTitle( NS_FILE
, $row->fa_name
) );
185 $file->id
= intval($row->fa_id
);
186 $file->name
= $row->fa_name
;
187 $file->archive_name
= $row->fa_archive_name
;
188 $file->group
= $row->fa_storage_group
;
189 $file->key
= $row->fa_storage_key
;
190 $file->size
= $row->fa_size
;
191 $file->bits
= $row->fa_bits
;
192 $file->width
= $row->fa_width
;
193 $file->height
= $row->fa_height
;
194 $file->metadata
= $row->fa_metadata
;
195 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
196 $file->media_type
= $row->fa_media_type
;
197 $file->description
= $row->fa_description
;
198 $file->user
= $row->fa_user
;
199 $file->user_text
= $row->fa_user_text
;
200 $file->timestamp
= $row->fa_timestamp
;
201 $file->deleted
= $row->fa_deleted
;
207 * Return the associated title object
209 public function getTitle() {
214 * Return the file name
216 public function getName() {
220 public function getID() {
225 public function exists() {
227 return $this->exists
;
231 * Return the FileStore key
233 public function getKey() {
239 * Return the FileStore key (overriding base File class)
241 public function getStorageKey() {
242 return $this->getKey();
246 * Return the FileStore storage group
248 public function getGroup() {
253 * Return the width of the image
255 public function getWidth() {
261 * Return the height of the image
263 public function getHeight() {
265 return $this->height
;
269 * Get handler-specific metadata
271 public function getMetadata() {
273 return $this->metadata
;
277 * Return the size of the image file, in bytes
279 public function getSize() {
285 * Return the bits of the image file, in bytes
287 public function getBits() {
293 * Returns the mime type of the file.
295 public function getMimeType() {
301 * Get a MediaHandler instance for this file
302 * @return MediaHandler
304 function getHandler() {
305 if ( !isset( $this->handler
) ) {
306 $this->handler
= MediaHandler
::getHandler( $this->getMimeType() );
308 return $this->handler
;
312 * Returns the number of pages of a multipage document, or false for
313 * documents which aren't multipage documents
315 function pageCount() {
316 if ( !isset( $this->pageCount
) ) {
317 if ( $this->getHandler() && $this->handler
->isMultiPage( $this ) ) {
318 $this->pageCount
= $this->handler
->pageCount( $this );
320 $this->pageCount
= false;
323 return $this->pageCount
;
327 * Return the type of the media in the file.
328 * Use the value returned by this function with the MEDIATYPE_xxx constants.
330 public function getMediaType() {
332 return $this->media_type
;
336 * Return upload timestamp.
338 public function getTimestamp() {
340 return wfTimestamp( TS_MW
, $this->timestamp
);
344 * Return the user ID of the uploader.
346 public function getUser() {
348 if( $this->isDeleted( File
::DELETED_USER
) ) {
356 * Return the user name of the uploader.
358 public function getUserText() {
360 if( $this->isDeleted( File
::DELETED_USER
) ) {
363 return $this->user_text
;
368 * Return upload description.
370 public function getDescription() {
372 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
375 return $this->description
;
380 * Return the user ID of the uploader.
382 public function getRawUser() {
388 * Return the user name of the uploader.
390 public function getRawUserText() {
392 return $this->user_text
;
396 * Return upload description.
398 public function getRawDescription() {
400 return $this->description
;
404 * Returns the deletion bitfield
407 public function getVisibility() {
409 return $this->deleted
;
413 * for file or revision rows
415 * @param $field Integer: one of DELETED_* bitfield constants
418 public function isDeleted( $field ) {
420 return ($this->deleted
& $field) == $field;
424 * Determine if the current user is allowed to view a particular
425 * field of this FileStore image file, if it's marked as deleted.
426 * @param $field Integer
429 public function userCan( $field ) {
431 return Revision
::userCanBitfield( $this->deleted
, $field );