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
13 class UnregisteredLocalFile
extends File
{
14 var $title, $path, $mime, $handler, $dims;
16 static function newFromPath( $path, $mime ) {
17 return new UnregisteredLocalFile( false, false, $path, $mime );
20 static function newFromTitle( $title, $repo ) {
21 return new UnregisteredLocalFile( $title, $repo, false, false );
24 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
25 if ( !( $title && $repo ) && !$path ) {
26 throw new MWException( __METHOD__
.': not enough parameters, must specify title and repo, or a full path' );
29 $this->title
= $title;
30 $this->name
= $repo->getNameFromTitle( $title );
32 $this->name
= basename( $path );
33 $this->title
= Title
::makeTitleSafe( NS_IMAGE
, $this->name
);
39 $this->path
= $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name
) . $this->name
;
44 $this->dims
= array();
47 function getPageDimensions( $page = 1 ) {
48 if ( !isset( $this->dims
[$page] ) ) {
49 if ( !$this->getHandler() ) {
52 $this->dims
[$page] = $this->handler
->getPageDimensions( $this, $page );
54 return $this->dims
[$page];
57 function getWidth( $page = 1 ) {
58 $dim = $this->getPageDimensions( $page );
62 function getHeight( $page = 1 ) {
63 $dim = $this->getPageDimensions( $page );
64 return $dim['height'];
67 function getMimeType() {
68 if ( !isset( $this->mime
) ) {
69 $magic = MimeMagic
::singleton();
70 $this->mime
= $magic->guessMimeType( $this->path
);
75 function getImageSize( $filename ) {
76 if ( !$this->getHandler() ) {
79 return $this->handler
->getImageSize( $this, $this->getPath() );
82 function getMetadata() {
83 if ( !isset( $this->metadata
) ) {
84 if ( !$this->getHandler() ) {
85 $this->metadata
= false;
87 $this->metadata
= $this->handler
->getMetadata( $this, $this->getPath() );
90 return $this->metadata
;
95 return $this->repo
->getZoneUrl( 'public' ) . '/' . $this->repo
->getHashPath( $this->name
) . urlencode( $this->name
);
102 if ( file_exists( $this->path
) ) {
103 return filesize( $this->path
);