be9d3f1e09b371c803f919a26dd0b35cd5f421de
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
39 var $title; # image title
43 function __construct( $title, $id=0, $key='' ) {
47 $this->group
= 'deleted'; // needed for direct use of constructor
54 $this->mime
= "unknown/unknown";
55 $this->media_type
= '';
56 $this->description
= '';
58 $this->user_text
= '';
59 $this->timestamp
= null;
61 $this->dataLoaded
= false;
62 $this->exists
= false;
64 if( is_object($title) ) {
65 $this->title
= $title;
66 $this->name
= $title->getDBkey();
75 if (!$id && !$key && !is_object($title))
76 throw new MWException( "No specifications provided to ArchivedFile constructor." );
80 * Loads a file object from the filearchive table
81 * @return true on success or null
83 public function load() {
84 if ( $this->dataLoaded
) {
90 $conds['fa_id'] = $this->id
;
92 $conds['fa_storage_group'] = $this->group
;
93 $conds['fa_storage_key'] = $this->key
;
96 $conds['fa_name'] = $this->title
->getDBkey();
99 throw new MWException( "No specific information for retrieving archived file" );
101 if( !$this->title ||
$this->title
->getNamespace() == NS_FILE
) {
102 $dbr = wfGetDB( DB_SLAVE
);
103 $res = $dbr->select( 'filearchive',
125 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
126 if ( $res == false ||
$dbr->numRows( $res ) == 0 ) {
127 // this revision does not exist?
130 $ret = $dbr->resultObject( $res );
131 $row = $ret->fetchObject();
133 // initialize fields for filestore image object
134 $this->id
= intval($row->fa_id
);
135 $this->name
= $row->fa_name
;
136 $this->archive_name
= $row->fa_archive_name
;
137 $this->group
= $row->fa_storage_group
;
138 $this->key
= $row->fa_storage_key
;
139 $this->size
= $row->fa_size
;
140 $this->bits
= $row->fa_bits
;
141 $this->width
= $row->fa_width
;
142 $this->height
= $row->fa_height
;
143 $this->metadata
= $row->fa_metadata
;
144 $this->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
145 $this->media_type
= $row->fa_media_type
;
146 $this->description
= $row->fa_description
;
147 $this->user
= $row->fa_user
;
148 $this->user_text
= $row->fa_user_text
;
149 $this->timestamp
= $row->fa_timestamp
;
150 $this->deleted
= $row->fa_deleted
;
152 throw new MWException( 'This title does not correspond to an image page.' );
154 $this->dataLoaded
= true;
155 $this->exists
= true;
161 * Loads a file object from the filearchive table
162 * @return ArchivedFile
164 public static function newFromRow( $row ) {
165 $file = new ArchivedFile( Title
::makeTitle( NS_FILE
, $row->fa_name
) );
167 $file->id
= intval($row->fa_id
);
168 $file->name
= $row->fa_name
;
169 $file->archive_name
= $row->fa_archive_name
;
170 $file->group
= $row->fa_storage_group
;
171 $file->key
= $row->fa_storage_key
;
172 $file->size
= $row->fa_size
;
173 $file->bits
= $row->fa_bits
;
174 $file->width
= $row->fa_width
;
175 $file->height
= $row->fa_height
;
176 $file->metadata
= $row->fa_metadata
;
177 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
178 $file->media_type
= $row->fa_media_type
;
179 $file->description
= $row->fa_description
;
180 $file->user
= $row->fa_user
;
181 $file->user_text
= $row->fa_user_text
;
182 $file->timestamp
= $row->fa_timestamp
;
183 $file->deleted
= $row->fa_deleted
;
189 * Return the associated title object
191 public function getTitle() {
196 * Return the file name
198 public function getName() {
202 public function getID() {
207 public function exists() {
209 return $this->exists
;
213 * Return the FileStore key
215 public function getKey() {
221 * Return the FileStore key (overriding base File class)
223 public function getStorageKey() {
224 return $this->getKey();
228 * Return the FileStore storage group
230 public function getGroup() {
235 * Return the width of the image
237 public function getWidth() {
243 * Return the height of the image
245 public function getHeight() {
247 return $this->height
;
251 * Get handler-specific metadata
253 public function getMetadata() {
255 return $this->metadata
;
259 * Return the size of the image file, in bytes
261 public function getSize() {
267 * Return the bits of the image file, in bytes
269 public function getBits() {
275 * Returns the mime type of the file.
277 public function getMimeType() {
283 * Return the type of the media in the file.
284 * Use the value returned by this function with the MEDIATYPE_xxx constants.
286 public function getMediaType() {
288 return $this->media_type
;
292 * Return upload timestamp.
294 public function getTimestamp() {
296 return wfTimestamp( TS_MW
, $this->timestamp
);
300 * Return the user ID of the uploader.
302 public function getUser() {
304 if( $this->isDeleted( File
::DELETED_USER
) ) {
312 * Return the user name of the uploader.
314 public function getUserText() {
316 if( $this->isDeleted( File
::DELETED_USER
) ) {
319 return $this->user_text
;
324 * Return upload description.
326 public function getDescription() {
328 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
331 return $this->description
;
336 * Return the user ID of the uploader.
338 public function getRawUser() {
344 * Return the user name of the uploader.
346 public function getRawUserText() {
348 return $this->user_text
;
352 * Return upload description.
354 public function getRawDescription() {
356 return $this->description
;
360 * Returns the deletion bitfield
363 public function getVisibility() {
365 return $this->deleted
;
369 * for file or revision rows
371 * @param $field Integer: one of DELETED_* bitfield constants
374 public function isDeleted( $field ) {
376 return ($this->deleted
& $field) == $field;
380 * Determine if the current user is allowed to view a particular
381 * field of this FileStore image file, if it's marked as deleted.
382 * @param $field Integer
385 public function userCan( $field ) {
387 return Revision
::userCanBitfield( $this->deleted
, $field );