11 var $id, # filearchive row ID
14 $group, # FileStore storage group
15 $key, # FileStore sha1 key
16 $size, # file dimensions
17 $bits, # size in bytes
20 $metadata, # metadata string
22 $media_type, # media type
23 $description, # upload description
24 $user, # user ID of uploader
25 $user_text, # user name of uploader
26 $timestamp, # time of upload
27 $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
28 $deleted; # Bitfield akin to rev_deleted
32 function ArchivedFile( $title, $id=0, $key='' ) {
36 $this->group = 'deleted'; // needed for direct use of constructor
43 $this->mime = "unknown/unknown";
44 $this->media_type = '';
45 $this->description = '';
47 $this->user_text = '';
48 $this->timestamp = null;
50 $this->dataLoaded = false;
51 $this->exists = false;
53 if( is_object($title) ) {
54 $this->title = $title;
55 $this->name = $title->getDBkey();
64 if (!$id && !$key && !is_object($title))
65 throw new MWException( "No specifications provided to ArchivedFile constructor." );
69 * Loads a file object from the filearchive table
70 * @return true on success or null
72 public function load() {
73 if ( $this->dataLoaded ) {
79 $conds['fa_id'] = $this->id;
81 $conds['fa_storage_group'] = $this->group;
82 $conds['fa_storage_key'] = $this->key;
85 $conds['fa_name'] = $this->title->getDBkey();
88 throw new MWException( "No specific information for retrieving archived file" );
90 if( !$this->title || $this->title->getNamespace() == NS_FILE ) {
91 $dbr = wfGetDB( DB_SLAVE );
92 $res = $dbr->select( 'filearchive',
114 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
116 if ( $dbr->numRows( $res ) == 0 ) {
117 // this revision does not exist?
120 $ret = $dbr->resultObject( $res );
121 $row = $ret->fetchObject();
123 // initialize fields for filestore image object
124 $this->id = intval($row->fa_id);
125 $this->name = $row->fa_name;
126 $this->archive_name = $row->fa_archive_name;
127 $this->group = $row->fa_storage_group;
128 $this->key = $row->fa_storage_key;
129 $this->size = $row->fa_size;
130 $this->bits = $row->fa_bits;
131 $this->width = $row->fa_width;
132 $this->height = $row->fa_height;
133 $this->metadata = $row->fa_metadata;
134 $this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
135 $this->media_type = $row->fa_media_type;
136 $this->description = $row->fa_description;
137 $this->user = $row->fa_user;
138 $this->user_text = $row->fa_user_text;
139 $this->timestamp = $row->fa_timestamp;
140 $this->deleted = $row->fa_deleted;
142 throw new MWException( 'This title does not correspond to an image page.' );
145 $this->dataLoaded = true;
146 $this->exists = true;
152 * Loads a file object from the filearchive table
153 * @return ArchivedFile
155 public static function newFromRow( $row ) {
156 $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
158 $file->id = intval($row->fa_id);
159 $file->name = $row->fa_name;
160 $file->archive_name = $row->fa_archive_name;
161 $file->group = $row->fa_storage_group;
162 $file->key = $row->fa_storage_key;
163 $file->size = $row->fa_size;
164 $file->bits = $row->fa_bits;
165 $file->width = $row->fa_width;
166 $file->height = $row->fa_height;
167 $file->metadata = $row->fa_metadata;
168 $file->mime = "$row->fa_major_mime/$row->fa_minor_mime";
169 $file->media_type = $row->fa_media_type;
170 $file->description = $row->fa_description;
171 $file->user = $row->fa_user;
172 $file->user_text = $row->fa_user_text;
173 $file->timestamp = $row->fa_timestamp;
174 $file->deleted = $row->fa_deleted;
180 * Return the associated title object
182 public function getTitle() {
187 * Return the file name
189 public function getName() {
193 public function getID() {
198 public function exists() {
200 return $this->exists;
204 * Return the FileStore key
206 public function getKey() {
212 * Return the FileStore key (overriding base File class)
214 public function getStorageKey() {
215 return $this->getKey();
219 * Return the FileStore storage group
221 public function getGroup() {
226 * Return the width of the image
228 public function getWidth() {
234 * Return the height of the image
236 public function getHeight() {
238 return $this->height;
242 * Get handler-specific metadata
244 public function getMetadata() {
246 return $this->metadata;
250 * Return the size of the image file, in bytes
252 public function getSize() {
258 * Return the bits of the image file, in bytes
260 public function getBits() {
266 * Returns the mime type of the file.
268 public function getMimeType() {
274 * Return the type of the media in the file.
275 * Use the value returned by this function with the MEDIATYPE_xxx constants.
277 public function getMediaType() {
279 return $this->media_type;
283 * Return upload timestamp.
285 public function getTimestamp() {
287 return wfTimestamp( TS_MW, $this->timestamp );
291 * Return the user ID of the uploader.
293 public function getUser() {
295 if( $this->isDeleted( File::DELETED_USER ) ) {
303 * Return the user name of the uploader.
305 public function getUserText() {
307 if( $this->isDeleted( File::DELETED_USER ) ) {
310 return $this->user_text;
315 * Return upload description.
317 public function getDescription() {
319 if( $this->isDeleted( File::DELETED_COMMENT ) ) {
322 return $this->description;
327 * Return the user ID of the uploader.
329 public function getRawUser() {
335 * Return the user name of the uploader.
337 public function getRawUserText() {
339 return $this->user_text;
343 * Return upload description.
345 public function getRawDescription() {
347 return $this->description;
351 * Returns the deletion bitfield
354 public function getVisibility() {
356 return $this->deleted;
360 * for file or revision rows
362 * @param $field Integer: one of DELETED_* bitfield constants
365 public function isDeleted( $field ) {
367 return ($this->deleted & $field) == $field;
371 * Determine if the current user is allowed to view a particular
372 * field of this FileStore image file, if it's marked as deleted.
373 * @param $field Integer
376 public function userCan( $field ) {
378 return Revision::userCanBitfield( $this->deleted, $field );