65a18a506209c58dc89f92d396f86b05fdf31463
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 FileRepo 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, $dims;
30 * @param $path string Storage path
32 * @return UnregisteredLocalFile
34 static function newFromPath( $path, $mime ) {
35 return new self( false, false, $path, $mime );
41 * @return UnregisteredLocalFile
43 static function newFromTitle( $title, $repo ) {
44 return new self( $title, $repo, false, false );
48 * Create an UnregisteredLocalFile based on a path or a (title,repo) pair.
49 * A FileRepo object is not required here, unlike most other File classes.
52 * @param $title Title|false
53 * @param $repo FileRepo
57 function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
58 if ( !( $title && $repo ) && !$path ) {
59 throw new MWException( __METHOD__
.': not enough parameters, must specify title and repo, or a full path' );
61 if ( $title instanceof Title
) {
62 $this->title
= File
::normalizeTitle( $title, 'exception' );
63 $this->name
= $repo->getNameFromTitle( $title );
65 $this->name
= basename( $path );
66 $this->title
= File
::normalizeTitle( $this->name
, 'exception' );
72 $this->assertRepoDefined();
73 $this->path
= $repo->getRootDirectory() . '/' .
74 $repo->getHashPath( $this->name
) . $this->name
;
79 $this->dims
= array();
82 private function cachePageDimensions( $page = 1 ) {
83 if ( !isset( $this->dims
[$page] ) ) {
84 if ( !$this->getHandler() ) {
87 $this->dims
[$page] = $this->handler
->getPageDimensions( $this, $page );
89 return $this->dims
[$page];
92 function getWidth( $page = 1 ) {
93 $dim = $this->cachePageDimensions( $page );
97 function getHeight( $page = 1 ) {
98 $dim = $this->cachePageDimensions( $page );
99 return $dim['height'];
102 function getMimeType() {
103 if ( !isset( $this->mime
) ) {
104 $magic = MimeMagic
::singleton();
105 $this->mime
= $magic->guessMimeType( $this->getLocalRefPath() );
110 function getImageSize( $filename ) {
111 if ( !$this->getHandler() ) {
114 return $this->handler
->getImageSize( $this, $this->getLocalRefPath() );
117 function getMetadata() {
118 if ( !isset( $this->metadata
) ) {
119 if ( !$this->getHandler() ) {
120 $this->metadata
= false;
122 $this->metadata
= $this->handler
->getMetadata( $this, $this->getLocalRefPath() );
125 return $this->metadata
;
130 return $this->repo
->getZoneUrl( 'public' ) . '/' .
131 $this->repo
->getHashPath( $this->name
) . rawurlencode( $this->name
);
138 $this->assertRepoDefined();
139 $props = $this->repo
->getFileProps( $this->path
);
140 if ( isset( $props['size'] ) ) {
141 return $props['size'];
143 return false; // doesn't exist