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;
32 * @return UnregisteredLocalFile
34 static function newFromPath( $path, $mime ) {
35 return new self( false, false, $path, $mime );
41 * @return UnregisteredLocalFile
43 static function newFromTitle( $title, $repo ) {
44 return new self( $title, $repo, false, false );
48 * Create an UnregisteredLocalFile based on a path or a (title,repo) pair.
49 * A FileRepo object is not required here, unlike most other File classes.
52 * @param $title Title|false
57 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
58 if ( !( $title && $repo ) && !$path ) {
59 throw new MWException( __METHOD__
.': not enough parameters, must specify title and repo, or a full path' );
61 if ( $title instanceof Title
) {
62 $this->title
= File
::normalizeTitle( $title, 'exception' );
63 $this->name
= $repo->getNameFromTitle( $title );
65 $this->name
= basename( $path );
66 $this->title
= File
::normalizeTitle( $this->name
, 'exception' );
72 $this->path
= $repo->getRootDirectory() . '/' .
73 $repo->getHashPath( $this->name
) . $this->name
;
78 $this->dims
= array();
81 private function cachePageDimensions( $page = 1 ) {
82 if ( !isset( $this->dims
[$page] ) ) {
83 if ( !$this->getHandler() ) {
86 $this->dims
[$page] = $this->handler
->getPageDimensions( $this, $page );
88 return $this->dims
[$page];
91 function getWidth( $page = 1 ) {
92 $dim = $this->cachePageDimensions( $page );
96 function getHeight( $page = 1 ) {
97 $dim = $this->cachePageDimensions( $page );
98 return $dim['height'];
101 function getMimeType() {
102 if ( !isset( $this->mime
) ) {
103 $magic = MimeMagic
::singleton();
104 $this->mime
= $magic->guessMimeType( $this->getPath() );
109 function getImageSize( $filename ) {
110 if ( !$this->getHandler() ) {
113 return $this->handler
->getImageSize( $this, $this->getPath() );
116 function getMetadata() {
117 if ( !isset( $this->metadata
) ) {
118 if ( !$this->getHandler() ) {
119 $this->metadata
= false;
121 $this->metadata
= $this->handler
->getMetadata( $this, $this->getPath() );
124 return $this->metadata
;
129 return $this->repo
->getZoneUrl( 'public' ) . '/' .
130 $this->repo
->getHashPath( $this->name
) . rawurlencode( $this->name
);
137 if ( file_exists( $this->path
) ) {
138 return filesize( $this->path
);