MediaWiki  REL1_22
File Class Reference

Implements some public methods and some protected utility functions which are required by multiple child classes. More...

Inheritance diagram for File:
Collaboration diagram for File:

List of all members.

Public Member Functions

 __construct ($title, $repo)
 Call this constructor from child classes.
 __get ($name)
 allowInlineDisplay ()
 Alias for canRender()
 canAnimateThumbIfAppropriate ()
 Will the thumbnail be animated if one would expect it to be.
 canRender ()
 Checks if the output of transform() for this file is likely to be valid.
 convertMetadataVersion ($metadata, $version)
 get versioned metadata
 createThumb ($width, $height=-1)
 Create a thumbnail of the image having the specified width/height.
 delete ($reason, $suppress=false)
 Delete all versions of the file.
 exists ()
 Returns true if file exists in the repository.
 formatMetadata ()
 generateThumbName ($name, $params)
 Generate a thumbnail file name from a name and specified parameters.
 getArchivePath ($suffix=false)
 Get the path of the archived file.
 getArchiveRel ($suffix=false)
 Get the path of an archived file relative to the public zone root.
 getArchiveThumbPath ($archiveName, $suffix=false)
 Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified.
 getArchiveThumbRel ($archiveName, $suffix=false)
 Get the path, relative to the thumbnail zone root, for an archived file's thumbs directory or a specific thumb if the $suffix is given.
 getArchiveThumbUrl ($archiveName, $suffix=false)
 Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified.
 getArchiveUrl ($suffix=false)
 Get the URL of the archive directory, or a particular file if $suffix is specified.
 getArchiveVirtualUrl ($suffix=false)
 Get the public zone virtual URL for an archived version source file.
 getBitDepth ()
 Return the bit depth of the file Overridden by LocalFile STUB.
 getCanonicalUrl ()
 getDescription ($audience=self::FOR_PUBLIC, User $user=null)
 Get description of file revision STUB.
 getDescriptionText ($lang=false)
 Get the HTML text of the description page, if available.
 getDescriptionUrl ()
 Get the URL of the image description page.
 getDimensionsString ()
 getExtension ()
 Get the file extension, e.g.
 getFullUrl ()
 Return a fully-qualified URL to the file.
 getHandler ()
 Get a MediaHandler instance for this file.
 getHashPath ()
 Get the filename hash component of the directory including trailing slash, e.g.
 getHeight ($page=1)
 Return the height of the image.
 getHistory ($limit=null, $start=null, $end=null, $inc=true)
 Return a fragment of the history of file.
 getImageSize ($fileName)
 Get an image size array like that returned by getImageSize(), or false if it can't be determined.
 getLastError ()
 Get last thumbnailing error.
 getLength ()
 Get the duration of a media file in seconds.
 getLocalRefPath ()
 Get an FS copy or original of this file and return the path.
 getLongDesc ()
 getMediaType ()
 Return the type of the media in the file.
 getMetadata ()
 Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB.
 getMimeType ()
 Returns the mime type of the file.
 getName ()
 Return the name of this file.
 getOriginalTitle ()
 Return the title used to find this file.
 getPath ()
 Return the storage path to the file.
 getRedirected ()
 getRedirectedTitle ()
 getRel ()
 Get the path of the file relative to the public zone root.
 getRepo ()
 Returns the repository.
 getRepoName ()
 Returns the name of the repository.
 getSha1 ()
 Get the SHA-1 base 36 hash of the file.
 getShortDesc ()
 getSize ()
 Return the size of the image file, in bytes Overridden by LocalFile, UnregisteredLocalFile STUB.
 getStorageKey ()
 Get the deletion archive key, "<sha1>.<ext>".
 getStreamHeaders ()
 getThumbDisposition ($thumbName)
 getThumbnails ()
 Get all thumbnail names previously generated for this file STUB Overridden by LocalFile.
 getThumbPath ($suffix=false)
 Get the path of the thumbnail directory, or a particular file if $suffix is specified.
 getThumbRel ($suffix=false)
 Get the path, relative to the thumbnail zone root, of the thumbnail directory or a particular file if $suffix is specified.
 getThumbUrl ($suffix=false)
 Get the URL of the thumbnail directory, or a particular file if $suffix is specified.
 getThumbVirtualUrl ($suffix=false)
 Get the virtual URL for a thumbnail file or directory.
 getTimestamp ()
 Get the 14-character timestamp of the file upload.
 getTitle ()
 Return the associated title object.
 getTranscodedPath ($suffix=false)
 Get the path of the transcoded directory, or a particular file if $suffix is specified.
 getTranscodedUrl ($suffix=false)
 Get the URL of the transcoded directory, or a particular file if $suffix is specified.
 getTransformScript ()
 getUnscaledThumb ($handlerParams=array())
 Get a ThumbnailImage which is the same size as the source.
 getUrl ()
 Return the URL of the file.
 getUrlRel ()
 Get urlencoded path of the file relative to the public zone root.
 getUser ($type= 'text')
 Returns ID or name of user who uploaded the file STUB.
 getViewURL ()
 getVirtualUrl ($suffix=false)
 Get the public zone virtual URL for a current version source file.
 getVisibility ()
 Return the deletion bitfield STUB.
 getWidth ($page=1)
 Return the width of the image.
 getZoneUrl ($zone, $suffix=false)
 Get the URL of the zone directory, or a particular file if $suffix is specified.
 iconThumb ()
 Get a ThumbnailImage representing a file type icon.
 isCacheable ()
 Check if this file object is small and can be cached.
 isDeleted ($field)
 Is this file a "deleted" file in a private archive? STUB.
 isHashed ()
 isLocal ()
 Returns true if the file comes from the local file repository.
 isMissing ()
 isMultipage ()
 Returns 'true' if this file is a type which supports multiple pages, e.g.
 isOld ()
 Returns true if the image is an old version STUB.
 isSafeFile ()
 Determines if this media file is in a format that is unlikely to contain viruses or malicious content.
 isTrustedFile ()
 Returns true if the file is flagged as trusted.
 isVectorized ()
 Return true if the file is vectorized.
 isVisible ()
 Returns true if file exists in the repository and can be included in a page.
 migrateThumbFile ($thumbName)
 Hook into transform() to allow migration of thumbnail files STUB Overridden by LocalFile.
 move ($target)
 Move file to the new title.
 mustRender ()
 Return true if the file is of a type that can't be directly rendered by typical browsers and needs to be re-rasterized.
 nextHistoryLine ()
 Return the history of this file, line by line.
 pageCount ()
 Returns the number of pages of a multipage document, or false for documents which aren't multipage documents.
 publish ($srcPath, $flags=0, array $options=array())
 Move or copy a file to its public location.
 purgeCache ($options=array())
 Purge shared caches such as thumbnails and DB data caching STUB Overridden by LocalFile.
 purgeDescription ()
 Purge the file description page, but don't go after pages using the file.
 purgeEverything ()
 Purge metadata and all affected pages when the file is created, deleted, or majorly updated.
 readOnlyError ()
 recordUpload ($oldver, $desc, $license= '', $copyStatus= '', $source= '', $watch=false, $timestamp=false, User $user=null)
 Record a file upload in the upload log and the image table STUB Overridden by LocalFile.
 redirectedFrom ($from)
 resetHistory ()
 Reset the history pointer to the first element of the history.
 restore ($versions=array(), $unsuppress=false)
 Restore all or specified deleted revisions to the given file.
 thumbName ($params, $flags=0)
 Return the file name of a thumbnail with the specified parameters.
 transform ($params, $flags=0)
 Transform a media file.
 upgradeRow ()
 Upgrade the database row if there is one Called by ImagePage STUB.
 userCan ($field, User $user=null)
 Determine if the current user is allowed to view a particular field of this file, if it's marked as deleted.
 wasDeleted ()
 Was this file ever deleted from the wiki?

