Make a note about the reserved word problem.
[mediawiki.git] / includes / filerepo / UnregisteredLocalFile.php
blob419c61f6cd45e23931874461ab894395e60f4c95
1 <?php
3 /**
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.
7 * Read-only.
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
11 * standalone role.
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' );
28 if ( $title ) {
29 $this->title = $title;
30 $this->name = $repo->getNameFromTitle( $title );
31 } else {
32 $this->name = basename( $path );
33 $this->title = Title::makeTitleSafe( NS_IMAGE, $this->name );
35 $this->repo = $repo;
36 if ( $path ) {
37 $this->path = $path;
38 } else {
39 $this->path = $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name ) . $this->name;
41 if ( $mime ) {
42 $this->mime = $mime;
44 $this->dims = array();
47 function getPageDimensions( $page = 1 ) {
48 if ( !isset( $this->dims[$page] ) ) {
49 if ( !$this->getHandler() ) {
50 return false;
52 $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
54 return $this->dims[$page];
57 function getWidth( $page = 1 ) {
58 $dim = $this->getPageDimensions( $page );
59 return $dim['width'];
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 );
72 return $this->mime;
75 function getImageSize( $filename ) {
76 if ( !$this->getHandler() ) {
77 return false;
79 return $this->handler->getImageSize( $this, $this->getPath() );
82 function getMetadata() {
83 if ( !isset( $this->metadata ) ) {
84 if ( !$this->getHandler() ) {
85 $this->metadata = false;
86 } else {
87 $this->metadata = $this->handler->getMetadata( $this, $this->getPath() );
90 return $this->metadata;
93 function getURL() {
94 if ( $this->repo ) {
95 return $this->repo->getZoneUrl( 'public' ) . '/' . $this->repo->getHashPath( $this->name ) . urlencode( $this->name );
96 } else {
97 return false;
101 function getSize() {
102 if ( file_exists( $this->path ) ) {
103 return filesize( $this->path );
104 } else {
105 return false;