MediaWiki REL1_31
UnregisteredLocalFile.php
Go to the documentation of this file.
1<?php
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}
Class representing a non-directory file on the file system.
Definition FSFile.php:29
getRootDirectory()
Get the public zone root storage directory of the repository.
Definition FileRepo.php:669
getHashPath( $name)
Get a relative path including trailing slash, e.g.
Definition FileRepo.php:680
getNameFromTitle(Title $title)
Get the name of a file from its title object.
Definition FileRepo.php:650
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:51
FSFile bool $fsFile
False if undefined.
Definition File.php:111
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
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
Definition File.php:2287
getLocalRefPath()
Get an FS copy or original of this file and return the path.
Definition File.php:433
string $name
The name of a file from its title object.
Definition File.php:123
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:96
getHandler()
Get a MediaHandler instance for this file.
Definition File.php:1383
MediaWiki exception.
Base media handler class.
Represents a title within MediaWiki.
Definition Title.php:39
A file object referring to either a standalone local file, or a file in a local repository with no da...
setLocalReference(FSFile $fsFile)
Optimize getLocalRefPath() by using an existing local reference.
__construct( $title=false, $repo=false, $path=false, $mime=false)
Create an UnregisteredLocalFile based on a path or a (title,repo) pair.
static newFromPath( $path, $mime)
array $dims
Dimension data.
static newFromTitle( $title, $repo)
bool string $metadata
Handler-specific metadata which will be saved in the img_metadata field.
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:930
> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) name
Definition hooks.txt:1840
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187