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 UnregisteredLocalFile( false, false, $path, $mime );
41 * @return UnregisteredLocalFile
43 static function newFromTitle( $title, $repo ) {
44 return new UnregisteredLocalFile( $title, $repo, false, false );
49 * @param $title string
54 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
55 if ( !( $title && $repo ) && !$path ) {
56 throw new MWException( __METHOD__
.': not enough parameters, must specify title and repo, or a full path' );
59 $this->title
= $title;
60 $this->name
= $repo->getNameFromTitle( $title );
62 $this->name
= basename( $path );
63 $this->title
= Title
::makeTitleSafe( NS_FILE
, $this->name
);
69 $this->path
= $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name
) . $this->name
;
74 $this->dims
= array();
77 function getPageDimensions( $page = 1 ) {
78 if ( !isset( $this->dims
[$page] ) ) {
79 if ( !$this->getHandler() ) {
82 $this->dims
[$page] = $this->handler
->getPageDimensions( $this, $page );
84 return $this->dims
[$page];
87 function getWidth( $page = 1 ) {
88 $dim = $this->getPageDimensions( $page );
92 function getHeight( $page = 1 ) {
93 $dim = $this->getPageDimensions( $page );
94 return $dim['height'];
97 function getMimeType() {
98 if ( !isset( $this->mime
) ) {
99 $magic = MimeMagic
::singleton();
100 $this->mime
= $magic->guessMimeType( $this->path
);
105 function getImageSize( $filename ) {
106 if ( !$this->getHandler() ) {
109 return $this->handler
->getImageSize( $this, $this->getPath() );
112 function getMetadata() {
113 if ( !isset( $this->metadata
) ) {
114 if ( !$this->getHandler() ) {
115 $this->metadata
= false;
117 $this->metadata
= $this->handler
->getMetadata( $this, $this->getPath() );
120 return $this->metadata
;
125 return $this->repo
->getZoneUrl( 'public' ) . '/' . $this->repo
->getHashPath( $this->name
) . rawurlencode( $this->name
);
132 if ( file_exists( $this->path
) ) {
133 return filesize( $this->path
);