MediaWiki  REL1_22
UnregisteredLocalFile.php
Go to the documentation of this file.
00001 <?php
00036 class UnregisteredLocalFile extends File {
00037     var $title, $path, $mime, $dims, $metadata;
00038 
00042     var $handler;
00043 
00049     static function newFromPath( $path, $mime ) {
00050         return new self( false, false, $path, $mime );
00051     }
00052 
00058     static function newFromTitle( $title, $repo ) {
00059         return new self( $title, $repo, false, false );
00060     }
00061 
00072     function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
00073         if ( !( $title && $repo ) && !$path ) {
00074             throw new MWException( __METHOD__ . ': not enough parameters, must specify title and repo, or a full path' );
00075         }
00076         if ( $title instanceof Title ) {
00077             $this->title = File::normalizeTitle( $title, 'exception' );
00078             $this->name = $repo->getNameFromTitle( $title );
00079         } else {
00080             $this->name = basename( $path );
00081             $this->title = File::normalizeTitle( $this->name, 'exception' );
00082         }
00083         $this->repo = $repo;
00084         if ( $path ) {
00085             $this->path = $path;
00086         } else {
00087             $this->assertRepoDefined();
00088             $this->path = $repo->getRootDirectory() . '/' .
00089                 $repo->getHashPath( $this->name ) . $this->name;
00090         }
00091         if ( $mime ) {
00092             $this->mime = $mime;
00093         }
00094         $this->dims = array();
00095     }
00096 
00101     private function cachePageDimensions( $page = 1 ) {
00102         if ( !isset( $this->dims[$page] ) ) {
00103             if ( !$this->getHandler() ) {
00104                 return false;
00105             }
00106             $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
00107         }
00108         return $this->dims[$page];
00109     }
00110 
00115     function getWidth( $page = 1 ) {
00116         $dim = $this->cachePageDimensions( $page );
00117         return $dim['width'];
00118     }
00119 
00124     function getHeight( $page = 1 ) {
00125         $dim = $this->cachePageDimensions( $page );
00126         return $dim['height'];
00127     }
00128 
00132     function getMimeType() {
00133         if ( !isset( $this->mime ) ) {
00134             $magic = MimeMagic::singleton();
00135             $this->mime = $magic->guessMimeType( $this->getLocalRefPath() );
00136         }
00137         return $this->mime;
00138     }
00139 
00144     function getImageSize( $filename ) {
00145         if ( !$this->getHandler() ) {
00146             return false;
00147         }
00148         return $this->handler->getImageSize( $this, $this->getLocalRefPath() );
00149     }
00150 
00154     function getMetadata() {
00155         if ( !isset( $this->metadata ) ) {
00156             if ( !$this->getHandler() ) {
00157                 $this->metadata = false;
00158             } else {
00159                 $this->metadata = $this->handler->getMetadata( $this, $this->getLocalRefPath() );
00160             }
00161         }
00162         return $this->metadata;
00163     }
00164 
00168     function getURL() {
00169         if ( $this->repo ) {
00170             return $this->repo->getZoneUrl( 'public' ) . '/' .
00171                 $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name );
00172         } else {
00173             return false;
00174         }
00175     }
00176 
00180     function getSize() {
00181         $this->assertRepoDefined();
00182         return $this->repo->getFileSize( $this->path );
00183     }
00184 
00193     public function setLocalReference( FSFile $fsFile ) {
00194         $this->fsFile = $fsFile;
00195     }
00196 }