Static Public Member Functions

static checkExtensionCompatibility (File $old, $new)
 Checks if file extensions are compatible.
static compare (File $a, File $b)
 Callback for usort() to do file sorts by name.
static getPropsFromPath ($path, $ext=true)
 Get an associative array containing information about a file in the local filesystem.
static normalizeExtension ($ext)
 Normalize a file extension to the common form, and ensure it's clean.
static normalizeTitle ($title, $exception=false)
 Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
static scaleHeight ($srcWidth, $srcHeight, $dstWidth)
 Calculate the height of a thumbnail using the source and destination width.
static sha1Base36 ($path)
 Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.
static splitMime ($mime)
 Split an internet media type into its two components; if not a two-part name, set the minor type to 'unknown'.

Public Attributes

string $extension
string $hashPath
bool $isSafeFile
 $lastError
string $name
string $pageCount
string $path
 $redirected
 $redirectedTitle
FileRepo bool $repo
 Some member variables can be lazy-initialised using __get().
Title $title
string $transformScript
const DELETE_SOURCE = 1
const DELETED_COMMENT = 2
const DELETED_FILE = 1
const DELETED_RESTRICTED = 8
const DELETED_USER = 4
const FOR_PUBLIC = 1
const FOR_THIS_USER = 2
const RAW = 3
const RENDER_FORCE = 2
 Force rendering even if thumbnail already exist and using RENDER_NOW I.e.
const RENDER_NOW = 1
 Force rendering in the current process.
const THUMB_FULL_NAME = 1

Protected Member Functions

 _getIsSafeFile ()
 Uncached accessor.
 assertRepoDefined ()
 Assert that $this->repo is set to a valid FileRepo instance.
 assertTitleDefined ()
 Assert that $this->title is set to a Title.
 getCanRender ()
 Accessor for __get()
 getIsSafeFile ()
 Accessor for __get()
 transformErrorOutput ($thumbPath, $thumbUrl, $params, $flags)
 Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors)

Protected Attributes

bool $canRender
FSFile bool $fsFile
 False if undefined.
MediaHandler $handler
 $redirectTitle
string $repoClass = 'FileRepo'
 Required Repository class type.
string $url

Detailed Description

Implements some public methods and some protected utility functions which are required by multiple child classes.

Contains stub functionality for unimplemented public methods.

Stub functions which should be overridden are marked with STUB. Some more concrete functions are also typically overridden by child classes.

Note that only the repo object knows what its file class is called. You should never name a file class explictly outside of the repo class. Instead use the repo's factory functions to generate file objects, for example:

RepoGroup::singleton()->getLocalRepo()->newFile( $title );

The convenience functions wfLocalFile() and wfFindFile() should be sufficient in most cases.

Definition at line 50 of file File.php.


Constructor & Destructor Documentation

File::__construct ( title,
repo 
)

Call this constructor from child classes.

Both $title and $repo are optional, though some functions may return false or throw exceptions if they are not set. Most subclasses will want to call assertRepoDefined() here.

Parameters:
$titleTitle|string|bool
$repoFileRepo|bool

Reimplemented in LocalFile.

Definition at line 136 of file File.php.


Member Function Documentation

File::__get ( name)

Definition at line 173 of file File.php.

File::_getIsSafeFile ( ) [protected]

Uncached accessor.

Returns:
bool

Definition at line 654 of file File.php.

Alias for canRender()

Returns:
bool

Definition at line 616 of file File.php.

File::assertRepoDefined ( ) [protected]

Assert that $this->repo is set to a valid FileRepo instance.

Exceptions:
MWException

Definition at line 1883 of file File.php.

Referenced by ForeignAPIFile\__construct().

File::assertTitleDefined ( ) [protected]

Assert that $this->title is set to a Title.

Exceptions:
MWException

Definition at line 1893 of file File.php.

Will the thumbnail be animated if one would expect it to be.

Currently used to add a warning to the image description page

Returns:
bool false if the main image is both animated and the thumbnail is not. In all other cases must return true. If image is not renderable whatsoever, should return true.

Definition at line 475 of file File.php.

Checks if the output of transform() for this file is likely to be valid.

If this is false, various user elements will display a placeholder instead.

Currently, this checks if the file is an image format that can be converted to a format supported by all browsers (namely GIF, PNG and JPEG), or if it is an SVG image and SVG conversion is enabled.

Returns:
bool

Definition at line 582 of file File.php.

Referenced by ForeignAPIFile\transform().

static File::checkExtensionCompatibility ( File old,
new 
) [static]

Checks if file extensions are compatible.

Parameters:
$oldFile Old file
string$newNew name
Returns:
bool|null

Definition at line 215 of file File.php.

Referenced by Title\validateFileMoveOperation().

static File::compare ( File a,
File b 
) [static]

Callback for usort() to do file sorts by name.

Parameters:
$aFile
$bFile
Returns:
Integer: result of name comparison

Definition at line 253 of file File.php.

File::convertMetadataVersion ( metadata,
version 
)

get versioned metadata

Parameters:
$metadataMixed Array or String of (serialized) metadata
$versioninteger version number.
Returns:
Array containing metadata, or what was passed to it on fail (unserializing if not array)

Definition at line 515 of file File.php.

File::createThumb ( width,
height = -1 
)

Create a thumbnail of the image having the specified width/height.

The thumbnail will not be created if the width is larger than the image's width. Let the browser do the scaling in this case. The thumbnail is stored on disk and is only computed if the thumbnail file does not exist OR if it is older than the image. Returns the URL.

Keeps aspect ratio of original image. If both width and height are specified, the generated image will be no bigger than width x height, and will also have correct aspect ratio.

Parameters:
$widthInteger: maximum width of the generated thumbnail
$heightInteger: maximum height of the image (optional)
Returns:
string

Definition at line 814 of file File.php.

File::delete ( reason,
suppress = false 
)

Delete all versions of the file.

Moves the files into an archive directory (or deletes them) and removes the database rows.

Cache purging is done; logging is caller's responsibility.

Parameters:
$reasonString
$suppressBoolean: hide content from sysops?
Returns:
bool on success, false on some kind of failure STUB Overridden by LocalFile

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1554 of file File.php.

Returns true if file exists in the repository.

Overridden by LocalFile to avoid unnecessary stat calls.

Returns:
boolean Whether file exists in the repository.

Reimplemented in LocalFile, UploadStashFile, and ForeignAPIFile.

Definition at line 711 of file File.php.

Referenced by getTransformScript().

Returns:
bool

Definition at line 1449 of file File.php.

References readOnlyError().

File::generateThumbName ( name,
params 
)

Generate a thumbnail file name from a name and specified parameters.

Parameters:
string$name
array$paramsParameters which will be passed to MediaHandler::makeParamString
Returns:
string

Definition at line 783 of file File.php.

File::getArchivePath ( suffix = false)

Get the path of the archived file.

Parameters:
bool | string$suffixif not false, the name of an archived file.
Returns:
string

Definition at line 1213 of file File.php.

File::getArchiveRel ( suffix = false)

Get the path of an archived file relative to the public zone root.

Parameters:
bool | string$suffixif not false, the name of an archived thumbnail file
Returns:
string

Definition at line 1151 of file File.php.

File::getArchiveThumbPath ( archiveName,
suffix = false 
)

Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified.

Parameters:
string$archiveNamethe timestamped name of an archived image
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string

Definition at line 1226 of file File.php.

File::getArchiveThumbRel ( archiveName,
suffix = false 
)

Get the path, relative to the thumbnail zone root, for an archived file's thumbs directory or a specific thumb if the $suffix is given.

Parameters:
string$archiveNamethe timestamped name of an archived image
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string

Definition at line 1196 of file File.php.

File::getArchiveThumbUrl ( archiveName,
suffix = false 
)

Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified.

Parameters:
string$archiveNamethe timestamped name of an archived image
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string

Definition at line 1283 of file File.php.

File::getArchiveUrl ( suffix = false)

Get the URL of the archive directory, or a particular file if $suffix is specified.

Parameters:
bool | string$suffixif not false, the name of an archived file
Returns:
string

Definition at line 1263 of file File.php.

Get the public zone virtual URL for an archived version source file.

Parameters:
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string

Definition at line 1359 of file File.php.

Return the bit depth of the file Overridden by LocalFile STUB.

Returns:
int

Reimplemented in LocalFile.

Definition at line 534 of file File.php.

Returns:
string

Definition at line 333 of file File.php.

References getUrl(), and wfExpandUrl().

File::getCanRender ( ) [protected]

Accessor for __get()

Returns:
bool

Definition at line 593 of file File.php.

File::getDescription ( audience = self::FOR_PUBLIC,
User user = null 
)

Get description of file revision STUB.

Parameters:
$audienceInteger: one of: File::FOR_PUBLIC to be displayed to all users File::FOR_THIS_USER to be displayed to the given user File::RAW get the description regardless of permissions
$userUser object to check for, only if FOR_THIS_USER is passed to the $audience parameter
Returns:
string

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1700 of file File.php.

Get the HTML text of the description page, if available.

Parameters:
$langLanguage Optional language to fetch description in
Returns:
string

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1656 of file File.php.

References $key, $res, $wgLang, $wgMemc, Http\get(), getName(), global, and wfDebug().

Get the URL of the image description page.

May return false if it is unknown or not applicable.

Returns:
string

Reimplemented in LocalFile, UploadStashFile, ForeignAPIFile, and ForeignDBFile.

Definition at line 1642 of file File.php.

References getName().

Returns:
string

Definition at line 1827 of file File.php.

Get the file extension, e.g.

"svg"

Returns:
string

Definition at line 275 of file File.php.

Referenced by ForeignAPIFile\getMimeType().

Return a fully-qualified URL to the file.

Upload URL paths _may or may not_ be fully qualified, so we check. Local paths are assumed to belong on $wgServer.

Returns:
String

Reimplemented in UploadStashFile.

Definition at line 326 of file File.php.

Get a MediaHandler instance for this file.

Returns:
MediaHandler|boolean Registered MediaHandler for file's mime type or false if none found

Definition at line 999 of file File.php.

Referenced by pageCount(), and ForeignAPIFile\purgeThumbnails().

Get the filename hash component of the directory including trailing slash, e.g.

f/fa/ If the repository is not hashed, returns an empty string.

Returns:
string

Definition at line 1126 of file File.php.

Referenced by OldLocalFile\getRel(), getRel(), ForeignAPIFile\getThumbPath(), OldLocalFile\getUrlRel(), getUrlRel(), and OldLocalFile\uploadOld().

File::getHeight ( page = 1)

Return the height of the image.

Returns false if the height is unknown or undefined

STUB Overridden by LocalFile, UnregisteredLocalFile

Parameters:
$pageint
Returns:
bool|number False on failure

Reimplemented in LocalFile, ForeignAPIFile, UnregisteredLocalFile, and FakeDimensionFile.

Definition at line 421 of file File.php.

File::getHistory ( limit = null,
start = null,
end = null,
inc = true 
)

Return a fragment of the history of file.

STUB

Parameters:
$limitinteger Limit of rows to return
string$starttimestamp Only revisions older than $start will be returned
string$endtimestamp Only revisions newer than $end will be returned
bool$incInclude the endpoints of the time range
Returns:
array

Reimplemented in LocalFile.

Definition at line 1094 of file File.php.

File::getImageSize ( fileName)

Get an image size array like that returned by getImageSize(), or false if it can't be determined.

Parameters:
string$fileNameThe filename
Returns:
Array

Reimplemented in UnregisteredLocalFile.

