MediaWiki
REL1_24
|
00001 <?php 00036 class UnregisteredLocalFile extends File { 00038 protected $title; 00039 00041 protected $path; 00042 00044 protected $mime; 00045 00047 protected $dims; 00048 00050 protected $metadata; 00051 00053 public $handler; 00054 00060 static function newFromPath( $path, $mime ) { 00061 return new self( false, false, $path, $mime ); 00062 } 00063 00069 static function newFromTitle( $title, $repo ) { 00070 return new self( $title, $repo, false, false ); 00071 } 00072 00083 function __construct( $title = false, $repo = false, $path = false, $mime = false ) { 00084 if ( !( $title && $repo ) && !$path ) { 00085 throw new MWException( __METHOD__ . 00086 ': not enough parameters, must specify title and repo, or a full path' ); 00087 } 00088 if ( $title instanceof Title ) { 00089 $this->title = File::normalizeTitle( $title, 'exception' ); 00090 $this->name = $repo->getNameFromTitle( $title ); 00091 } else { 00092 $this->name = basename( $path ); 00093 $this->title = File::normalizeTitle( $this->name, 'exception' ); 00094 } 00095 $this->repo = $repo; 00096 if ( $path ) { 00097 $this->path = $path; 00098 } else { 00099 $this->assertRepoDefined(); 00100 $this->path = $repo->getRootDirectory() . '/' . 00101 $repo->getHashPath( $this->name ) . $this->name; 00102 } 00103 if ( $mime ) { 00104 $this->mime = $mime; 00105 } 00106 $this->dims = array(); 00107 } 00108 00113 private function cachePageDimensions( $page = 1 ) { 00114 if ( !isset( $this->dims[$page] ) ) { 00115 if ( !$this->getHandler() ) { 00116 return false; 00117 } 00118 $this->dims[$page] = $this->handler->getPageDimensions( $this, $page ); 00119 } 00120 00121 return $this->dims[$page]; 00122 } 00123 00128 function getWidth( $page = 1 ) { 00129 $dim = $this->cachePageDimensions( $page ); 00130 00131 return $dim['width']; 00132 } 00133 00138 function getHeight( $page = 1 ) { 00139 $dim = $this->cachePageDimensions( $page ); 00140 00141 return $dim['height']; 00142 } 00143 00147 function getMimeType() { 00148 if ( !isset( $this->mime ) ) { 00149 $magic = MimeMagic::singleton(); 00150 $this->mime = $magic->guessMimeType( $this->getLocalRefPath() ); 00151 } 00152 00153 return $this->mime; 00154 } 00155 00160 function getImageSize( $filename ) { 00161 if ( !$this->getHandler() ) { 00162 return false; 00163 } 00164 00165 return $this->handler->getImageSize( $this, $this->getLocalRefPath() ); 00166 } 00167 00171 function getMetadata() { 00172 if ( !isset( $this->metadata ) ) { 00173 if ( !$this->getHandler() ) { 00174 $this->metadata = false; 00175 } else { 00176 $this->metadata = $this->handler->getMetadata( $this, $this->getLocalRefPath() ); 00177 } 00178 } 00179 00180 return $this->metadata; 00181 } 00182 00186 function getURL() { 00187 if ( $this->repo ) { 00188 return $this->repo->getZoneUrl( 'public' ) . '/' . 00189 $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name ); 00190 } else { 00191 return false; 00192 } 00193 } 00194 00198 function getSize() { 00199 $this->assertRepoDefined(); 00200 00201 return $this->repo->getFileSize( $this->path ); 00202 } 00203 00212 public function setLocalReference( FSFile $fsFile ) { 00213 $this->fsFile = $fsFile; 00214 } 00215 }