60 return is_file( $this->path );
69 return filesize( $this->path );
78 MediaWiki\suppressWarnings();
80 MediaWiki\restoreWarnings();
120 wfDebug( __METHOD__ .
": Getting file info for $this->path\n" );
122 $info = self::placeholderProps();
123 $info[
'fileExists'] = $this->
exists();
125 if ( $info[
'fileExists'] ) {
128 # get the file extension
129 if (
$ext ===
true ) {
130 $ext = self::extensionFromPath( $this->path );
133 # MIME type according to file contents
136 $info[
'mime'] = $magic->improveTypeFromExtension( $info[
'file-mime'],
$ext );
139 $info[
'media_type'] = $magic->getMediaType( $this->path, $info[
'mime'] );
142 $info[
'size'] = $this->
getSize();
144 # Height, width and metadata
148 $info[
'metadata'] =
$handler->getMetadata( $tempImage, $this->path );
149 $gis =
$handler->getImageSize( $tempImage, $this->path, $info[
'metadata'] );
150 if ( is_array( $gis ) ) {
156 wfDebug( __METHOD__ .
": $this->path loaded, {$info['size']} bytes, {$info['mime']}.\n" );
158 wfDebug( __METHOD__ .
": $this->path NOT FOUND!\n" );
181 $info[
'fileExists'] =
false;
182 $info[
'mime'] = null;
184 $info[
'metadata'] =
'';
201 # NOTE: $gis[2] contains a code for the image type. This is no longer used.
202 $info[
'width'] = $gis[0];
203 $info[
'height'] = $gis[1];
204 if ( isset( $gis[
'bits'] ) ) {
205 $info[
'bits'] = $gis[
'bits'];
224 if ( $this->sha1Base36 !== null && !$recache ) {
228 MediaWiki\suppressWarnings();
229 $this->sha1Base36 = sha1_file( $this->path );
230 MediaWiki\restoreWarnings();
232 if ( $this->sha1Base36 !==
false ) {
233 $this->sha1Base36 = Wikimedia\base_convert( $this->sha1Base36, 16, 36, 31 );
246 $i = strrpos(
$path,
'.' );
248 return strtolower( $i ? substr(
$path, $i + 1 ) :
'' );
260 $fsFile =
new self(
$path );
262 return $fsFile->getProps(
$ext );
276 $fsFile =
new self(
$path );
278 return $fsFile->getSha1Base36();
getMimeType()
Guess the MIME type from the file contents alone.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
the array() calling protocol came about after MediaWiki 1.4rc1.
__construct($path)
Sets up the file object.
static splitMime($mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to '...
getPath()
Returns the file system path.
string $sha1Base36
File SHA-1 in base 36.
static singleton()
Get an instance of this class.
string $path
Path to file.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static extensionFromPath($path)
Get the final file extension from a file system path.
getProps($ext=true)
Get an associative array containing information about a file with the given storage path...
static placeholderProps()
Placeholder file properties to use for files that don't exist.
static getSha1Base36FromPath($path)
Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
extractImageSizeInfo(array $gis)
Exract image size information.
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
exists()
Checks if the file exists.
Class representing a non-directory file on the file system.
getSize()
Get the file size in bytes.
getSha1Base36($recache=false)
Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.
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 $handler
getTimestamp()
Get the file's last-modified timestamp.
static getPropsFromPath($path, $ext=true)
Get an associative array containing information about a file in the local filesystem.