Definition at line 1629 of file File.php.

File::getIsSafeFile ( ) [protected]

Accessor for __get()

Returns:
bool

Definition at line 645 of file File.php.

Get last thumbnailing error.

Largely obsolete.

Definition at line 1030 of file File.php.

Get the duration of a media file in seconds.

Returns:
number

Definition at line 442 of file File.php.

Get an FS copy or original of this file and return the path.

Returns false on failure. Callers must not alter the file. Temporary files are cleared automatically.

Returns:
string|bool False on failure

Definition at line 382 of file File.php.

Returns:
string

Definition at line 1803 of file File.php.

Return the type of the media in the file.

Use the value returned by this function with the MEDIATYPE_xxx constants. Overridden by LocalFile, STUB

Returns:
string

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 566 of file File.php.

Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB.

Returns:
bool

Reimplemented in LocalFile, ForeignAPIFile, and UnregisteredLocalFile.

Definition at line 504 of file File.php.

Returns the mime type of the file.

Overridden by LocalFile, UnregisteredLocalFile STUB

Returns:
string

Reimplemented in LocalFile, ForeignAPIFile, and UnregisteredLocalFile.

Definition at line 555 of file File.php.

Return the title used to find this file.

Returns:
Title

Definition at line 298 of file File.php.

Return the storage path to the file.

Note that this does not mean that a file actually exists under that location.

This path depends on whether directory hashing is active or not, i.e. whether the files are all found in the same directory, or in hashed paths like /images/3/3c.

Most callers don't check the return value, but ForeignAPIFile::getPath returns false.

Returns:
string|bool ForeignAPIFile::getPath can return false

Reimplemented in ForeignAPIFile, and FakeDimensionFile.

Definition at line 367 of file File.php.

Referenced by SpecialUploadStash\outputLocalFile(), and RefreshFileHeaders\updateFileHeaders().

static File::getPropsFromPath ( path,
ext = true 
) [static]

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

Parameters:
string$pathabsolute local filesystem path
$extMixed: the file extension, or true to extract it from the filename. Set it to false to ignore the extension.
Returns:
array
Deprecated:
since 1.19

Definition at line 1761 of file File.php.

Returns:

Definition at line 1839 of file File.php.

Returns:
Title|null

Definition at line 1846 of file File.php.

Get the path of the file relative to the public zone root.

This function is overriden in OldLocalFile to be like getArchiveRel().

Returns:
string

Reimplemented in OldLocalFile.

Definition at line 1140 of file File.php.

References getHashPath(), and getName().

Returns the repository.

Returns:
FileRepo|bool

Definition at line 1479 of file File.php.

Referenced by SpecialUploadStash\outputLocalFile(), and RefreshFileHeaders\updateFileHeaders().

Returns the name of the repository.

Returns:
string

Definition at line 1470 of file File.php.

Get the SHA-1 base 36 hash of the file.

Returns:
string

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1719 of file File.php.

Returns:
string

Definition at line 1815 of file File.php.

Return the size of the image file, in bytes Overridden by LocalFile, UnregisteredLocalFile STUB.

Returns:
bool

Reimplemented in LocalFile, ForeignAPIFile, and UnregisteredLocalFile.

Definition at line 544 of file File.php.

Referenced by SpecialUploadStash\outputLocalFile().

Get the deletion archive key, "<sha1>.<ext>".

Returns:
string

Definition at line 1729 of file File.php.

Returns:
Array HTTP header name/value map to use for HEAD/GET request responses

Definition at line 1791 of file File.php.

File::getThumbDisposition ( thumbName)
Parameters:
string$thumbNameThumbnail name
Returns:
string Content-Disposition header value

Definition at line 978 of file File.php.

Get all thumbnail names previously generated for this file STUB Overridden by LocalFile.

Returns:
array

Reimplemented in ForeignAPIFile.

Definition at line 1040 of file File.php.

References array().

File::getThumbPath ( suffix = false)

Get the path of the thumbnail directory, or a particular file if $suffix is specified.

Parameters:
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string

Reimplemented in UploadStashFile, and ForeignAPIFile.

Definition at line 1239 of file File.php.

File::getThumbRel ( suffix = false)

Get the path, relative to the thumbnail zone root, of the thumbnail directory or a particular file if $suffix is specified.

Parameters:
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string

Definition at line 1169 of file File.php.

File::getThumbUrl ( suffix = false)

Get the URL of the thumbnail directory, or a particular file if $suffix is specified.

Parameters:
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string path

Reimplemented in UploadStashFile.

Definition at line 1321 of file File.php.

Get the virtual URL for a thumbnail file or directory.

Parameters:
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string

Definition at line 1377 of file File.php.

Get the 14-character timestamp of the file upload.

Returns:
string|bool TS_MW timestamp or false on failure

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1709 of file File.php.

Return the associated title object.

Returns:
Title

Definition at line 289 of file File.php.

File::getTranscodedPath ( suffix = false)

