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 = '';
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
00052 if( is_object($title) ) {
00053 $this->title = $title;
00054 $this->name = $title->getDBkey();
00055 }
00056
00057 if ($id)
00058 $this->id = $id;
00059
00060 if ($key)
00061 $this->key = $key;
00062
00063 if (!$id && !$key && !is_object($title))
00064 throw new MWException( "No specifications provided to ArchivedFile constructor." );
00065 }
00066
00071 public function load() {
00072 if ( $this->dataLoaded ) {
00073 return true;
00074 }
00075 $conds = array();
00076
00077 if( $this->id > 0 )
00078 $conds['fa_id'] = $this->id;
00079 if( $this->key ) {
00080 $conds['fa_storage_group'] = $this->group;
00081 $conds['fa_storage_key'] = $this->key;
00082 }
00083 if( $this->title )
00084 $conds['fa_name'] = $this->title->getDBkey();
00085
00086 if( !count($conds))
00087 throw new MWException( "No specific information for retrieving archived file" );
00088
00089 if( !$this->title || $this->title->getNamespace() == NS_FILE ) {
00090 $dbr = wfGetDB( DB_SLAVE );
00091 $res = $dbr->select( 'filearchive',
00092 array(
00093 'fa_id',
00094 'fa_name',
00095 'fa_archive_name',
00096 'fa_storage_key',
00097 'fa_storage_group',
00098 'fa_size',
00099 'fa_bits',
00100 'fa_width',
00101 'fa_height',
00102 'fa_metadata',
00103 'fa_media_type',
00104 'fa_major_mime',
00105 'fa_minor_mime',
00106 'fa_description',
00107 'fa_user',
00108 'fa_user_text',
00109 'fa_timestamp',
00110 'fa_deleted' ),
00111 $conds,
00112 __METHOD__,
00113 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
00114
00115 if ( $dbr->numRows( $res ) == 0 ) {
00116
00117 return;
00118 }
00119 $ret = $dbr->resultObject( $res );
00120 $row = $ret->fetchObject();
00121
00122
00123 $this->id = intval($row->fa_id);
00124 $this->name = $row->fa_name;
00125 $this->archive_name = $row->fa_archive_name;
00126 $this->group = $row->fa_storage_group;
00127 $this->key = $row->fa_storage_key;
00128 $this->size = $row->fa_size;
00129 $this->bits = $row->fa_bits;
00130 $this->width = $row->fa_width;
00131 $this->height = $row->fa_height;
00132 $this->metadata = $row->fa_metadata;
00133 $this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
00134 $this->media_type = $row->fa_media_type;
00135 $this->description = $row->fa_description;
00136 $this->user = $row->fa_user;
00137 $this->user_text = $row->fa_user_text;
00138 $this->timestamp = $row->fa_timestamp;
00139 $this->deleted = $row->fa_deleted;
00140 } else {
00141 throw new MWException( 'This title does not correspond to an image page.' );
00142 return;
00143 }
00144 $this->dataLoaded = true;
00145
00146 return true;
00147 }
00148
00153 public static function newFromRow( $row ) {
00154 $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
00155
00156 $file->id = intval($row->fa_id);
00157 $file->name = $row->fa_name;
00158 $file->archive_name = $row->fa_archive_name;
00159 $file->group = $row->fa_storage_group;
00160 $file->key = $row->fa_storage_key;
00161 $file->size = $row->fa_size;
00162 $file->bits = $row->fa_bits;
00163 $file->width = $row->fa_width;
00164 $file->height = $row->fa_height;
00165 $file->metadata = $row->fa_metadata;
00166 $file->mime = "$row->fa_major_mime/$row->fa_minor_mime";
00167 $file->media_type = $row->fa_media_type;
00168 $file->description = $row->fa_description;
00169 $file->user = $row->fa_user;
00170 $file->user_text = $row->fa_user_text;
00171 $file->timestamp = $row->fa_timestamp;
00172 $file->deleted = $row->fa_deleted;
00173
00174 return $file;
00175 }
00176
00181 public function getTitle() {
00182 return $this->title;
00183 }
00184
00188 public function getName() {
00189 return $this->name;
00190 }
00191
00192 public function getID() {
00193 $this->load();
00194 return $this->id;
00195 }
00196
00200 public function getKey() {
00201 $this->load();
00202 return $this->key;
00203 }
00204
00208 public function getGroup() {
00209 return $file->group;
00210 }
00211
00215 public function getWidth() {
00216 $this->load();
00217 return $this->width;
00218 }
00219
00223 public function getHeight() {
00224 $this->load();
00225 return $this->height;
00226 }
00227
00231 public function getMetadata() {
00232 $this->load();
00233 return $this->metadata;
00234 }
00235
00240 public function getSize() {
00241 $this->load();
00242 return $this->size;
00243 }
00244
00249 public function getBits() {
00250 $this->load();
00251 return $this->bits;
00252 }
00253
00257 public function getMimeType() {
00258 $this->load();
00259 return $this->mime;
00260 }
00261
00266 public function getMediaType() {
00267 $this->load();
00268 return $this->media_type;
00269 }
00270
00274 public function getTimestamp() {
00275 $this->load();
00276 return wfTimestamp( TS_MW, $this->timestamp );
00277 }
00278
00282 public function getUser() {
00283 $this->load();
00284 if( $this->isDeleted( File::DELETED_USER ) ) {
00285 return 0;
00286 } else {
00287 return $this->user;
00288 }
00289 }
00290
00294 public function getUserText() {
00295 $this->load();
00296 if( $this->isDeleted( File::DELETED_USER ) ) {
00297 return 0;
00298 } else {
00299 return $this->user_text;
00300 }
00301 }
00302
00306 public function getDescription() {
00307 $this->load();
00308 if( $this->isDeleted( File::DELETED_COMMENT ) ) {
00309 return 0;
00310 } else {
00311 return $this->description;
00312 }
00313 }
00314
00318 public function getRawUser() {
00319 $this->load();
00320 return $this->user;
00321 }
00322
00326 public function getRawUserText() {
00327 $this->load();
00328 return $this->user_text;
00329 }
00330
00334 public function getRawDescription() {
00335 $this->load();
00336 return $this->description;
00337 }
00338
00344 public function isDeleted( $field ) {
00345 return ($this->deleted & $field) == $field;
00346 }
00347
00354 public function userCan( $field ) {
00355 if( ($this->deleted & $field) == $field ) {
00356 global $wgUser;
00357 $permission = ( $this->deleted & File::DELETED_RESTRICTED ) == File::DELETED_RESTRICTED
00358 ? 'suppressrevision'
00359 : 'deleterevision';
00360 wfDebug( "Checking for $permission due to $field match on $this->deleted\n" );
00361 return $wgUser->isAllowed( $permission );
00362 } else {
00363 return true;
00364 }
00365 }
00366 }