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 ResultWrapper
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 ResultWrapper
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
183 public function getTitle() {
188 * Return the file name
190 public function getName() {
194 public function getID() {
199 public function exists() {
201 return $this->exists
;
205 * Return the FileStore key
207 public function getKey() {
213 * Return the FileStore key (overriding base File class)
215 public function getStorageKey() {
216 return $this->getKey();
220 * Return the FileStore storage group
222 public function getGroup() {
227 * Return the width of the image
229 public function getWidth() {
235 * Return the height of the image
237 public function getHeight() {
239 return $this->height
;
243 * Get handler-specific metadata
245 public function getMetadata() {
247 return $this->metadata
;
251 * Return the size of the image file, in bytes
254 public function getSize() {
260 * Return the bits of the image file, in bytes
263 public function getBits() {
269 * Returns the mime type of the file.
271 public function getMimeType() {
277 * Return the type of the media in the file.
278 * Use the value returned by this function with the MEDIATYPE_xxx constants.
280 public function getMediaType() {
282 return $this->media_type
;
286 * Return upload timestamp.
288 public function getTimestamp() {
290 return wfTimestamp( TS_MW
, $this->timestamp
);
294 * Return the user ID of the uploader.
296 public function getUser() {
298 if( $this->isDeleted( File
::DELETED_USER
) ) {
306 * Return the user name of the uploader.
308 public function getUserText() {
310 if( $this->isDeleted( File
::DELETED_USER
) ) {
313 return $this->user_text
;
318 * Return upload description.
320 public function getDescription() {
322 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
325 return $this->description
;
330 * Return the user ID of the uploader.
332 public function getRawUser() {
338 * Return the user name of the uploader.
340 public function getRawUserText() {
342 return $this->user_text
;
346 * Return upload description.
348 public function getRawDescription() {
350 return $this->description
;
354 * Returns the deletion bitfield
357 public function getVisibility() {
359 return $this->deleted
;
363 * int $field one of DELETED_* bitfield constants
364 * for file or revision rows
367 public function isDeleted( $field ) {
369 return ($this->deleted
& $field) == $field;
373 * Determine if the current user is allowed to view a particular
374 * field of this FileStore image file, if it's marked as deleted.
378 public function userCan( $field ) {
380 if( $this->deleted
& $field ) {
382 $permission = ( $this->deleted
& File
::DELETED_RESTRICTED
)
384 : ( $field & File
::DELETED_FILE
) ?
'deletedtext' : 'deletedhistory';
385 wfDebug( "Checking for $permission due to $field match on $this->deleted\n" );
386 return $wgUser->isAllowed( $permission );