Get the path of the transcoded directory, or a particular file if $suffix is specified.

Parameters:
bool | string$suffixif not false, the name of a media file
Returns:
string

Definition at line 1251 of file File.php.

File::getTranscodedUrl ( suffix = false)

Get the URL of the transcoded directory, or a particular file if $suffix is specified.

Parameters:
bool | string$suffixif not false, the name of a media file
Returns:
string path

Definition at line 1332 of file File.php.

Returns:
string

Definition at line 728 of file File.php.

References exists().

File::getUnscaledThumb ( handlerParams = array())

Get a ThumbnailImage which is the same size as the source.

Parameters:
$handlerParamsarray
Returns:
string

Definition at line 748 of file File.php.

Return the URL of the file.

Returns:
string

Reimplemented in UploadStashFile, and ForeignAPIFile.

Definition at line 310 of file File.php.

Referenced by getCanonicalUrl(), and getViewURL().

Get urlencoded path of the file relative to the public zone root.

This function is overriden in OldLocalFile to be like getArchiveUrl().

Returns:
string

Reimplemented in OldLocalFile.

Definition at line 1183 of file File.php.

References getHashPath(), and getName().

File::getUser ( type = 'text')

Returns ID or name of user who uploaded the file STUB.

Parameters:
string$type'text' or 'id'
Returns:
string|int

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 433 of file File.php.

Returns:
string

Definition at line 340 of file File.php.

References getUrl(), and wfExpandUrl().

File::getVirtualUrl ( suffix = false)

Get the public zone virtual URL for a current version source file.

Parameters:
bool | string$suffixif not false, the name of a thumbnail file
Returns:
string

Definition at line 1343 of file File.php.

Return the deletion bitfield STUB.

Returns:
int

Reimplemented in OldLocalFile.

Definition at line 1510 of file File.php.

File::getWidth ( page = 1)

Return the width of the image.

Returns false if the width is unknown or undefined.

STUB Overridden by LocalFile, UnregisteredLocalFile

Parameters:
$pageint
Returns:
number

Reimplemented in LocalFile, ForeignAPIFile, UnregisteredLocalFile, and FakeDimensionFile.

Definition at line 406 of file File.php.

File::getZoneUrl ( zone,
suffix = false 
)

Get the URL of the zone directory, or a particular file if $suffix is specified.

Parameters:
string$zonename of requested zone
bool | string$suffixif not false, the name of a file in zone
Returns:
string path

Definition at line 1304 of file File.php.

Get a ThumbnailImage representing a file type icon.

Returns:
ThumbnailImage

Definition at line 1011 of file File.php.

Check if this file object is small and can be cached.

Returns:
boolean

Reimplemented in LocalFile.

Definition at line 1875 of file File.php.

File::isDeleted ( field)

Is this file a "deleted" file in a private archive? STUB.

Parameters:
integer$fieldone of DELETED_* bitfield constants
Returns:
bool

Reimplemented in OldLocalFile.

Definition at line 1501 of file File.php.

Returns:
bool

Definition at line 1389 of file File.php.

Returns true if the file comes from the local file repository.

Returns:
bool

Definition at line 1461 of file File.php.

Returns:
bool

Reimplemented in LocalFile.

Definition at line 1867 of file File.php.

Returns 'true' if this file is a type which supports multiple pages, e.g.

DJVU or PDF. Note that this may be true even if the file in question only has a single page.

Returns:
Bool

Definition at line 1583 of file File.php.

Returns true if the image is an old version STUB.

Returns:
bool

Reimplemented in OldLocalFile.

Definition at line 1489 of file File.php.

Determines if this media file is in a format that is unlikely to contain viruses or malicious content.

It uses the global $wgTrustedMediaFormats list to determine if the file is safe.

This is used to show a warning on the description page of non-safe files. It may also be used to disallow direct [[media:...]] links to such files.

Note that this function will always return true if allowInlineDisplay() or isTrustedFile() is true for this file.

Returns:
bool

Definition at line 633 of file File.php.

Returns true if the file is flagged as trusted.

Files flagged that way can be linked to directly, even if that is not allowed for this type of file normally.

This is a dummy function right now and always returns false. It could be implemented to extract a flag from the database. The trusted flag could be set on upload, if the user has sufficient privileges, to bypass script- and html-filters. It may even be coupled with cryptographics signatures or such.

Returns:
bool

Definition at line 698 of file File.php.

Return true if the file is vectorized.

Returns:
bool

Definition at line 456 of file File.php.

Returns true if file exists in the repository and can be included in a page.

It would be unsafe to include private images, making public thumbnails inadvertently

Returns:
boolean Whether file exists in the repository and is includable.

Reimplemented in OldLocalFile.

Definition at line 721 of file File.php.

File::migrateThumbFile ( thumbName)

Hook into transform() to allow migration of thumbnail files STUB Overridden by LocalFile.

Reimplemented in LocalFile.

Definition at line 992 of file File.php.

