MediaWiki
REL1_19
|
00001 <?php 00021 class UnregisteredLocalFile extends File { 00022 var $title, $path, $mime, $dims; 00023 00027 var $handler; 00028 00034 static function newFromPath( $path, $mime ) { 00035 return new self( false, false, $path, $mime ); 00036 } 00037 00043 static function newFromTitle( $title, $repo ) { 00044 return new self( $title, $repo, false, false ); 00045 } 00046 00057 function __construct( $title = false, $repo = false, $path = false, $mime = false ) { 00058 if ( !( $title && $repo ) && !$path ) { 00059 throw new MWException( __METHOD__.': not enough parameters, must specify title and repo, or a full path' ); 00060 } 00061 if ( $title instanceof Title ) { 00062 $this->title = File::normalizeTitle( $title, 'exception' ); 00063 $this->name = $repo->getNameFromTitle( $title ); 00064 } else { 00065 $this->name = basename( $path ); 00066 $this->title = File::normalizeTitle( $this->name, 'exception' ); 00067 } 00068 $this->repo = $repo; 00069 if ( $path ) { 00070 $this->path = $path; 00071 } else { 00072 $this->assertRepoDefined(); 00073 $this->path = $repo->getRootDirectory() . '/' . 00074 $repo->getHashPath( $this->name ) . $this->name; 00075 } 00076 if ( $mime ) { 00077 $this->mime = $mime; 00078 } 00079 $this->dims = array(); 00080 } 00081 00082 private function cachePageDimensions( $page = 1 ) { 00083 if ( !isset( $this->dims[$page] ) ) { 00084 if ( !$this->getHandler() ) { 00085 return false; 00086 } 00087 $this->dims[$page] = $this->handler->getPageDimensions( $this, $page ); 00088 } 00089 return $this->dims[$page]; 00090 } 00091 00092 function getWidth( $page = 1 ) { 00093 $dim = $this->cachePageDimensions( $page ); 00094 return $dim['width']; 00095 } 00096 00097 function getHeight( $page = 1 ) { 00098 $dim = $this->cachePageDimensions( $page ); 00099 return $dim['height']; 00100 } 00101 00102 function getMimeType() { 00103 if ( !isset( $this->mime ) ) { 00104 $magic = MimeMagic::singleton(); 00105 $this->mime = $magic->guessMimeType( $this->getLocalRefPath() ); 00106 } 00107 return $this->mime; 00108 } 00109 00110 function getImageSize( $filename ) { 00111 if ( !$this->getHandler() ) { 00112 return false; 00113 } 00114 return $this->handler->getImageSize( $this, $this->getLocalRefPath() ); 00115 } 00116 00117 function getMetadata() { 00118 if ( !isset( $this->metadata ) ) { 00119 if ( !$this->getHandler() ) { 00120 $this->metadata = false; 00121 } else { 00122 $this->metadata = $this->handler->getMetadata( $this, $this->getLocalRefPath() ); 00123 } 00124 } 00125 return $this->metadata; 00126 } 00127 00128 function getURL() { 00129 if ( $this->repo ) { 00130 return $this->repo->getZoneUrl( 'public' ) . '/' . 00131 $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name ); 00132 } else { 00133 return false; 00134 } 00135 } 00136 00137 function getSize() { 00138 $this->assertRepoDefined(); 00139 $props = $this->repo->getFileProps( $this->path ); 00140 if ( isset( $props['size'] ) ) { 00141 return $props['size']; 00142 } 00143 return false; // doesn't exist 00144 } 00145 }