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='' ) {
43 $this->mime
= "unknown/unknown";
44 $this->media_type
= '';
45 $this->description
= '';
47 $this->user_text
= '';
48 $this->timestamp
= NULL;
50 $this->dataLoaded
= false;
52 if( is_object($title) ) {
53 $this->title
= $title;
54 $this->name
= $title->getDBkey();
63 if (!$id && !$key && !is_object($title))
64 throw new MWException( "No specifications provided to ArchivedFile constructor." );
68 * Loads a file object from the filearchive table
69 * @return ResultWrapper
71 public function load() {
72 if ( $this->dataLoaded
) {
78 $conds['fa_id'] = $this->id
;
80 $conds['fa_storage_group'] = $this->group
;
81 $conds['fa_storage_key'] = $this->key
;
84 $conds['fa_name'] = $this->title
->getDBkey();
87 throw new MWException( "No specific information for retrieving archived file" );
89 if( !$this->title ||
$this->title
->getNamespace() == NS_FILE
) {
90 $dbr = wfGetDB( DB_SLAVE
);
91 $res = $dbr->select( 'filearchive',
113 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
115 if ( $dbr->numRows( $res ) == 0 ) {
116 // this revision does not exist?
119 $ret = $dbr->resultObject( $res );
120 $row = $ret->fetchObject();
122 // initialize fields for filestore image object
123 $this->id
= intval($row->fa_id
);
124 $this->name
= $row->fa_name
;
125 $this->archive_name
= $row->fa_archive_name
;
126 $this->group
= $row->fa_storage_group
;
127 $this->key
= $row->fa_storage_key
;
128 $this->size
= $row->fa_size
;
129 $this->bits
= $row->fa_bits
;
130 $this->width
= $row->fa_width
;
131 $this->height
= $row->fa_height
;
132 $this->metadata
= $row->fa_metadata
;
133 $this->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
134 $this->media_type
= $row->fa_media_type
;
135 $this->description
= $row->fa_description
;
136 $this->user
= $row->fa_user
;
137 $this->user_text
= $row->fa_user_text
;
138 $this->timestamp
= $row->fa_timestamp
;
139 $this->deleted
= $row->fa_deleted
;
141 throw new MWException( 'This title does not correspond to an image page.' );
144 $this->dataLoaded
= true;
150 * Loads a file object from the filearchive table
151 * @return ResultWrapper
153 public static function newFromRow( $row ) {
154 $file = new ArchivedFile( Title
::makeTitle( NS_FILE
, $row->fa_name
) );
156 $file->id
= intval($row->fa_id
);
157 $file->name
= $row->fa_name
;
158 $file->archive_name
= $row->fa_archive_name
;
159 $file->group
= $row->fa_storage_group
;
160 $file->key
= $row->fa_storage_key
;
161 $file->size
= $row->fa_size
;
162 $file->bits
= $row->fa_bits
;
163 $file->width
= $row->fa_width
;
164 $file->height
= $row->fa_height
;
165 $file->metadata
= $row->fa_metadata
;
166 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
167 $file->media_type
= $row->fa_media_type
;
168 $file->description
= $row->fa_description
;
169 $file->user
= $row->fa_user
;
170 $file->user_text
= $row->fa_user_text
;
171 $file->timestamp
= $row->fa_timestamp
;
172 $file->deleted
= $row->fa_deleted
;
178 * Return the associated title object
181 public function getTitle() {
186 * Return the file name
188 public function getName() {
192 public function getID() {
198 * Return the FileStore key
200 public function getKey() {
206 * Return the FileStore storage group
208 public function getGroup() {
213 * Return the width of the image
215 public function getWidth() {
221 * Return the height of the image
223 public function getHeight() {
225 return $this->height
;
229 * Get handler-specific metadata
231 public function getMetadata() {
233 return $this->metadata
;
237 * Return the size of the image file, in bytes
240 public function getSize() {
246 * Return the bits of the image file, in bytes
249 public function getBits() {
255 * Returns the mime type of the file.
257 public function getMimeType() {
263 * Return the type of the media in the file.
264 * Use the value returned by this function with the MEDIATYPE_xxx constants.
266 public function getMediaType() {
268 return $this->media_type
;
272 * Return upload timestamp.
274 public function getTimestamp() {
276 return wfTimestamp( TS_MW
, $this->timestamp
);
280 * Return the user ID of the uploader.
282 public function getUser() {
284 if( $this->isDeleted( File
::DELETED_USER
) ) {
292 * Return the user name of the uploader.
294 public function getUserText() {
296 if( $this->isDeleted( File
::DELETED_USER
) ) {
299 return $this->user_text
;
304 * Return upload description.
306 public function getDescription() {
308 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
311 return $this->description
;
316 * Return the user ID of the uploader.
318 public function getRawUser() {
324 * Return the user name of the uploader.
326 public function getRawUserText() {
328 return $this->user_text
;
332 * Return upload description.
334 public function getRawDescription() {
336 return $this->description
;
340 * int $field one of DELETED_* bitfield constants
341 * for file or revision rows
344 public function isDeleted( $field ) {
345 return ($this->deleted
& $field) == $field;
349 * Determine if the current user is allowed to view a particular
350 * field of this FileStore image file, if it's marked as deleted.
354 public function userCan( $field ) {
355 if( ($this->deleted
& $field) == $field ) {
357 $permission = ( $this->deleted
& File
::DELETED_RESTRICTED
) == File
::DELETED_RESTRICTED
360 wfDebug( "Checking for $permission due to $field match on $this->deleted\n" );
361 return $wgUser->isAllowed( $permission );