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_key'] = $this->key
;
82 $conds['fa_name'] = $this->title
->getDBkey();
85 throw new MWException( "No specific information for retrieving archived file" );
87 if( !$this->title ||
$this->title
->getNamespace() == NS_IMAGE
) {
88 $dbr = wfGetDB( DB_SLAVE
);
89 $res = $dbr->select( 'filearchive',
111 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
113 if ( $dbr->numRows( $res ) == 0 ) {
114 // this revision does not exist?
117 $ret = $dbr->resultObject( $res );
118 $row = $ret->fetchObject();
120 // initialize fields for filestore image object
121 $this->id
= intval($row->fa_id
);
122 $this->name
= $row->fa_name
;
123 $this->archive_name
= $row->fa_archive_name
;
124 $this->group
= $row->fa_storage_group
;
125 $this->key
= $row->fa_storage_key
;
126 $this->size
= $row->fa_size
;
127 $this->bits
= $row->fa_bits
;
128 $this->width
= $row->fa_width
;
129 $this->height
= $row->fa_height
;
130 $this->metadata
= $row->fa_metadata
;
131 $this->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
132 $this->media_type
= $row->fa_media_type
;
133 $this->description
= $row->fa_description
;
134 $this->user
= $row->fa_user
;
135 $this->user_text
= $row->fa_user_text
;
136 $this->timestamp
= $row->fa_timestamp
;
137 $this->deleted
= $row->fa_deleted
;
139 throw new MWException( 'This title does not correspond to an image page.' );
142 $this->dataLoaded
= true;
148 * Loads a file object from the filearchive table
149 * @return ResultWrapper
151 public static function newFromRow( $row ) {
152 $file = new ArchivedFile( Title
::makeTitle( NS_IMAGE
, $row->fa_name
) );
154 $file->id
= intval($row->fa_id
);
155 $file->name
= $row->fa_name
;
156 $file->archive_name
= $row->fa_archive_name
;
157 $file->group
= $row->fa_storage_group
;
158 $file->key
= $row->fa_storage_key
;
159 $file->size
= $row->fa_size
;
160 $file->bits
= $row->fa_bits
;
161 $file->width
= $row->fa_width
;
162 $file->height
= $row->fa_height
;
163 $file->metadata
= $row->fa_metadata
;
164 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
165 $file->media_type
= $row->fa_media_type
;
166 $file->description
= $row->fa_description
;
167 $file->user
= $row->fa_user
;
168 $file->user_text
= $row->fa_user_text
;
169 $file->timestamp
= $row->fa_timestamp
;
170 $file->deleted
= $row->fa_deleted
;
176 * Return the associated title object
179 public function getTitle() {
184 * Return the file name
186 public function getName() {
190 public function getID() {
196 * Return the FileStore key
198 public function getKey() {
204 * Return the FileStore storage group
206 public function getGroup() {
211 * Return the width of the image
213 public function getWidth() {
219 * Return the height of the image
221 public function getHeight() {
223 return $this->height
;
227 * Get handler-specific metadata
229 public function getMetadata() {
231 return $this->metadata
;
235 * Return the size of the image file, in bytes
238 public function getSize() {
244 * Return the bits of the image file, in bytes
247 public function getBits() {
253 * Returns the mime type of the file.
255 public function getMimeType() {
261 * Return the type of the media in the file.
262 * Use the value returned by this function with the MEDIATYPE_xxx constants.
264 public function getMediaType() {
266 return $this->media_type
;
270 * Return upload timestamp.
272 public function getTimestamp() {
274 return wfTimestamp( TS_MW
, $this->timestamp
);
278 * Return the user ID of the uploader.
280 public function getUser() {
282 if( $this->isDeleted( File
::DELETED_USER
) ) {
290 * Return the user name of the uploader.
292 public function getUserText() {
294 if( $this->isDeleted( File
::DELETED_USER
) ) {
297 return $this->user_text
;
302 * Return upload description.
304 public function getDescription() {
306 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
309 return $this->description
;
314 * Return the user ID of the uploader.
316 public function getRawUser() {
322 * Return the user name of the uploader.
324 public function getRawUserText() {
326 return $this->user_text
;
330 * Return upload description.
332 public function getRawDescription() {
334 return $this->description
;
338 * int $field one of DELETED_* bitfield constants
339 * for file or revision rows
342 public function isDeleted( $field ) {
343 return ($this->deleted
& $field) == $field;
347 * Determine if the current user is allowed to view a particular
348 * field of this FileStore image file, if it's marked as deleted.
352 public function userCan( $field ) {
353 if( ($this->deleted
& $field) == $field ) {
355 $permission = ( $this->deleted
& File
::DELETED_RESTRICTED
) == File
::DELETED_RESTRICTED
358 wfDebug( "Checking for $permission due to $field match on $this->deleted\n" );
359 return $wgUser->isAllowed( $permission );