MediaWiki  1.27.4
FSFile Class Reference

Class representing a non-directory file on the file system. More...

Inheritance diagram for FSFile:
Collaboration diagram for FSFile:

Public Member Functions

 __construct ($path)
 Sets up the file object. More...
 
 exists ()
 Checks if the file exists. More...
 
 getMimeType ()
 Guess the MIME type from the file contents alone. More...
 
 getPath ()
 Returns the file system path. More...
 
 getProps ($ext=true)
 Get an associative array containing information about a file with the given storage path. More...
 
 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. More...
 
 getSize ()
 Get the file size in bytes. More...
 
 getTimestamp ()
 Get the file's last-modified timestamp. More...
 

Static Public Member Functions

static extensionFromPath ($path)
 Get the final file extension from a file system path. More...
 
static getPropsFromPath ($path, $ext=true)
 Get an associative array containing information about a file in the local filesystem. More...
 
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. More...
 
static placeholderProps ()
 Placeholder file properties to use for files that don't exist. More...
 

Protected Member Functions

 extractImageSizeInfo (array $gis)
 Exract image size information. More...
 

Protected Attributes

string $path
 Path to file. More...
 
string $sha1Base36
 File SHA-1 in base 36. More...
 

Detailed Description

Class representing a non-directory file on the file system.

Definition at line 29 of file FSFile.php.

Constructor & Destructor Documentation

FSFile::__construct (   $path)

Sets up the file object.

Parameters
string$pathPath to temporary file on local disk

Definition at line 41 of file FSFile.php.

References $path.

Member Function Documentation

FSFile::exists ( )

Checks if the file exists.

Returns
bool

Definition at line 59 of file FSFile.php.

Referenced by getProps().

static FSFile::extensionFromPath (   $path)
static

Get the final file extension from a file system path.

Parameters
string$path
Returns
string

Definition at line 245 of file FSFile.php.

FSFile::extractImageSizeInfo ( array  $gis)
protected

Exract image size information.

Parameters
array$gis
Returns
array

Definition at line 199 of file FSFile.php.

Referenced by getProps().

FSFile::getMimeType ( )

Guess the MIME type from the file contents alone.

Returns
string

Definition at line 93 of file FSFile.php.

References MimeMagic\singleton().

Referenced by getProps().

FSFile::getPath ( )

Returns the file system path.

Returns
string

Definition at line 50 of file FSFile.php.

References $path.

FSFile::getProps (   $ext = true)

Get an associative array containing information about a file with the given storage path.

Resulting array fields include:

  • fileExists
  • size (filesize in bytes)
  • mime (as major/minor)
  • media_type (value to be used with the MEDIATYPE_xxx constants)
  • metadata (handler specific)
  • sha1 (in base 36)
  • width
  • height
  • bits (bitrate)
  • file-mime
  • major_mime
  • minor_mime
Parameters
string | bool$extThe file extension, or true to extract it from the filename. Set it to false to ignore the extension.
Returns
array

Definition at line 119 of file FSFile.php.

References $ext, $handler, exists(), extractImageSizeInfo(), MediaHandler\getHandler(), getMimeType(), getSha1Base36(), getSize(), list, object, MimeMagic\singleton(), File\splitMime(), and wfDebug().

static FSFile::getPropsFromPath (   $path,
  $ext = true 
)
static

Get an associative array containing information about a file in the local filesystem.

Parameters
string$pathAbsolute local filesystem path
string | bool$extThe file extension, or true to extract it from the filename. Set it to false to ignore the extension.
Returns
array

Definition at line 259 of file FSFile.php.

References $ext, and $path.

Referenced by FileBackendTest\doTestStore(), RepoGroup\getFileProps(), UploadStash\stashFile(), LocalFile\upload(), UploadBase\verifyFile(), and UploadBase\verifyPartialFile().

FSFile::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.

160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36 fairly neatly.

Parameters
bool$recache
Returns
bool|string False on failure

Definition at line 223 of file FSFile.php.

References $sha1Base36.

Referenced by getProps().

static FSFile::getSha1Base36FromPath (   $path)
static

Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.

160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36 fairly neatly.

Parameters
string$path
Returns
bool|string False on failure

Definition at line 275 of file FSFile.php.

References $path.

Referenced by ApiTestCaseUpload\deleteFileByContent(), UploadBase\getTempFileSha1Base36(), and LocalFile\publishTo().

FSFile::getSize ( )

Get the file size in bytes.

Returns
int|bool

Definition at line 68 of file FSFile.php.

Referenced by getProps().

FSFile::getTimestamp ( )

Get the file's last-modified timestamp.

Returns
string|bool TS_MW timestamp or false on failure

Definition at line 77 of file FSFile.php.

References $timestamp, TS_MW, and wfTimestamp().

static FSFile::placeholderProps ( )
static

Placeholder file properties to use for files that don't exist.

Resulting array fields include:

  • fileExists
  • mime (as major/minor)
  • media_type (value to be used with the MEDIATYPE_xxx constants)
  • metadata (handler specific)
  • sha1 (in base 36)
  • width
  • height
  • bits (bitrate)
Returns
array

Definition at line 179 of file FSFile.php.

References MEDIATYPE_UNKNOWN.

Referenced by FileBackendStore\getFileProps().

Member Data Documentation

string FSFile::$sha1Base36
protected

File SHA-1 in base 36.

Definition at line 34 of file FSFile.php.

Referenced by getSha1Base36().


The documentation for this class was generated from the following file: