A parser test for the spaces.
[mediawiki.git] / includes / filerepo / UnregisteredLocalFile.php
blob6f63cb0bca71851b6cbb69427bf0e4460b8a7d1f
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 * @ingroup FileRepo
15 class UnregisteredLocalFile extends File {
16 var $title, $path, $mime, $handler, $dims;
18 static function newFromPath( $path, $mime ) {
19 return new UnregisteredLocalFile( false, false, $path, $mime );
22 static function newFromTitle( $title, $repo ) {
23 return new UnregisteredLocalFile( $title, $repo, false, false );
26 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
27 if ( !( $title && $repo ) && !$path ) {
28 throw new MWException( __METHOD__.': not enough parameters, must specify title and repo, or a full path' );
30 if ( $title ) {
31 $this->title = $title;
32 $this->name = $repo->getNameFromTitle( $title );
33 } else {
34 $this->name = basename( $path );
35 $this->title = Title::makeTitleSafe( NS_FILE, $this->name );
37 $this->repo = $repo;
38 if ( $path ) {
39 $this->path = $path;
40 } else {
41 $this->path = $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name ) . $this->name;
43 if ( $mime ) {
44 $this->mime = $mime;
46 $this->dims = array();
49 function getPageDimensions( $page = 1 ) {
50 if ( !isset( $this->dims[$page] ) ) {
51 if ( !$this->getHandler() ) {
52 return false;
54 $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
56 return $this->dims[$page];
59 function getWidth( $page = 1 ) {
60 $dim = $this->getPageDimensions( $page );
61 return $dim['width'];
64 function getHeight( $page = 1 ) {
65 $dim = $this->getPageDimensions( $page );
66 return $dim['height'];
69 function getMimeType() {
70 if ( !isset( $this->mime ) ) {
71 $magic = MimeMagic::singleton();
72 $this->mime = $magic->guessMimeType( $this->path );
74 return $this->mime;
77 function getImageSize( $filename ) {
78 if ( !$this->getHandler() ) {
79 return false;
81 return $this->handler->getImageSize( $this, $this->getPath() );
84 function getMetadata() {
85 if ( !isset( $this->metadata ) ) {
86 if ( !$this->getHandler() ) {
87 $this->metadata = false;
88 } else {
89 $this->metadata = $this->handler->getMetadata( $this, $this->getPath() );
92 return $this->metadata;
95 function getURL() {
96 if ( $this->repo ) {
97 return $this->repo->getZoneUrl( 'public' ) . '/' . $this->repo->getHashPath( $this->name ) . urlencode( $this->name );
98 } else {
99 return false;
103 function getSize() {
104 if ( file_exists( $this->path ) ) {
105 return filesize( $this->path );
106 } else {
107 return false;