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' ) );
123 if ( $dbr->numRows( $res ) == 0 ) {
124 // this revision does not exist?
127 $ret = $dbr->resultObject( $res );
128 $row = $ret->fetchObject();
130 // initialize fields for filestore image object
131 $this->id = intval($row->fa_id);
132 $this->name = $row->fa_name;
133 $this->archive_name = $row->fa_archive_name;
134 $this->group = $row->fa_storage_group;
135 $this->key = $row->fa_storage_key;
136 $this->size = $row->fa_size;
137 $this->bits = $row->fa_bits;
138 $this->width = $row->fa_width;
139 $this->height = $row->fa_height;
140 $this->metadata = $row->fa_metadata;
141 $this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
142 $this->media_type = $row->fa_media_type;
143 $this->description = $row->fa_description;
144 $this->user = $row->fa_user;
145 $this->user_text = $row->fa_user_text;
146 $this->timestamp = $row->fa_timestamp;
147 $this->deleted = $row->fa_deleted;
149 throw new MWException( 'This title does not correspond to an image page.' );
151 $this->dataLoaded = true;
152 $this->exists = true;
158 * Loads a file object from the filearchive table
159 * @return ArchivedFile
161 public static function newFromRow( $row ) {
162 $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
164 $file->id = intval($row->fa_id);
165 $file->name = $row->fa_name;
166 $file->archive_name = $row->fa_archive_name;
167 $file->group = $row->fa_storage_group;
168 $file->key = $row->fa_storage_key;
169 $file->size = $row->fa_size;
170 $file->bits = $row->fa_bits;
171 $file->width = $row->fa_width;
172 $file->height = $row->fa_height;
173 $file->metadata = $row->fa_metadata;
174 $file->mime = "$row->fa_major_mime/$row->fa_minor_mime";
175 $file->media_type = $row->fa_media_type;
176 $file->description = $row->fa_description;
177 $file->user = $row->fa_user;
178 $file->user_text = $row->fa_user_text;
179 $file->timestamp = $row->fa_timestamp;
180 $file->deleted = $row->fa_deleted;
186 * Return the associated title object
188 public function getTitle() {
193 * Return the file name
195 public function getName() {
199 public function getID() {
204 public function exists() {
206 return $this->exists;
210 * Return the FileStore key
212 public function getKey() {
218 * Return the FileStore key (overriding base File class)
220 public function getStorageKey() {
221 return $this->getKey();
225 * Return the FileStore storage group
227 public function getGroup() {
232 * Return the width of the image
234 public function getWidth() {
240 * Return the height of the image
242 public function getHeight() {
244 return $this->height;
248 * Get handler-specific metadata
250 public function getMetadata() {
252 return $this->metadata;
256 * Return the size of the image file, in bytes
258 public function getSize() {
264 * Return the bits of the image file, in bytes
266 public function getBits() {
272 * Returns the mime type of the file.
274 public function getMimeType() {
280 * Return the type of the media in the file.
281 * Use the value returned by this function with the MEDIATYPE_xxx constants.
283 public function getMediaType() {
285 return $this->media_type;
289 * Return upload timestamp.
291 public function getTimestamp() {
293 return wfTimestamp( TS_MW, $this->timestamp );
297 * Return the user ID of the uploader.
299 public function getUser() {
301 if( $this->isDeleted( File::DELETED_USER ) ) {
309 * Return the user name of the uploader.
311 public function getUserText() {
313 if( $this->isDeleted( File::DELETED_USER ) ) {
316 return $this->user_text;
321 * Return upload description.
323 public function getDescription() {
325 if( $this->isDeleted( File::DELETED_COMMENT ) ) {
328 return $this->description;
333 * Return the user ID of the uploader.
335 public function getRawUser() {
341 * Return the user name of the uploader.
343 public function getRawUserText() {
345 return $this->user_text;
349 * Return upload description.
351 public function getRawDescription() {
353 return $this->description;
357 * Returns the deletion bitfield
360 public function getVisibility() {
362 return $this->deleted;
366 * for file or revision rows
368 * @param $field Integer: one of DELETED_* bitfield constants
371 public function isDeleted( $field ) {
373 return ($this->deleted & $field) == $field;
377 * Determine if the current user is allowed to view a particular
378 * field of this FileStore image file, if it's marked as deleted.
379 * @param $field Integer
382 public function userCan( $field ) {
384 return Revision::userCanBitfield( $this->deleted, $field );