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='' ) {
33 if( !is_object($title) ) {
34 throw new MWException( 'ArchivedFile constructor given bogus title.' );
37 $this->title
= $title;
38 $this->name
= $title->getDBKey();
46 $this->mime
= "unknown/unknown";
47 $this->media_type
= '';
48 $this->description
= '';
50 $this->user_text
= '';
51 $this->timestamp
= NULL;
53 $this->dataLoaded
= false;
57 * Loads a file object from the filearchive table
58 * @return ResultWrapper
60 public function load() {
61 if ( $this->dataLoaded
) {
64 $conds = ($this->id
) ?
"fa_id = {$this->id}" : "fa_storage_key = '{$this->key}'";
65 if( $this->title
->getNamespace() == NS_IMAGE
) {
66 $dbr = wfGetDB( DB_SLAVE
);
67 $res = $dbr->select( 'filearchive',
88 'fa_name' => $this->title
->getDBKey(),
91 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
93 if ( $dbr->numRows( $res ) == 0 ) {
94 // this revision does not exist?
97 $ret = $dbr->resultObject( $res );
98 $row = $ret->fetchObject();
100 // initialize fields for filestore image object
101 $this->id
= intval($row->fa_id
);
102 $this->name
= $row->fa_name
;
103 $this->archive_name
= $row->fa_archive_name
;
104 $this->group
= $row->fa_storage_group
;
105 $this->key
= $row->fa_storage_key
;
106 $this->size
= $row->fa_size
;
107 $this->bits
= $row->fa_bits
;
108 $this->width
= $row->fa_width
;
109 $this->height
= $row->fa_height
;
110 $this->metadata
= $row->fa_metadata
;
111 $this->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
112 $this->media_type
= $row->fa_media_type
;
113 $this->description
= $row->fa_description
;
114 $this->user
= $row->fa_user
;
115 $this->user_text
= $row->fa_user_text
;
116 $this->timestamp
= $row->fa_timestamp
;
117 $this->deleted
= $row->fa_deleted
;
119 throw new MWException( 'This title does not correspond to an image page.' );
122 $this->dataLoaded
= true;
128 * Loads a file object from the filearchive table
129 * @return ResultWrapper
131 public static function newFromRow( $row ) {
132 $file = new ArchivedFile( Title
::makeTitle( NS_IMAGE
, $row->fa_name
) );
134 $file->id
= intval($row->fa_id
);
135 $file->name
= $row->fa_name
;
136 $file->archive_name
= $row->fa_archive_name
;
137 $file->group
= $row->fa_storage_group
;
138 $file->key
= $row->fa_storage_key
;
139 $file->size
= $row->fa_size
;
140 $file->bits
= $row->fa_bits
;
141 $file->width
= $row->fa_width
;
142 $file->height
= $row->fa_height
;
143 $file->metadata
= $row->fa_metadata
;
144 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
145 $file->media_type
= $row->fa_media_type
;
146 $file->description
= $row->fa_description
;
147 $file->user
= $row->fa_user
;
148 $file->user_text
= $row->fa_user_text
;
149 $file->timestamp
= $row->fa_timestamp
;
150 $file->deleted
= $row->fa_deleted
;
156 * Return the associated title object
159 public function getTitle() {
163 public function getID() {
168 public function getKey() {
174 * Return the width of the image
176 public function getWidth() {
182 * Return the height of the image
184 public function getHeight() {
186 return $this->height
;
190 * Get handler-specific metadata
192 public function getMetadata() {
194 return $this->metadata
;
198 * Return the size of the image file, in bytes
201 public function getSize() {
207 * Returns the mime type of the file.
209 public function getMimeType() {
215 * Return the type of the media in the file.
216 * Use the value returned by this function with the MEDIATYPE_xxx constants.
218 public function getMediaType() {
220 return $this->media_type
;
224 * Return upload timestamp.
226 public function getTimestamp() {
228 return $this->timestamp
;
232 * Return the user ID of the uploader.
234 public function getUser() {
236 if( $this->isDeleted( File
::DELETED_USER
) ) {
244 * Return the user name of the uploader.
246 public function getUserText() {
248 if( $this->isDeleted( File
::DELETED_USER
) ) {
251 return $this->user_text
;
256 * Return upload description.
258 public function getDescription() {
260 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
263 return $this->description
;
268 * Return the user ID of the uploader.
270 public function getRawUser() {
276 * Return the user name of the uploader.
278 public function getRawUserText() {
280 return $this->user_text
;
284 * Return upload description.
286 public function getRawDescription() {
288 return $this->description
;
292 * int $field one of DELETED_* bitfield constants
293 * for file or revision rows
296 public function isDeleted( $field ) {
297 return ($this->deleted
& $field) == $field;
301 * Determine if the current user is allowed to view a particular
302 * field of this FileStore image file, if it's marked as deleted.
306 public function userCan( $field ) {
307 if( isset($this->deleted
) && ($this->deleted
& $field) == $field ) {
310 $permission = ( $this->deleted
& File
::DELETED_RESTRICTED
) == File
::DELETED_RESTRICTED
313 wfDebug( "Checking for $permission due to $field match on $this->deleted\n" );
314 return $wgUser->isAllowed( $permission );