File::move ( target)

Move file to the new title.

Move current, old version and all thumbnails to the new filename. Old file is deleted.

Cache purging is done; checks for validity and logging are caller's responsibility

Parameters:
$targetTitle New file name
Returns:
FileRepoStatus object.

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1536 of file File.php.

Return true if the file is of a type that can't be directly rendered by typical browsers and needs to be re-rasterized.

This returns true for everything but the bitmap types supported by all browsers, i.e. JPEG; GIF and PNG. It will also return true for any non-image formats.

Returns:
bool

Reimplemented in FakeDimensionFile.

Definition at line 607 of file File.php.

Return the history of this file, line by line.

Starts with current version, then old versions. Should return an object similar to an image/oldimage database row.

STUB Overridden in LocalFile

Returns:
bool

Reimplemented in LocalFile.

Definition at line 1107 of file File.php.

static File::normalizeExtension ( ext) [static]

Normalize a file extension to the common form, and ensure it's clean.

Extensions with non-alphanumeric characters will be discarded.

Parameters:
string$ext(without the .)
Returns:
string

Definition at line 190 of file File.php.

Referenced by LocalRepo\hiddenFileHasKey().

static File::normalizeTitle ( title,
exception = false 
) [static]

Given a string or Title object return either a valid Title object with namespace NS_FILE or null.

Parameters:
$titleTitle|string
string | bool$exceptionUse 'exception' to throw an error on bad titles
Exceptions:
MWException
Returns:
Title|null

Definition at line 153 of file File.php.

Referenced by LocalRepo\checkRedirect().

Returns the number of pages of a multipage document, or false for documents which aren't multipage documents.

Returns:
bool|int

Definition at line 1593 of file File.php.

References getHandler().

File::publish ( srcPath,
flags = 0,
array options = array() 
)

Move or copy a file to its public location.

If a file exists at the destination, move it to an archive. Returns a FileRepoStatus object with the archive name in the "value" member on success.

The archive name should be passed through to recordUpload for database registration.

Options to $options include:

  • headers : name/value map of HTTP headers to use in response to GET/HEAD requests
Parameters:
string$srcPathlocal filesystem path to the source image
$flagsInteger: a bitwise combination of: File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
array$optionsOptional additional parameters
Returns:
FileRepoStatus object. On success, the value member contains the archive name, or an empty string if it was a new file.

STUB Overridden by LocalFile

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1442 of file File.php.

File::purgeCache ( options = array())

Purge shared caches such as thumbnails and DB data caching STUB Overridden by LocalFile.

Parameters:
array$optionsOptions, which include: 'forThumbRefresh' : The purging is only to refresh thumbnails

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1051 of file File.php.

Purge the file description page, but don't go after pages using the file.

Use when modifying file history but not the current data.

Definition at line 1058 of file File.php.

Purge metadata and all affected pages when the file is created, deleted, or majorly updated.

Definition at line 1070 of file File.php.

File::recordUpload ( oldver,
desc,
license = '',
copyStatus = '',
source = '',
watch = false,
timestamp = false,
User user = null 
)

Record a file upload in the upload log and the image table STUB Overridden by LocalFile.

Parameters:
$oldver
$desc
$licensestring
$copyStatusstring
$sourcestring
$watchbool
$timestampstring|bool
$userUser object or null to use $wgUser
Returns:
bool
Exceptions:
MWException

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1416 of file File.php.

File::redirectedFrom ( from)
Parameters:
$from
Returns:
void

Definition at line 1860 of file File.php.

Reset the history pointer to the first element of the history.

Always call this function after using nextHistoryLine() to free db resources STUB Overridden in LocalFile.

Reimplemented in LocalFile.

Definition at line 1117 of file File.php.

File::restore ( versions = array(),
unsuppress = false 
)

Restore all or specified deleted revisions to the given file.

Permissions and logging are left to the caller.

May throw database exceptions on error.

Parameters:
array$versionsset of record ids of deleted items to restore, or empty to restore all revisions.
bool$unsuppressremove restrictions on content upon restoration?
Returns:
int|bool the number of file revisions restored if successful, or false on failure STUB Overridden by LocalFile

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1572 of file File.php.

static File::scaleHeight ( srcWidth,
srcHeight,
dstWidth 
) [static]

Calculate the height of a thumbnail using the source and destination width.

Parameters:
$srcWidth
$srcHeight
$dstWidth
Returns:
int

Definition at line 1613 of file File.php.

Referenced by SvgHandler\normaliseParams(), ImageHandler\normaliseParams(), and ImageHandler\validateThumbParams().

