3 * Deleted file in the 'filearchive' table.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup FileAbstraction
25 * Class representing a row of the 'filearchive' table
27 * @ingroup FileAbstraction
33 var $id, # filearchive row ID
35 $group, # FileStore storage group
36 $key, # FileStore sha1 key
37 $size, # file dimensions
38 $bits, # size in bytes
41 $metadata, # metadata string
43 $media_type, # media type
44 $description, # upload description
45 $user, # user ID of uploader
46 $user_text, # user name of uploader
47 $timestamp, # time of upload
48 $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
49 $deleted, # Bitfield akin to rev_deleted
60 var $title; # image title
70 function __construct( $title, $id=0, $key='' ) {
74 $this->group
= 'deleted'; // needed for direct use of constructor
81 $this->mime
= "unknown/unknown";
82 $this->media_type
= '';
83 $this->description
= '';
85 $this->user_text
= '';
86 $this->timestamp
= null;
88 $this->dataLoaded
= false;
89 $this->exists
= false;
91 if( $title instanceof Title
) {
92 $this->title
= File
::normalizeTitle( $title, 'exception' );
93 $this->name
= $title->getDBkey();
104 if ( !$id && !$key && !( $title instanceof Title
) ) {
105 throw new MWException( "No specifications provided to ArchivedFile constructor." );
110 * Loads a file object from the filearchive table
111 * @return bool|null True on success or null
113 public function load() {
114 if ( $this->dataLoaded
) {
119 if( $this->id
> 0 ) {
120 $conds['fa_id'] = $this->id
;
123 $conds['fa_storage_group'] = $this->group
;
124 $conds['fa_storage_key'] = $this->key
;
127 $conds['fa_name'] = $this->title
->getDBkey();
130 if( !count($conds)) {
131 throw new MWException( "No specific information for retrieving archived file" );
134 if( !$this->title ||
$this->title
->getNamespace() == NS_FILE
) {
135 $dbr = wfGetDB( DB_SLAVE
);
136 $res = $dbr->select( 'filearchive',
158 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
159 if ( $res == false ||
$dbr->numRows( $res ) == 0 ) {
160 // this revision does not exist?
163 $ret = $dbr->resultObject( $res );
164 $row = $ret->fetchObject();
166 // initialize fields for filestore image object
167 $this->id
= intval($row->fa_id
);
168 $this->name
= $row->fa_name
;
169 $this->archive_name
= $row->fa_archive_name
;
170 $this->group
= $row->fa_storage_group
;
171 $this->key
= $row->fa_storage_key
;
172 $this->size
= $row->fa_size
;
173 $this->bits
= $row->fa_bits
;
174 $this->width
= $row->fa_width
;
175 $this->height
= $row->fa_height
;
176 $this->metadata
= $row->fa_metadata
;
177 $this->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
178 $this->media_type
= $row->fa_media_type
;
179 $this->description
= $row->fa_description
;
180 $this->user
= $row->fa_user
;
181 $this->user_text
= $row->fa_user_text
;
182 $this->timestamp
= $row->fa_timestamp
;
183 $this->deleted
= $row->fa_deleted
;
185 throw new MWException( 'This title does not correspond to an image page.' );
187 $this->dataLoaded
= true;
188 $this->exists
= true;
194 * Loads a file object from the filearchive table
198 * @return ArchivedFile
200 public static function newFromRow( $row ) {
201 $file = new ArchivedFile( Title
::makeTitle( NS_FILE
, $row->fa_name
) );
203 $file->id
= intval($row->fa_id
);
204 $file->name
= $row->fa_name
;
205 $file->archive_name
= $row->fa_archive_name
;
206 $file->group
= $row->fa_storage_group
;
207 $file->key
= $row->fa_storage_key
;
208 $file->size
= $row->fa_size
;
209 $file->bits
= $row->fa_bits
;
210 $file->width
= $row->fa_width
;
211 $file->height
= $row->fa_height
;
212 $file->metadata
= $row->fa_metadata
;
213 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
214 $file->media_type
= $row->fa_media_type
;
215 $file->description
= $row->fa_description
;
216 $file->user
= $row->fa_user
;
217 $file->user_text
= $row->fa_user_text
;
218 $file->timestamp
= $row->fa_timestamp
;
219 $file->deleted
= $row->fa_deleted
;
225 * Return the associated title object
229 public function getTitle() {
234 * Return the file name
238 public function getName() {
245 public function getID() {
253 public function exists() {
255 return $this->exists
;
259 * Return the FileStore key
262 public function getKey() {
268 * Return the FileStore key (overriding base File class)
271 public function getStorageKey() {
272 return $this->getKey();
276 * Return the FileStore storage group
279 public function getGroup() {
284 * Return the width of the image
287 public function getWidth() {
293 * Return the height of the image
296 public function getHeight() {
298 return $this->height
;
302 * Get handler-specific metadata
305 public function getMetadata() {
307 return $this->metadata
;
311 * Return the size of the image file, in bytes
314 public function getSize() {
320 * Return the bits of the image file, in bytes
323 public function getBits() {
329 * Returns the mime type of the file.
332 public function getMimeType() {
338 * Get a MediaHandler instance for this file
339 * @return MediaHandler
341 function getHandler() {
342 if ( !isset( $this->handler
) ) {
343 $this->handler
= MediaHandler
::getHandler( $this->getMimeType() );
345 return $this->handler
;
349 * Returns the number of pages of a multipage document, or false for
350 * documents which aren't multipage documents
352 function pageCount() {
353 if ( !isset( $this->pageCount
) ) {
354 if ( $this->getHandler() && $this->handler
->isMultiPage( $this ) ) {
355 $this->pageCount
= $this->handler
->pageCount( $this );
357 $this->pageCount
= false;
360 return $this->pageCount
;
364 * Return the type of the media in the file.
365 * Use the value returned by this function with the MEDIATYPE_xxx constants.
368 public function getMediaType() {
370 return $this->media_type
;
374 * Return upload timestamp.
378 public function getTimestamp() {
380 return wfTimestamp( TS_MW
, $this->timestamp
);
384 * Return the user ID of the uploader.
388 public function getUser() {
390 if( $this->isDeleted( File
::DELETED_USER
) ) {
398 * Return the user name of the uploader.
402 public function getUserText() {
404 if( $this->isDeleted( File
::DELETED_USER
) ) {
407 return $this->user_text
;
412 * Return upload description.
416 public function getDescription() {
418 if( $this->isDeleted( File
::DELETED_COMMENT
) ) {
421 return $this->description
;
426 * Return the user ID of the uploader.
430 public function getRawUser() {
436 * Return the user name of the uploader.
440 public function getRawUserText() {
442 return $this->user_text
;
446 * Return upload description.
450 public function getRawDescription() {
452 return $this->description
;
456 * Returns the deletion bitfield
459 public function getVisibility() {
461 return $this->deleted
;
465 * for file or revision rows
467 * @param $field Integer: one of DELETED_* bitfield constants
470 public function isDeleted( $field ) {
472 return ($this->deleted
& $field) == $field;
476 * Determine if the current user is allowed to view a particular
477 * field of this FileStore image file, if it's marked as deleted.
478 * @param $field Integer
479 * @param $user User object to check, or null to use $wgUser
482 public function userCan( $field, User
$user = null ) {
484 return Revision
::userCanBitfield( $this->deleted
, $field, $user );