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( $title instanceof Title
) {
77 $this->title
= File
::normalizeTitle( $title, 'exception' );
78 $this->name
= $title->getDBkey();
89 if ( !$id && !$key && !( $title instanceof 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
183 * @return ArchivedFile
185 public static function newFromRow( $row ) {
186 $file = new ArchivedFile( Title
::makeTitle( NS_FILE
, $row->fa_name
) );
188 $file->id
= intval($row->fa_id
);
189 $file->name
= $row->fa_name
;
190 $file->archive_name
= $row->fa_archive_name
;
191 $file->group
= $row->fa_storage_group
;
192 $file->key
= $row->fa_storage_key
;
193 $file->size
= $row->fa_size
;
194 $file->bits
= $row->fa_bits
;
195 $file->width
= $row->fa_width
;
196 $file->height
= $row->fa_height
;
197 $file->metadata
= $row->fa_metadata
;
198 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
199 $file->media_type
= $row->fa_media_type
;
200 $file->description
= $row->fa_description
;
201 $file->user
= $row->fa_user
;
202 $file->user_text
= $row->fa_user_text
;
203 $file->timestamp
= $row->fa_timestamp
;
204 $file->deleted
= $row->fa_deleted
;
210 * Return the associated title object
214 public function getTitle() {
219 * Return the file name
223 public function getName() {
230 public function getID() {
238 public function exists() {
240 return $this->exists
;
244 * Return the FileStore key
247 public function getKey() {
253 * Return the FileStore key (overriding base File class)
256 public function getStorageKey() {
257 return $this->getKey();
261 * Return the FileStore storage group
264 public function getGroup() {
269 * Return the width of the image
272 public function getWidth() {
278 * Return the height of the image
281 public function getHeight() {
283 return $this->height
;
287 * Get handler-specific metadata
290 public function getMetadata() {
292 return $this->metadata
;
296 * Return the size of the image file, in bytes
299 public function getSize() {
305 * Return the bits of the image file, in bytes
308 public function getBits() {
314 * Returns the mime type of the file.
317 public function getMimeType() {
323 * Get a MediaHandler instance for this file
324 * @return MediaHandler
326 function getHandler() {
327 if ( !isset( $this->handler
) ) {
328 $this->handler
= MediaHandler
::getHandler( $this->getMimeType() );
330 return $this->handler
;
334 * Returns the number of pages of a multipage document, or false for
335 * documents which aren't multipage documents
337 function pageCount() {
338 if ( !isset( $this->pageCount
) ) {
339 if ( $this->getHandler() && $this->handler
->isMultiPage( $this ) ) {
340 $this->pageCount
= $this->handler
->pageCount( $this );
342 $this->pageCount
= false;
345 return $this->pageCount
;
349 * Return the type of the media in the file.
350 * Use the value returned by this function with the MEDIATYPE_xxx constants.
353 public function getMediaType() {
355 return $this->media_type
;
359 * Return upload timestamp.
363 public function getTimestamp() {
365 return wfTimestamp( TS_MW
, $this->timestamp
);
369 * Return the user ID of the uploader.
373 public function getUser() {
375 if( $this->isDeleted( File
::DELETED_USER
) ) {
383 * Return the user name of the uploader.
387 public function getUserText() {
389 if( $this->isDeleted( File
::DELETED_USER
) ) {
392 return $this->user_text
;
397 * Return upload description.
401 public function getDescription() {
403 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
406 return $this->description
;
411 * Return the user ID of the uploader.
415 public function getRawUser() {
421 * Return the user name of the uploader.
425 public function getRawUserText() {
427 return $this->user_text
;
431 * Return upload description.
435 public function getRawDescription() {
437 return $this->description
;
441 * Returns the deletion bitfield
444 public function getVisibility() {
446 return $this->deleted
;
450 * for file or revision rows
452 * @param $field Integer: one of DELETED_* bitfield constants
455 public function isDeleted( $field ) {
457 return ($this->deleted
& $field) == $field;
461 * Determine if the current user is allowed to view a particular
462 * field of this FileStore image file, if it's marked as deleted.
463 * @param $field Integer
464 * @param $user User object to check, or null to use $wgUser
467 public function userCan( $field, User
$user = null ) {
469 return Revision
::userCanBitfield( $this->deleted
, $field, $user );