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, $handler, $dims;
24 static function newFromPath( $path, $mime ) {
25 return new UnregisteredLocalFile( false, false, $path, $mime );
28 static function newFromTitle( $title, $repo ) {
29 return new UnregisteredLocalFile( $title, $repo, false, false );
32 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
33 if ( !( $title && $repo ) && !$path ) {
34 throw new MWException( __METHOD__.': not enough parameters, must specify title and repo, or a full path' );
37 $this->title = $title;
38 $this->name = $repo->getNameFromTitle( $title );
40 $this->name = basename( $path );
41 $this->title = Title::makeTitleSafe( NS_FILE, $this->name );
47 $this->path = $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name ) . $this->name;
52 $this->dims = array();
55 function getPageDimensions( $page = 1 ) {
56 if ( !isset( $this->dims[$page] ) ) {
57 if ( !$this->getHandler() ) {
60 $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
62 return $this->dims[$page];
65 function getWidth( $page = 1 ) {
66 $dim = $this->getPageDimensions( $page );
70 function getHeight( $page = 1 ) {
71 $dim = $this->getPageDimensions( $page );
72 return $dim['height'];
75 function getMimeType() {
76 if ( !isset( $this->mime ) ) {
77 $magic = MimeMagic::singleton();
78 $this->mime = $magic->guessMimeType( $this->path );
83 function getImageSize( $filename ) {
84 if ( !$this->getHandler() ) {
87 return $this->handler->getImageSize( $this, $this->getPath() );
90 function getMetadata() {
91 if ( !isset( $this->metadata ) ) {
92 if ( !$this->getHandler() ) {
93 $this->metadata = false;
95 $this->metadata = $this->handler->getMetadata( $this, $this->getPath() );
98 return $this->metadata;
103 return $this->repo->getZoneUrl( 'public' ) . '/' . $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name );
110 if ( file_exists( $this->path ) ) {
111 return filesize( $this->path );