MediaWiki  1.32.5
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 = [];
107  }
108 
113  private function cachePageDimensions( $page = 1 ) {
114  $page = (int)$page;
115  if ( $page < 1 ) {
116  $page = 1;
117  }
118 
119  if ( !isset( $this->dims[$page] ) ) {
120  if ( !$this->getHandler() ) {
121  return false;
122  }
123  $this->dims[$page] = $this->handler->getPageDimensions( $this, $page );
124  }
125 
126  return $this->dims[$page];
127  }
128 
133  function getWidth( $page = 1 ) {
134  $dim = $this->cachePageDimensions( $page );
135 
136  return $dim['width'];
137  }
138 
143  function getHeight( $page = 1 ) {
144  $dim = $this->cachePageDimensions( $page );
145 
146  return $dim['height'];
147  }
148 
152  function getMimeType() {
153  if ( !isset( $this->mime ) ) {
154  $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
155  $this->mime = $magic->guessMimeType( $this->getLocalRefPath() );
156  }
157 
158  return $this->mime;
159  }
160 
165  function getImageSize( $filename ) {
166  if ( !$this->getHandler() ) {
167  return false;
168  }
169 
170  return $this->handler->getImageSize( $this, $this->getLocalRefPath() );
171  }
172 
176  function getBitDepth() {
177  $gis = $this->getImageSize( $this->getLocalRefPath() );
178 
179  if ( !$gis || !isset( $gis['bits'] ) ) {
180  return 0;
181  }
182  return $gis['bits'];
183  }
184 
188  function getMetadata() {
189  if ( !isset( $this->metadata ) ) {
190  if ( !$this->getHandler() ) {
191  $this->metadata = false;
192  } else {
193  $this->metadata = $this->handler->getMetadata( $this, $this->getLocalRefPath() );
194  }
195  }
196 
197  return $this->metadata;
198  }
199 
203  function getURL() {
204  if ( $this->repo ) {
205  return $this->repo->getZoneUrl( 'public' ) . '/' .
206  $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name );
207  } else {
208  return false;
209  }
210  }
211 
215  function getSize() {
216  $this->assertRepoDefined();
217 
218  return $this->repo->getFileSize( $this->path );
219  }
220 
229  public function setLocalReference( FSFile $fsFile ) {
230  $this->fsFile = $fsFile;
231  }
232 }
UnregisteredLocalFile\newFromTitle
static newFromTitle( $title, $repo)
Definition: UnregisteredLocalFile.php:69
File\$repo
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition: File.php:96
UnregisteredLocalFile\getSize
getSize()
Definition: UnregisteredLocalFile.php:215
UnregisteredLocalFile\newFromPath
static newFromPath( $path, $mime)
Definition: UnregisteredLocalFile.php:60
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
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:83
FileRepo\getRootDirectory
getRootDirectory()
Get the public zone root storage directory of the repository.
Definition: FileRepo.php:660
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:38
UnregisteredLocalFile\getMetadata
getMetadata()
Definition: UnregisteredLocalFile.php:188
UnregisteredLocalFile\getWidth
getWidth( $page=1)
Definition: UnregisteredLocalFile.php:133
UnregisteredLocalFile\getBitDepth
getBitDepth()
Definition: UnregisteredLocalFile.php:176
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:184
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
UnregisteredLocalFile\$path
string $path
Definition: UnregisteredLocalFile.php:41
handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves set to a MediaTransformOutput the error message to be returned in an array you should do so by altering $wgNamespaceProtection and $wgNamespaceContentModels outside the handler
Definition: hooks.txt:813
name
and how to run hooks for an and one after Each event has a name
Definition: hooks.txt:6
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:51
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:433
UnregisteredLocalFile\getURL
getURL()
Definition: UnregisteredLocalFile.php:203
UnregisteredLocalFile\getImageSize
getImageSize( $filename)
Definition: UnregisteredLocalFile.php:165
UnregisteredLocalFile\setLocalReference
setLocalReference(FSFile $fsFile)
Optimize getLocalRefPath() by using an existing local reference.
Definition: UnregisteredLocalFile.php:229
UnregisteredLocalFile\$metadata
bool string $metadata
Handler-specific metadata which will be saved in the img_metadata field.
Definition: UnregisteredLocalFile.php:50
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
FileRepo\getNameFromTitle
getNameFromTitle(Title $title)
Get the name of a file from its title object.
Definition: FileRepo.php:642
UnregisteredLocalFile\getHeight
getHeight( $page=1)
Definition: UnregisteredLocalFile.php:143
File\$fsFile
FSFile bool $fsFile
False if undefined.
Definition: File.php:111
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:120
title
title
Definition: parserTests.txt:239
FSFile
Class representing a non-directory file on the file system.
Definition: FSFile.php:29
UnregisteredLocalFile\getMimeType
getMimeType()
Definition: UnregisteredLocalFile.php:152
FileRepo\getHashPath
getHashPath( $name)
Get a relative path including trailing slash, e.g.
Definition: FileRepo.php:671
UnregisteredLocalFile\$handler
MediaHandler $handler
Definition: UnregisteredLocalFile.php:53
Title
Represents a title within MediaWiki.
Definition: Title.php:39
UnregisteredLocalFile\cachePageDimensions
cachePageDimensions( $page=1)
Definition: UnregisteredLocalFile.php:113
File\assertRepoDefined
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
Definition: File.php:2279
File\$name
string $name
The name of a file from its title object.
Definition: File.php:123
File\getHandler
getHandler()
Get a MediaHandler instance for this file.
Definition: File.php:1383
UnregisteredLocalFile\$dims
array $dims
Dimension data.
Definition: UnregisteredLocalFile.php:47
UnregisteredLocalFile\$mime
bool string $mime
Definition: UnregisteredLocalFile.php:44
MediaHandler
Base media handler class.
Definition: MediaHandler.php:30