3 * File without associated database record
10 * A file object referring to either a standalone local file, or a file in a
11 * local repository with no database, for example an FSRepo repository.
15 * TODO: Currently it doesn't really work in the repository role, there are
16 * lots of functions missing. It is used by the WebStore extension in the
21 class UnregisteredLocalFile
extends File
{
22 var $title, $path, $mime, $dims;
29 static function newFromPath( $path, $mime ) {
30 return new UnregisteredLocalFile( false, false, $path, $mime );
33 static function newFromTitle( $title, $repo ) {
34 return new UnregisteredLocalFile( $title, $repo, false, false );
44 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
45 if ( !( $title && $repo ) && !$path ) {
46 throw new MWException( __METHOD__
.': not enough parameters, must specify title and repo, or a full path' );
49 $this->title
= $title;
50 $this->name
= $repo->getNameFromTitle( $title );
52 $this->name
= basename( $path );
53 $this->title
= Title
::makeTitleSafe( NS_FILE
, $this->name
);
59 $this->path
= $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name
) . $this->name
;
64 $this->dims
= array();
67 function getPageDimensions( $page = 1 ) {
68 if ( !isset( $this->dims
[$page] ) ) {
69 if ( !$this->getHandler() ) {
72 $this->dims
[$page] = $this->handler
->getPageDimensions( $this, $page );
74 return $this->dims
[$page];
77 function getWidth( $page = 1 ) {
78 $dim = $this->getPageDimensions( $page );
82 function getHeight( $page = 1 ) {
83 $dim = $this->getPageDimensions( $page );
84 return $dim['height'];
87 function getMimeType() {
88 if ( !isset( $this->mime
) ) {
89 $magic = MimeMagic
::singleton();
90 $this->mime
= $magic->guessMimeType( $this->path
);
95 function getImageSize( $filename ) {
96 if ( !$this->getHandler() ) {
99 return $this->handler
->getImageSize( $this, $this->getPath() );
102 function getMetadata() {
103 if ( !isset( $this->metadata
) ) {
104 if ( !$this->getHandler() ) {
105 $this->metadata
= false;
107 $this->metadata
= $this->handler
->getMetadata( $this, $this->getPath() );
110 return $this->metadata
;
115 return $this->repo
->getZoneUrl( 'public' ) . '/' . $this->repo
->getHashPath( $this->name
) . rawurlencode( $this->name
);
122 if ( file_exists( $this->path
) ) {
123 return filesize( $this->path
);