00001 <?php
00002
00015 class UnregisteredLocalFile extends File {
00016 var $title, $path, $mime, $handler, $dims;
00017
00018 static function newFromPath( $path, $mime ) {
00019 return new UnregisteredLocalFile( false, false, $path, $mime );
00020 }
00021
00022 static function newFromTitle( $title, $repo ) {
00023 return new UnregisteredLocalFile( $title, $repo, false, false );
00024 }
00025
00026 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
00027 if ( !( $title && $repo ) && !$path ) {
00028 throw new MWException( __METHOD__.': not enough parameters, must specify title and repo, or a full path' );
00029 }
00030 if ( $title ) {
00031 $this->title = $title;
00032 $this->name = $repo->getNameFromTitle( $title );
00033 } else {
00034 $this->name = basename( $path );
00035 $this->title = Title::makeTitleSafe( NS_FILE, $this->name );
00036 }
00037 $this->repo = $repo;
00038 if ( $path ) {
00039 $this->path = $path;
00040 } else {
00041 $this->path = $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name ) . $this->name;
00042 }
00043 if ( $mime ) {
00044 $this->mime = $mime;
00045 }
00046 $this->dims = array();
00047 }
00048
00049 function getPageDimensions( $page = 1 ) {
00050 if ( !isset( $this->dims[$page] ) ) {
00051 if ( !$this->getHandler() ) {
00052 return false;
00053 }
00054 $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
00055 }
00056 return $this->dims[$page];
00057 }
00058
00059 function getWidth( $page = 1 ) {
00060 $dim = $this->getPageDimensions( $page );
00061 return $dim['width'];
00062 }
00063
00064 function getHeight( $page = 1 ) {
00065 $dim = $this->getPageDimensions( $page );
00066 return $dim['height'];
00067 }
00068
00069 function getMimeType() {
00070 if ( !isset( $this->mime ) ) {
00071 $magic = MimeMagic::singleton();
00072 $this->mime = $magic->guessMimeType( $this->path );
00073 }
00074 return $this->mime;
00075 }
00076
00077 function getImageSize( $filename ) {
00078 if ( !$this->getHandler() ) {
00079 return false;
00080 }
00081 return $this->handler->getImageSize( $this, $this->getPath() );
00082 }
00083
00084 function getMetadata() {
00085 if ( !isset( $this->metadata ) ) {
00086 if ( !$this->getHandler() ) {
00087 $this->metadata = false;
00088 } else {
00089 $this->metadata = $this->handler->getMetadata( $this, $this->getPath() );
00090 }
00091 }
00092 return $this->metadata;
00093 }
00094
00095 function getURL() {
00096 if ( $this->repo ) {
00097 return $this->repo->getZoneUrl( 'public' ) . '/' . $this->repo->getHashPath( $this->name ) . urlencode( $this->name );
00098 } else {
00099 return false;
00100 }
00101 }
00102
00103 function getSize() {
00104 if ( file_exists( $this->path ) ) {
00105 return filesize( $this->path );
00106 } else {
00107 return false;
00108 }
00109 }
00110 }