4 * A file object referring to either a standalone local file, or a file in a
5 * local repository with no database, for example an FSRepo repository.
9 * TODO: Currently it doesn't really work in the repository role, there are
10 * lots of functions missing. It is used by the WebStore extension in the
15 class UnregisteredLocalFile extends File {
16 var $title, $path, $mime, $handler, $dims;
18 static function newFromPath( $path, $mime ) {
19 return new UnregisteredLocalFile( false, false, $path, $mime );
22 static function newFromTitle( $title, $repo ) {
23 return new UnregisteredLocalFile( $title, $repo, false, false );
26 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
27 if ( !( $title && $repo ) && !$path ) {
28 throw new MWException( __METHOD__.': not enough parameters, must specify title and repo, or a full path' );
31 $this->title = $title;
32 $this->name = $repo->getNameFromTitle( $title );
34 $this->name = basename( $path );
35 $this->title = Title::makeTitleSafe( NS_FILE, $this->name );
41 $this->path = $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name ) . $this->name;
46 $this->dims = array();
49 function getPageDimensions( $page = 1 ) {
50 if ( !isset( $this->dims[$page] ) ) {
51 if ( !$this->getHandler() ) {
54 $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
56 return $this->dims[$page];
59 function getWidth( $page = 1 ) {
60 $dim = $this->getPageDimensions( $page );
64 function getHeight( $page = 1 ) {
65 $dim = $this->getPageDimensions( $page );
66 return $dim['height'];
69 function getMimeType() {
70 if ( !isset( $this->mime ) ) {
71 $magic = MimeMagic::singleton();
72 $this->mime = $magic->guessMimeType( $this->path );
77 function getImageSize( $filename ) {
78 if ( !$this->getHandler() ) {
81 return $this->handler->getImageSize( $this, $this->getPath() );
84 function getMetadata() {
85 if ( !isset( $this->metadata ) ) {
86 if ( !$this->getHandler() ) {
87 $this->metadata = false;
89 $this->metadata = $this->handler->getMetadata( $this, $this->getPath() );
92 return $this->metadata;
97 return $this->repo->getZoneUrl( 'public' ) . '/' . $this->repo->getHashPath( $this->name ) . urlencode( $this->name );
104 if ( file_exists( $this->path ) ) {
105 return filesize( $this->path );