fe1b73020cb58f708a26dbad13faa9b57a8fd158
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() {
164 * Return the file name
166 public function getName() {
170 public function getID() {
176 * Return the FileStore key
178 public function getKey() {
184 * Return the FileStore storage group
186 public function getGroup() {
191 * Return the width of the image
193 public function getWidth() {
199 * Return the height of the image
201 public function getHeight() {
203 return $this->height
;
207 * Get handler-specific metadata
209 public function getMetadata() {
211 return $this->metadata
;
215 * Return the size of the image file, in bytes
218 public function getSize() {
224 * Return the bits of the image file, in bytes
227 public function getBits() {
233 * Returns the mime type of the file.
235 public function getMimeType() {
241 * Return the type of the media in the file.
242 * Use the value returned by this function with the MEDIATYPE_xxx constants.
244 public function getMediaType() {
246 return $this->media_type
;
250 * Return upload timestamp.
252 public function getTimestamp() {
254 return $this->timestamp
;
258 * Return the user ID of the uploader.
260 public function getUser() {
262 if( $this->isDeleted( File
::DELETED_USER
) ) {
270 * Return the user name of the uploader.
272 public function getUserText() {
274 if( $this->isDeleted( File
::DELETED_USER
) ) {
277 return $this->user_text
;
282 * Return upload description.
284 public function getDescription() {
286 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
289 return $this->description
;
294 * Return the user ID of the uploader.
296 public function getRawUser() {
302 * Return the user name of the uploader.
304 public function getRawUserText() {
306 return $this->user_text
;
310 * Return upload description.
312 public function getRawDescription() {
314 return $this->description
;
318 * int $field one of DELETED_* bitfield constants
319 * for file or revision rows
322 public function isDeleted( $field ) {
323 return ($this->deleted
& $field) == $field;
327 * Determine if the current user is allowed to view a particular
328 * field of this FileStore image file, if it's marked as deleted.
332 public function userCan( $field ) {
333 if( ($this->deleted
& $field) == $field ) {
335 $permission = ( $this->deleted
& File
::DELETED_RESTRICTED
) == File
::DELETED_RESTRICTED
338 wfDebug( "Checking for $permission due to $field match on $this->deleted\n" );
339 return $wgUser->isAllowed( $permission );