MediaWiki
REL1_20
|
00001 <?php 00029 class ArchivedFile { 00033 var $id, # filearchive row ID 00034 $name, # image name 00035 $group, # FileStore storage group 00036 $key, # FileStore sha1 key 00037 $size, # file dimensions 00038 $bits, # size in bytes 00039 $width, # width 00040 $height, # height 00041 $metadata, # metadata string 00042 $mime, # mime type 00043 $media_type, # media type 00044 $description, # upload description 00045 $user, # user ID of uploader 00046 $user_text, # user name of uploader 00047 $timestamp, # time of upload 00048 $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx) 00049 $deleted, # Bitfield akin to rev_deleted 00050 $pageCount, 00051 $archive_name; 00052 00056 var $handler; 00060 var $title; # image title 00061 00070 function __construct( $title, $id=0, $key='' ) { 00071 $this->id = -1; 00072 $this->title = false; 00073 $this->name = false; 00074 $this->group = 'deleted'; // needed for direct use of constructor 00075 $this->key = ''; 00076 $this->size = 0; 00077 $this->bits = 0; 00078 $this->width = 0; 00079 $this->height = 0; 00080 $this->metadata = ''; 00081 $this->mime = "unknown/unknown"; 00082 $this->media_type = ''; 00083 $this->description = ''; 00084 $this->user = 0; 00085 $this->user_text = ''; 00086 $this->timestamp = null; 00087 $this->deleted = 0; 00088 $this->dataLoaded = false; 00089 $this->exists = false; 00090 00091 if( $title instanceof Title ) { 00092 $this->title = File::normalizeTitle( $title, 'exception' ); 00093 $this->name = $title->getDBkey(); 00094 } 00095 00096 if ($id) { 00097 $this->id = $id; 00098 } 00099 00100 if ($key) { 00101 $this->key = $key; 00102 } 00103 00104 if ( !$id && !$key && !( $title instanceof Title ) ) { 00105 throw new MWException( "No specifications provided to ArchivedFile constructor." ); 00106 } 00107 } 00108 00113 public function load() { 00114 if ( $this->dataLoaded ) { 00115 return true; 00116 } 00117 $conds = array(); 00118 00119 if( $this->id > 0 ) { 00120 $conds['fa_id'] = $this->id; 00121 } 00122 if( $this->key ) { 00123 $conds['fa_storage_group'] = $this->group; 00124 $conds['fa_storage_key'] = $this->key; 00125 } 00126 if( $this->title ) { 00127 $conds['fa_name'] = $this->title->getDBkey(); 00128 } 00129 00130 if( !count($conds)) { 00131 throw new MWException( "No specific information for retrieving archived file" ); 00132 } 00133 00134 if( !$this->title || $this->title->getNamespace() == NS_FILE ) { 00135 $dbr = wfGetDB( DB_SLAVE ); 00136 $res = $dbr->select( 'filearchive', 00137 array( 00138 'fa_id', 00139 'fa_name', 00140 'fa_archive_name', 00141 'fa_storage_key', 00142 'fa_storage_group', 00143 'fa_size', 00144 'fa_bits', 00145 'fa_width', 00146 'fa_height', 00147 'fa_metadata', 00148 'fa_media_type', 00149 'fa_major_mime', 00150 'fa_minor_mime', 00151 'fa_description', 00152 'fa_user', 00153 'fa_user_text', 00154 'fa_timestamp', 00155 'fa_deleted' ), 00156 $conds, 00157 __METHOD__, 00158 array( 'ORDER BY' => 'fa_timestamp DESC' ) ); 00159 if ( $res == false || $dbr->numRows( $res ) == 0 ) { 00160 // this revision does not exist? 00161 return null; 00162 } 00163 $ret = $dbr->resultObject( $res ); 00164 $row = $ret->fetchObject(); 00165 00166 // initialize fields for filestore image object 00167 $this->id = intval($row->fa_id); 00168 $this->name = $row->fa_name; 00169 $this->archive_name = $row->fa_archive_name; 00170 $this->group = $row->fa_storage_group; 00171 $this->key = $row->fa_storage_key; 00172 $this->size = $row->fa_size; 00173 $this->bits = $row->fa_bits; 00174 $this->width = $row->fa_width; 00175 $this->height = $row->fa_height; 00176 $this->metadata = $row->fa_metadata; 00177 $this->mime = "$row->fa_major_mime/$row->fa_minor_mime"; 00178 $this->media_type = $row->fa_media_type; 00179 $this->description = $row->fa_description; 00180 $this->user = $row->fa_user; 00181 $this->user_text = $row->fa_user_text; 00182 $this->timestamp = $row->fa_timestamp; 00183 $this->deleted = $row->fa_deleted; 00184 } else { 00185 throw new MWException( 'This title does not correspond to an image page.' ); 00186 } 00187 $this->dataLoaded = true; 00188 $this->exists = true; 00189 00190 return true; 00191 } 00192 00200 public static function newFromRow( $row ) { 00201 $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) ); 00202 00203 $file->id = intval($row->fa_id); 00204 $file->name = $row->fa_name; 00205 $file->archive_name = $row->fa_archive_name; 00206 $file->group = $row->fa_storage_group; 00207 $file->key = $row->fa_storage_key; 00208 $file->size = $row->fa_size; 00209 $file->bits = $row->fa_bits; 00210 $file->width = $row->fa_width; 00211 $file->height = $row->fa_height; 00212 $file->metadata = $row->fa_metadata; 00213 $file->mime = "$row->fa_major_mime/$row->fa_minor_mime"; 00214 $file->media_type = $row->fa_media_type; 00215 $file->description = $row->fa_description; 00216 $file->user = $row->fa_user; 00217 $file->user_text = $row->fa_user_text; 00218 $file->timestamp = $row->fa_timestamp; 00219 $file->deleted = $row->fa_deleted; 00220 00221 return $file; 00222 } 00223 00229 public function getTitle() { 00230 return $this->title; 00231 } 00232 00238 public function getName() { 00239 return $this->name; 00240 } 00241 00245 public function getID() { 00246 $this->load(); 00247 return $this->id; 00248 } 00249 00253 public function exists() { 00254 $this->load(); 00255 return $this->exists; 00256 } 00257 00262 public function getKey() { 00263 $this->load(); 00264 return $this->key; 00265 } 00266 00271 public function getStorageKey() { 00272 return $this->getKey(); 00273 } 00274 00279 public function getGroup() { 00280 return $this->group; 00281 } 00282 00287 public function getWidth() { 00288 $this->load(); 00289 return $this->width; 00290 } 00291 00296 public function getHeight() { 00297 $this->load(); 00298 return $this->height; 00299 } 00300 00305 public function getMetadata() { 00306 $this->load(); 00307 return $this->metadata; 00308 } 00309 00314 public function getSize() { 00315 $this->load(); 00316 return $this->size; 00317 } 00318 00323 public function getBits() { 00324 $this->load(); 00325 return $this->bits; 00326 } 00327 00332 public function getMimeType() { 00333 $this->load(); 00334 return $this->mime; 00335 } 00336 00341 function getHandler() { 00342 if ( !isset( $this->handler ) ) { 00343 $this->handler = MediaHandler::getHandler( $this->getMimeType() ); 00344 } 00345 return $this->handler; 00346 } 00347 00352 function pageCount() { 00353 if ( !isset( $this->pageCount ) ) { 00354 if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) { 00355 $this->pageCount = $this->handler->pageCount( $this ); 00356 } else { 00357 $this->pageCount = false; 00358 } 00359 } 00360 return $this->pageCount; 00361 } 00362 00368 public function getMediaType() { 00369 $this->load(); 00370 return $this->media_type; 00371 } 00372 00378 public function getTimestamp() { 00379 $this->load(); 00380 return wfTimestamp( TS_MW, $this->timestamp ); 00381 } 00382 00388 public function getUser() { 00389 $this->load(); 00390 if( $this->isDeleted( File::DELETED_USER ) ) { 00391 return 0; 00392 } else { 00393 return $this->user; 00394 } 00395 } 00396 00402 public function getUserText() { 00403 $this->load(); 00404 if( $this->isDeleted( File::DELETED_USER ) ) { 00405 return 0; 00406 } else { 00407 return $this->user_text; 00408 } 00409 } 00410 00416 public function getDescription() { 00417 $this->load(); 00418 if( $this->isDeleted( File::DELETED_COMMENT ) ) { 00419 return 0; 00420 } else { 00421 return $this->description; 00422 } 00423 } 00424 00430 public function getRawUser() { 00431 $this->load(); 00432 return $this->user; 00433 } 00434 00440 public function getRawUserText() { 00441 $this->load(); 00442 return $this->user_text; 00443 } 00444 00450 public function getRawDescription() { 00451 $this->load(); 00452 return $this->description; 00453 } 00454 00459 public function getVisibility() { 00460 $this->load(); 00461 return $this->deleted; 00462 } 00463 00470 public function isDeleted( $field ) { 00471 $this->load(); 00472 return ($this->deleted & $field) == $field; 00473 } 00474 00482 public function userCan( $field, User $user = null ) { 00483 $this->load(); 00484 return Revision::userCanBitfield( $this->deleted, $field, $user ); 00485 } 00486 }