Fix bug that brakes the 'jquery.tabIndex > firstTabIndex' test in IE8/IE9. Some value...
[mediawiki.git] / includes / filerepo / UnregisteredLocalFile.php
blob2df9a9b5d258e91d5da58c5b26454644d061e4d9
1 <?php
2 /**
3 * File without associated database record
5 * @file
6 * @ingroup FileRepo
7 */
9 /**
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.
13 * Read-only.
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
17 * standalone role.
19 * @ingroup FileRepo
21 class UnregisteredLocalFile extends File {
22 var $title, $path, $mime, $dims;
24 /**
25 * @var MediaHandler
27 var $handler;
29 /**
30 * @param $path
31 * @param $mime
32 * @return UnregisteredLocalFile
34 static function newFromPath( $path, $mime ) {
35 return new UnregisteredLocalFile( false, false, $path, $mime );
38 /**
39 * @param $title
40 * @param $repo
41 * @return UnregisteredLocalFile
43 static function newFromTitle( $title, $repo ) {
44 return new UnregisteredLocalFile( $title, $repo, false, false );
47 /**
48 * @throws MWException
49 * @param $title string
50 * @param $repo FSRepo
51 * @param $path string
52 * @param $mime 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' );
58 if ( $title ) {
59 $this->title = $title;
60 $this->name = $repo->getNameFromTitle( $title );
61 } else {
62 $this->name = basename( $path );
63 $this->title = Title::makeTitleSafe( NS_FILE, $this->name );
65 $this->repo = $repo;
66 if ( $path ) {
67 $this->path = $path;
68 } else {
69 $this->path = $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name ) . $this->name;
71 if ( $mime ) {
72 $this->mime = $mime;
74 $this->dims = array();
77 function getPageDimensions( $page = 1 ) {
78 if ( !isset( $this->dims[$page] ) ) {
79 if ( !$this->getHandler() ) {
80 return false;
82 $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
84 return $this->dims[$page];
87 function getWidth( $page = 1 ) {
88 $dim = $this->getPageDimensions( $page );
89 return $dim['width'];
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 );
102 return $this->mime;
105 function getImageSize( $filename ) {
106 if ( !$this->getHandler() ) {
107 return false;
109 return $this->handler->getImageSize( $this, $this->getPath() );
112 function getMetadata() {
113 if ( !isset( $this->metadata ) ) {
114 if ( !$this->getHandler() ) {
115 $this->metadata = false;
116 } else {
117 $this->metadata = $this->handler->getMetadata( $this, $this->getPath() );
120 return $this->metadata;
123 function getURL() {
124 if ( $this->repo ) {
125 return $this->repo->getZoneUrl( 'public' ) . '/' . $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name );
126 } else {
127 return false;
131 function getSize() {
132 if ( file_exists( $this->path ) ) {
133 return filesize( $this->path );
134 } else {
135 return false;