62 return new static(
false,
false,
$path,
$mime );
87 ': not enough parameters, must specify title and repo, or a full path' );
93 $this->name = basename(
$path );
107 $this->pageDims = [];
114 private function cachePageDimensions( $page = 1 ) {
120 if ( !isset( $this->pageDims[$page] ) ) {
124 if ( $this->
getHandler()->isMultiPage( $this ) ) {
125 $this->pageDims[$page] = $this->handler->getPageDimensions( $this, $page );
127 $info = $this->getSizeAndMetadata();
129 'width' => $info[
'width'],
130 'height' => $info[
'height']
135 return $this->pageDims[$page];
143 $dim = $this->cachePageDimensions( $page );
145 return $dim[
'width'] ?? 0;
153 $dim = $this->cachePageDimensions( $page );
155 return $dim[
'height'] ?? 0;
162 if ( !isset( $this->mime ) ) {
164 if ( $refPath !==
false ) {
165 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
166 $this->mime = $magic->guessMimeType( $refPath );
179 $info = $this->getSizeAndMetadata();
180 return $info[
'bits'] ?? 0;
187 $info = $this->getSizeAndMetadata();
188 return $info[
'metadata'] ?
serialize( $info[
'metadata'] ) :
false;
192 $info = $this->getSizeAndMetadata();
193 return $info[
'metadata'];
196 private function getSizeAndMetadata() {
197 if ( $this->sizeAndMetadata ===
null ) {
198 if ( !$this->getHandler() ) {
199 $this->sizeAndMetadata = [
'width' => 0,
'height' => 0,
'metadata' => [] ];
201 $this->sizeAndMetadata = $this->getHandler()->getSizeAndMetadataWithFallback(
202 $this, $this->getLocalRefPath() );
206 return $this->sizeAndMetadata;
214 return $this->repo->getZoneUrl(
'public' ) .
'/' .
215 $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name );
225 $this->assertRepoDefined();
227 return $this->repo->getFileSize( $this->path );
239 $this->fsFile = $fsFile;
Class representing a non-directory file on the file system.
getRootDirectory()
Get the public zone root storage directory of the repository.
getNameFromTitle( $title)
Get the name of a file from its title.
getHashPath( $name)
Get a relative path including trailing slash, e.g.
Implements some public methods and some protected utility functions which are required by multiple ch...
static normalizeTitle( $title, $exception=false)
Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
getLocalRefPath()
Get an FS copy or original of this file and return the path.
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
getHandler()
Get a MediaHandler instance for this file.
string null $name
The name of a file from its title object.
Represents a title within MediaWiki.
File without associated database record.
array null $sizeAndMetadata
setLocalReference(FSFile $fsFile)
Optimize getLocalRefPath() by using an existing local reference.
array[] bool[] $pageDims
Dimension data.
__construct( $title=false, $repo=false, $path=false, $mime=false)
Create an UnregisteredLocalFile based on a path or a (title,repo) pair.
getMetadataArray()
Get the unserialized handler-specific metadata STUB.
static newFromPath( $path, $mime)
static newFromTitle( $title, $repo)