00001 <?php
00002
00006 class ArchivedFile
00007 {
00011 var $id, # filearchive row ID
00012 $title, # image title
00013 $name, # image name
00014 $group, # FileStore storage group
00015 $key, # FileStore sha1 key
00016 $size, # file dimensions
00017 $bits, # size in bytes
00018 $width, # width
00019 $height, # height
00020 $metadata, # metadata string
00021 $mime, # mime type
00022 $media_type, # media type
00023 $description, # upload description
00024 $user, # user ID of uploader
00025 $user_text, # user name of uploader
00026 $timestamp, # time of upload
00027 $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
00028 $deleted; # Bitfield akin to rev_deleted
00029
00032 function ArchivedFile( $title, $id=0, $key='' ) {
00033 $this->id = -1;
00034 $this->title = false;
00035 $this->name = false;
00036 $this->group = 'deleted';
00037 $this->key = '';
00038 $this->size = 0;
00039 $this->bits = 0;
00040 $this->width = 0;
00041 $this->height = 0;
00042 $this->metadata = '';
00043 $this->mime = "unknown/unknown";
00044 $this->media_type = '';
00045 $this->description = '';
00046 $this->user = 0;
00047 $this->user_text = '';
00048 $this->timestamp = null;
00049 $this->deleted = 0;
00050 $this->dataLoaded = false;
00051 $this->exists = false;
00052
00053 if( is_object($title) ) {
00054 $this->title = $title;
00055 $this->name = $title->getDBkey();
00056 }
00057
00058 if ($id)
00059 $this->id = $id;
00060
00061 if ($key)
00062 $this->key = $key;
00063
00064 if (!$id && !$key && !is_object($title))
00065 throw new MWException( "No specifications provided to ArchivedFile constructor." );
00066 }
00067
00072 public function load() {
00073 if ( $this->dataLoaded ) {
00074 return true;
00075 }
00076 $conds = array();
00077
00078 if( $this->id > 0 )
00079 $conds['fa_id'] = $this->id;
00080 if( $this->key ) {
00081 $conds['fa_storage_group'] = $this->group;
00082 $conds['fa_storage_key'] = $this->key;
00083 }
00084 if( $this->title )
00085 $conds['fa_name'] = $this->title->getDBkey();
00086
00087 if( !count($conds))
00088 throw new MWException( "No specific information for retrieving archived file" );
00089
00090 if( !$this->title || $this->title->getNamespace() == NS_FILE ) {
00091 $dbr = wfGetDB( DB_SLAVE );
00092 $res = $dbr->select( 'filearchive',
00093 array(
00094 'fa_id',
00095 'fa_name',
00096 'fa_archive_name',
00097 'fa_storage_key',
00098 'fa_storage_group',
00099 'fa_size',
00100 'fa_bits',
00101 'fa_width',
00102 'fa_height',
00103 'fa_metadata',
00104 'fa_media_type',
00105 'fa_major_mime',
00106 'fa_minor_mime',
00107 'fa_description',
00108 'fa_user',
00109 'fa_user_text',
00110 'fa_timestamp',
00111 'fa_deleted' ),
00112 $conds,
00113 __METHOD__,
00114 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
00115
00116 if ( $dbr->numRows( $res ) == 0 ) {
00117
00118 return;
00119 }
00120 $ret = $dbr->resultObject( $res );
00121 $row = $ret->fetchObject();
00122
00123
00124 $this->id = intval($row->fa_id);
00125 $this->name = $row->fa_name;
00126 $this->archive_name = $row->fa_archive_name;
00127 $this->group = $row->fa_storage_group;
00128 $this->key = $row->fa_storage_key;
00129 $this->size = $row->fa_size;
00130 $this->bits = $row->fa_bits;
00131 $this->width = $row->fa_width;
00132 $this->height = $row->fa_height;
00133 $this->metadata = $row->fa_metadata;
00134 $this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
00135 $this->media_type = $row->fa_media_type;
00136 $this->description = $row->fa_description;
00137 $this->user = $row->fa_user;
00138 $this->user_text = $row->fa_user_text;
00139 $this->timestamp = $row->fa_timestamp;
00140 $this->deleted = $row->fa_deleted;
00141 } else {
00142 throw new MWException( 'This title does not correspond to an image page.' );
00143 return;
00144 }
00145 $this->dataLoaded = true;
00146 $this->exists = true;
00147
00148 return true;
00149 }
00150
00155 public static function newFromRow( $row ) {
00156 $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
00157
00158 $file->id = intval($row->fa_id);
00159 $file->name = $row->fa_name;
00160 $file->archive_name = $row->fa_archive_name;
00161 $file->group = $row->fa_storage_group;
00162 $file->key = $row->fa_storage_key;
00163 $file->size = $row->fa_size;
00164 $file->bits = $row->fa_bits;
00165 $file->width = $row->fa_width;
00166 $file->height = $row->fa_height;
00167 $file->metadata = $row->fa_metadata;
00168 $file->mime = "$row->fa_major_mime/$row->fa_minor_mime";
00169 $file->media_type = $row->fa_media_type;
00170 $file->description = $row->fa_description;
00171 $file->user = $row->fa_user;
00172 $file->user_text = $row->fa_user_text;
00173 $file->timestamp = $row->fa_timestamp;
00174 $file->deleted = $row->fa_deleted;
00175
00176 return $file;
00177 }
00178
00182 public function getTitle() {
00183 return $this->title;
00184 }
00185
00189 public function getName() {
00190 return $this->name;
00191 }
00192
00193 public function getID() {
00194 $this->load();
00195 return $this->id;
00196 }
00197
00198 public function exists() {
00199 $this->load();
00200 return $this->exists;
00201 }
00202
00206 public function getKey() {
00207 $this->load();
00208 return $this->key;
00209 }
00210
00214 public function getStorageKey() {
00215 return $this->getKey();
00216 }
00217
00221 public function getGroup() {
00222 return $file->group;
00223 }
00224
00228 public function getWidth() {
00229 $this->load();
00230 return $this->width;
00231 }
00232
00236 public function getHeight() {
00237 $this->load();
00238 return $this->height;
00239 }
00240
00244 public function getMetadata() {
00245 $this->load();
00246 return $this->metadata;
00247 }
00248
00252 public function getSize() {
00253 $this->load();
00254 return $this->size;
00255 }
00256
00260 public function getBits() {
00261 $this->load();
00262 return $this->bits;
00263 }
00264
00268 public function getMimeType() {
00269 $this->load();
00270 return $this->mime;
00271 }
00272
00277 public function getMediaType() {
00278 $this->load();
00279 return $this->media_type;
00280 }
00281
00285 public function getTimestamp() {
00286 $this->load();
00287 return wfTimestamp( TS_MW, $this->timestamp );
00288 }
00289
00293 public function getUser() {
00294 $this->load();
00295 if( $this->isDeleted( File::DELETED_USER ) ) {
00296 return 0;
00297 } else {
00298 return $this->user;
00299 }
00300 }
00301
00305 public function getUserText() {
00306 $this->load();
00307 if( $this->isDeleted( File::DELETED_USER ) ) {
00308 return 0;
00309 } else {
00310 return $this->user_text;
00311 }
00312 }
00313
00317 public function getDescription() {
00318 $this->load();
00319 if( $this->isDeleted( File::DELETED_COMMENT ) ) {
00320 return 0;
00321 } else {
00322 return $this->description;
00323 }
00324 }
00325
00329 public function getRawUser() {
00330 $this->load();
00331 return $this->user;
00332 }
00333
00337 public function getRawUserText() {
00338 $this->load();
00339 return $this->user_text;
00340 }
00341
00345 public function getRawDescription() {
00346 $this->load();
00347 return $this->description;
00348 }
00349
00354 public function getVisibility() {
00355 $this->load();
00356 return $this->deleted;
00357 }
00358
00365 public function isDeleted( $field ) {
00366 $this->load();
00367 return ($this->deleted & $field) == $field;
00368 }
00369
00376 public function userCan( $field ) {
00377 $this->load();
00378 return Revision::userCanBitfield( $this->deleted, $field );
00379 }
00380 }