]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/filerepo/UnregisteredLocalFile.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / includes / filerepo / UnregisteredLocalFile.php
1 <?php
2
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.
6  *
7  * Read-only.
8  *
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.
12  *
13  * @ingroup FileRepo
14  */
15 class UnregisteredLocalFile extends File {
16         var $title, $path, $mime, $handler, $dims;
17
18         static function newFromPath( $path, $mime ) {
19                 return new UnregisteredLocalFile( false, false, $path, $mime );
20         }
21
22         static function newFromTitle( $title, $repo ) {
23                 return new UnregisteredLocalFile( $title, $repo, false, false );
24         }
25
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' );
29                 }
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 );
36                 }
37                 $this->repo = $repo;
38                 if ( $path ) {
39                         $this->path = $path;
40                 } else {
41                         $this->path = $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name ) . $this->name;
42                 }
43                 if ( $mime ) {
44                         $this->mime = $mime;
45                 }
46                 $this->dims = array();
47         }
48
49         function getPageDimensions( $page = 1 ) {
50                 if ( !isset( $this->dims[$page] ) ) {
51                         if ( !$this->getHandler() ) {
52                                 return false;
53                         }
54                         $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
55                 }
56                 return $this->dims[$page];
57         }
58
59         function getWidth( $page = 1 ) {
60                 $dim = $this->getPageDimensions( $page );
61                 return $dim['width'];
62         }
63
64         function getHeight( $page = 1 ) {
65                 $dim = $this->getPageDimensions( $page );
66                 return $dim['height'];
67         }
68
69         function getMimeType() {
70                 if ( !isset( $this->mime ) ) {
71                         $magic = MimeMagic::singleton();
72                         $this->mime = $magic->guessMimeType( $this->path );
73                 }
74                 return $this->mime;
75         }
76
77         function getImageSize( $filename ) {
78                 if ( !$this->getHandler() ) {
79                         return false;
80                 }
81                 return $this->handler->getImageSize( $this, $this->getPath() );
82         }
83
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() );
90                         }
91                 }
92                 return $this->metadata;
93         }
94
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;
100                 }
101         }
102
103         function getSize() {
104                 if ( file_exists( $this->path ) ) {
105                         return filesize( $this->path );
106                 } else {
107                         return false;
108                 }
109         }
110 }