368a561edf29a86df6622399837f912cc7c454ed
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.' );
144 $this->dataLoaded
= true;
145 $this->exists
= true;
151 * Loads a file object from the filearchive table
152 * @return ArchivedFile
154 public static function newFromRow( $row ) {
155 $file = new ArchivedFile( Title
::makeTitle( NS_FILE
, $row->fa_name
) );
157 $file->id
= intval($row->fa_id
);
158 $file->name
= $row->fa_name
;
159 $file->archive_name
= $row->fa_archive_name
;
160 $file->group
= $row->fa_storage_group
;
161 $file->key
= $row->fa_storage_key
;
162 $file->size
= $row->fa_size
;
163 $file->bits
= $row->fa_bits
;
164 $file->width
= $row->fa_width
;
165 $file->height
= $row->fa_height
;
166 $file->metadata
= $row->fa_metadata
;
167 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
168 $file->media_type
= $row->fa_media_type
;
169 $file->description
= $row->fa_description
;
170 $file->user
= $row->fa_user
;
171 $file->user_text
= $row->fa_user_text
;
172 $file->timestamp
= $row->fa_timestamp
;
173 $file->deleted
= $row->fa_deleted
;
179 * Return the associated title object
181 public function getTitle() {
186 * Return the file name
188 public function getName() {
192 public function getID() {
197 public function exists() {
199 return $this->exists
;
203 * Return the FileStore key
205 public function getKey() {
211 * Return the FileStore key (overriding base File class)
213 public function getStorageKey() {
214 return $this->getKey();
218 * Return the FileStore storage group
220 public function getGroup() {
225 * Return the width of the image
227 public function getWidth() {
233 * Return the height of the image
235 public function getHeight() {
237 return $this->height
;
241 * Get handler-specific metadata
243 public function getMetadata() {
245 return $this->metadata
;
249 * Return the size of the image file, in bytes
251 public function getSize() {
257 * Return the bits of the image file, in bytes
259 public function getBits() {
265 * Returns the mime type of the file.
267 public function getMimeType() {
273 * Return the type of the media in the file.
274 * Use the value returned by this function with the MEDIATYPE_xxx constants.
276 public function getMediaType() {
278 return $this->media_type
;
282 * Return upload timestamp.
284 public function getTimestamp() {
286 return wfTimestamp( TS_MW
, $this->timestamp
);
290 * Return the user ID of the uploader.
292 public function getUser() {
294 if( $this->isDeleted( File
::DELETED_USER
) ) {
302 * Return the user name of the uploader.
304 public function getUserText() {
306 if( $this->isDeleted( File
::DELETED_USER
) ) {
309 return $this->user_text
;
314 * Return upload description.
316 public function getDescription() {
318 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
321 return $this->description
;
326 * Return the user ID of the uploader.
328 public function getRawUser() {
334 * Return the user name of the uploader.
336 public function getRawUserText() {
338 return $this->user_text
;
342 * Return upload description.
344 public function getRawDescription() {
346 return $this->description
;
350 * Returns the deletion bitfield
353 public function getVisibility() {
355 return $this->deleted
;
359 * for file or revision rows
361 * @param $field Integer: one of DELETED_* bitfield constants
364 public function isDeleted( $field ) {
366 return ($this->deleted
& $field) == $field;
370 * Determine if the current user is allowed to view a particular
371 * field of this FileStore image file, if it's marked as deleted.
372 * @param $field Integer
375 public function userCan( $field ) {
377 return Revision
::userCanBitfield( $this->deleted
, $field );