MediaWiki  1.23.14
UnregisteredLocalFile.php
Go to the documentation of this file.
1 <?php
36 class UnregisteredLocalFile extends File {
38  protected $title;
39 
41  protected $path;
42 
44  protected $mime;
45 
47  protected $dims;
48 
50  protected $metadata;
51 
53  public $handler;
54 
60  static function newFromPath( $path, $mime ) {
61  return new self( false, false, $path, $mime );
62  }
63 
69  static function newFromTitle( $title, $repo ) {
70  return new self( $title, $repo, false, false );
71  }
72 
83  function __construct( $title = false, $repo = false, $path = false, $mime = false ) {
84  if ( !( $title && $repo ) && !$path ) {
85  throw new MWException( __METHOD__ .
86  ': not enough parameters, must specify title and repo, or a full path' );
87  }
88  if ( $title instanceof Title ) {
89  $this->title = File::normalizeTitle( $title, 'exception' );
90  $this->name = $repo->getNameFromTitle( $title );
91  } else {
92  $this->name = basename( $path );
93  $this->title = File::normalizeTitle( $this->name, 'exception' );
94  }
95  $this->repo = $repo;
96  if ( $path ) {
97  $this->path = $path;
98  } else {
99  $this->assertRepoDefined();
100  $this->path = $repo->getRootDirectory() . '/' .
101  $repo->getHashPath( $this->name ) . $this->name;
102  }
103  if ( $mime ) {
104  $this->mime = $mime;
105  }
106  $this->dims = array();
107  }
108 
113  private function cachePageDimensions( $page = 1 ) {
114  if ( !isset( $this->dims[$page] ) ) {
115  if ( !$this->getHandler() ) {
116  return false;
117  }
118  $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
119  }
120 
121  return $this->dims[$page];
122  }
123 
128  function getWidth( $page = 1 ) {
129  $dim = $this->cachePageDimensions( $page );
130 
131  return $dim['width'];
132  }
133 
138  function getHeight( $page = 1 ) {
139  $dim = $this->cachePageDimensions( $page );
140 
141  return $dim['height'];
142  }
143 
147  function getMimeType() {
148  if ( !isset( $this->mime ) ) {
149  $magic = MimeMagic::singleton();
150  $this->mime = $magic->guessMimeType( $this->getLocalRefPath() );
151  }
152 
153  return $this->mime;
154  }
155 
160  function getImageSize( $filename ) {
161  if ( !$this->getHandler() ) {
162  return false;
163  }
164 
165  return $this->handler->getImageSize( $this, $this->getLocalRefPath() );
166  }
167 
171  function getMetadata() {
172  if ( !isset( $this->metadata ) ) {
173  if ( !$this->getHandler() ) {
174  $this->metadata = false;
175  } else {
176  $this->metadata = $this->handler->getMetadata( $this, $this->getLocalRefPath() );
177  }
178  }
179 
181  }
182 
186  function getURL() {
187  if ( $this->repo ) {
188  return $this->repo->getZoneUrl( 'public' ) . '/' .
189  $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name );
190  } else {
191  return false;
192  }
193  }
194 
198  function getSize() {
199  $this->assertRepoDefined();
200 
201  return $this->repo->getFileSize( $this->path );
202  }
203 
212  public function setLocalReference( FSFile $fsFile ) {
213  $this->fsFile = $fsFile;
214  }
215 }
UnregisteredLocalFile\newFromTitle
static newFromTitle( $title, $repo)
Definition: UnregisteredLocalFile.php:63
File\$repo
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition: File.php:94
UnregisteredLocalFile\getSize
getSize()
Definition: UnregisteredLocalFile.php:192
UnregisteredLocalFile\newFromPath
static newFromPath( $path, $mime)
Definition: UnregisteredLocalFile.php:54
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
UnregisteredLocalFile\__construct
__construct( $title=false, $repo=false, $path=false, $mime=false)
Create an UnregisteredLocalFile based on a path or a (title,repo) pair.
Definition: UnregisteredLocalFile.php:77
FileRepo\getRootDirectory
getRootDirectory()
Get the public zone root storage directory of the repository.
Definition: FileRepo.php:641
UnregisteredLocalFile
A file object referring to either a standalone local file, or a file in a local repository with no da...
Definition: UnregisteredLocalFile.php:36
UnregisteredLocalFile\$title
Title $title
Definition: UnregisteredLocalFile.php:37
UnregisteredLocalFile\getMetadata
getMetadata()
Definition: UnregisteredLocalFile.php:165
UnregisteredLocalFile\getWidth
getWidth( $page=1)
Definition: UnregisteredLocalFile.php:122
File\normalizeTitle
static normalizeTitle( $title, $exception=false)
Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
Definition: File.php:161
UnregisteredLocalFile\$path
string $path
Definition: UnregisteredLocalFile.php:39
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:50
MWException
MediaWiki exception.
Definition: MWException.php:26
File\getLocalRefPath
getLocalRefPath()
Get an FS copy or original of this file and return the path.
Definition: File.php:399
UnregisteredLocalFile\getURL
getURL()
Definition: UnregisteredLocalFile.php:180
UnregisteredLocalFile\getImageSize
getImageSize( $filename)
Definition: UnregisteredLocalFile.php:154
UnregisteredLocalFile\setLocalReference
setLocalReference(FSFile $fsFile)
Optimize getLocalRefPath() by using an existing local reference.
Definition: UnregisteredLocalFile.php:206
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
UnregisteredLocalFile\$metadata
bool string $metadata
Handler-specific metadata which will be saved in the img_metadata field *.
Definition: UnregisteredLocalFile.php:45
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
FileRepo\getNameFromTitle
getNameFromTitle(Title $title)
Get the name of a file from its title object.
Definition: FileRepo.php:622
UnregisteredLocalFile\getHeight
getHeight( $page=1)
Definition: UnregisteredLocalFile.php:132
File\$fsFile
FSFile bool $fsFile
False if undefined *.
Definition: File.php:104
FSFile
Class representing a non-directory file on the file system.
Definition: FSFile.php:29
UnregisteredLocalFile\getMimeType
getMimeType()
Definition: UnregisteredLocalFile.php:141
FileRepo\getHashPath
getHashPath( $name)
Get a relative path including trailing slash, e.g.
Definition: FileRepo.php:652
UnregisteredLocalFile\$handler
MediaHandler $handler
Definition: UnregisteredLocalFile.php:47
Title
Represents a title within MediaWiki.
Definition: Title.php:35
UnregisteredLocalFile\cachePageDimensions
cachePageDimensions( $page=1)
Definition: UnregisteredLocalFile.php:107
File\assertRepoDefined
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
Definition: File.php:1984
File\$name
string $name
The name of a file from its title object *.
Definition: File.php:112
name
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Definition: design.txt:12
File\getHandler
getHandler()
Get a MediaHandler instance for this file.
Definition: File.php:1078
UnregisteredLocalFile\$dims
array $dims
Dimension data *.
Definition: UnregisteredLocalFile.php:43
UnregisteredLocalFile\$mime
bool string $mime
Definition: UnregisteredLocalFile.php:41
MediaHandler
Base media handler class.
Definition: MediaHandler.php:29