static File::sha1Base36 ( 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:
$pathstring
Returns:
bool|string False on failure
Deprecated:
since 1.19

Definition at line 1781 of file File.php.

static File::splitMime ( mime) [static]

Split an internet media type into its two components; if not a two-part name, set the minor type to 'unknown'.

Parameters:
string$mime"text/html" etc
Returns:
array ("text", "html") etc

Definition at line 237 of file File.php.

Referenced by MIMEsearchPage\execute(), FSFile\getProps(), ApiQueryAllImages\run(), and OldLocalFile\upgradeRow().

File::thumbName ( params,
flags = 0 
)

Return the file name of a thumbnail with the specified parameters.

Use File::THUMB_FULL_NAME to always get a name like "<params>-<source>". Otherwise, the format may be "<params>-<source>" or "<params>-thumbnail.<ext>".

Parameters:
array$paramshandler-specific parameters
$flagsinteger Bitfield that supports THUMB_* constants
Returns:
string

Reimplemented in UploadStashFile.

Definition at line 768 of file File.php.

File::transform ( params,
flags = 0 
)

Transform a media file.

Parameters:
array$paramsan associative array of handler-specific parameters. Typical keys are width, height and page.
$flagsInteger: a bitfield, may contain self::RENDER_NOW to force rendering
Returns:
MediaTransformOutput|bool False on failure

Reimplemented in ForeignAPIFile.

Definition at line 855 of file File.php.

File::transformErrorOutput ( thumbPath,
thumbUrl,
params,
flags 
) [protected]

Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors)

Parameters:
string$thumbPathThumbnail storage path
string$thumbUrlThumbnail URL
$paramsArray
$flagsinteger
Returns:
MediaTransformOutput

Definition at line 835 of file File.php.

Upgrade the database row if there is one Called by ImagePage STUB.

Reimplemented in LocalFile, and OldLocalFile.

Definition at line 228 of file File.php.

File::userCan ( field,
User user = null 
)

Determine if the current user is allowed to view a particular field of this file, if it's marked as deleted.

STUB

Parameters:
$fieldInteger
$userUser object to check, or null to use $wgUser
Returns:
Boolean

Reimplemented in OldLocalFile.

Definition at line 1747 of file File.php.

Was this file ever deleted from the wiki?

Returns:
bool

Definition at line 1519 of file File.php.


Member Data Documentation

bool File::$canRender [protected]

Definition at line 120 of file File.php.

string File::$extension

Definition at line 114 of file File.php.

FSFile bool File::$fsFile [protected]

False if undefined.

Definition at line 106 of file File.php.

MediaHandler File::$handler [protected]

Reimplemented in UnregisteredLocalFile.

Definition at line 110 of file File.php.

Referenced by ForeignAPIFile\purgeThumbnails().

string File::$hashPath

Definition at line 114 of file File.php.

bool File::$isSafeFile

Definition at line 120 of file File.php.

File::$lastError

Definition at line 102 of file File.php.

string File::$name

Definition at line 114 of file File.php.

Referenced by OldLocalFile\loadExtraFromDB().

string File::$pageCount

Definition at line 114 of file File.php.

string File::$path

Reimplemented in UnregisteredLocalFile.

Definition at line 114 of file File.php.

Referenced by ForeignAPIFile\getThumbPath().

File::$redirected

Definition at line 102 of file File.php.

File::$redirectedTitle

Definition at line 102 of file File.php.

File::$redirectTitle [protected]

Definition at line 116 of file File.php.

FileRepo bool File::$repo

Some member variables can be lazy-initialised using __get().

The initialisation function for these variables is always a function named like getVar(), where Var is the variable name with upper-case first letter.

The following variables are initialised in this way in this base class: name, extension, handler, path, canRender, isSafeFile, transformScript, hashPath, pageCount, url

Code within this class should generally use the accessor function directly, since __get() isn't re-entrant and therefore causes bugs that depend on initialisation order. The following member variables are not lazy-initialised

Reimplemented in LocalFile.

Definition at line 96 of file File.php.

Referenced by ForeignAPIFile\__construct(), and ForeignAPIFile\newFromTitle().

string File::$repoClass = 'FileRepo' [protected]

Required Repository class type.

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 124 of file File.php.

string File::$transformScript

Definition at line 114 of file File.php.

string File::$url [protected]

Reimplemented in UploadStashFile.

Definition at line 114 of file File.php.

Referenced by ForeignAPIFile\purgeDescriptionPage().

Definition at line 65 of file File.php.

Referenced by UploadBase\performUpload(), and OldLocalFile\uploadOld().

const File::FOR_PUBLIC = 1

Definition at line 68 of file File.php.

Definition at line 69 of file File.php.

Referenced by ImageHistoryList\imageHistoryLine().

const File::RAW = 3

Definition at line 70 of file File.php.

const File::RENDER_FORCE = 2

Force rendering even if thumbnail already exist and using RENDER_NOW I.e.

you have to pass both flags: File::RENDER_NOW | File::RENDER_FORCE

Definition at line 63 of file File.php.

Referenced by ExifRotationTest\testRotationRendering(), and ExifRotationTest\testRotationRenderingNoAutoRotate().

Definition at line 73 of file File.php.

Referenced by wfStreamThumb().


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