MediaWiki REL1_33
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:

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, $user=null)
 Delete all versions of the file.
 
 exists ()
 Returns true if file exists in the repository.
 
 formatMetadata ( $context=false)
 
 generateAndSaveThumb ( $tmpFile, $transformParams, $flags)
 Generates a thumbnail according to the given parameters and saves it to storage.
 
 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.
 
 getAvailableLanguages ()
 Gives a (possibly empty) list of languages to render the file in.
 
 getBitDepth ()
 Return the bit depth of the file Overridden by LocalFile STUB.
 
 getCanonicalUrl ()
 
 getCommonMetaArray ()
 Like getMetadata but returns a handler independent array of common values.
 
 getContentHeaders ()
 
 getDefaultRenderLanguage ()
 In files that support multiple language, what is the default language to use if none specified.
 
 getDescription ( $audience=self::FOR_PUBLIC, User $user=null)
 Get description of file revision STUB.
 
 getDescriptionShortUrl ()
 Get short description URL for a files based on the page ID.
 
 getDescriptionText (Language $lang=null)
 Get the HTML text of the description page, if available.
 
 getDescriptionTouched ()
 Returns the timestamp (in TS_MW format) of the last change of the description page.
 
 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 ( $filePath)
 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 ()
 
 getMatchedLanguage ( $userPreferredLanguage)
 Get the language code from the available languages for this file that matches the language requested by the user.
 
 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>".
 
 getThumbDisposition ( $thumbName, $dispositionType='inline')
 
 getThumbnailBucket ( $desiredWidth, $page=1)
 Return the smallest bucket from $wgThumbnailBuckets which is at least $wgThumbnailMinimumBucketDistance larger than $desiredWidth.
 
 getThumbnails ()
 Get all thumbnail names previously generated for this file STUB Overridden by LocalFile.
 
 getThumbnailSource ( $params)
 Returns the most appropriate source image for the thumbnail, given a target thumbnail size.
 
 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=[])
 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.
 
 isExpensiveToThumbnail ()
 True if creating thumbnails from the file is large or otherwise resource-intensive.
 
 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.
 
 isTransformedLocally ()
 Whether the thumbnails created on the same server as this code is running.
 
 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.
 
 load ( $flags=0)
 Load any lazy-loaded file object fields from source.
 
 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 ( $src, $flags=0, array $options=[])
 Move or copy a file to its public location.
 
 purgeCache ( $options=[])
 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=[], $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 normalizeExtension ( $extension)
 Normalize a file extension to the common form, making it lowercase and checking some synonyms, 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 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

FileRepo LocalRepo ForeignAPIRepo bool $repo
 Some member variables can be lazy-initialised using __get().
 
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
 
- Public Attributes inherited from IDBAccessObject
const READ_LOCKING = self::READ_LATEST | 2
 Constants for object loading bitfield flags (higher => higher QoS)
 
const READ_NONE = -1
 

Protected Member Functions

 assertRepoDefined ()
 Assert that $this->repo is set to a valid FileRepo instance.
 
 assertTitleDefined ()
 Assert that $this->title is set to a Title.
 
 generateBucketsIfNeeded ( $params, $flags=0)
 Generates chained bucketed thumbnails if needed.
 
 getBucketThumbName ( $bucket)
 Returns the name of the thumb for a given bucket.
 
 getBucketThumbPath ( $bucket)
 Returns the repo path of the thumb for a given bucket.
 
 getCanRender ()
 Accessor for __get()
 
 getIsSafeFile ()
 Accessor for __get()
 
 getIsSafeFileUncached ()
 Uncached accessor.
 
 makeTransformTmpFile ( $thumbPath)
 Creates a temp FS file with the same extension and the thumbnail.
 
 transformErrorOutput ( $thumbPath, $thumbUrl, $params, $flags)
 Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors)
 

Protected Attributes

bool $canRender
 Whether the output of transform() for this file is likely to be valid.
 
string $extension
 File extension.
 
FSFile bool $fsFile
 False if undefined.
 
MediaHandler $handler
 
string $hashPath
 Relative path including trailing slash.
 
bool $isSafeFile
 Whether this media file is in a format that is unlikely to contain viruses or malicious content.
 
string $lastError
 Text of last error.
 
string $name
 The name of a file from its title object.
 
string false $pageCount
 Number of pages of a multipage document, or false for documents which aren't multipage documents.
 
string $path
 The storage path corresponding to one of the zones.
 
string $redirected
 Main part of the title, with underscores (Title::getDBkey)
 
Title $redirectedTitle
 
Title $redirectTitle
 
string $repoClass = FileRepo::class
 Required Repository class type.
 
Title string bool $title
 
array $tmpBucketedThumbCache = []
 Cache of tmp filepaths pointing to generated bucket thumbnails, keyed by width.
 
string $transformScript
 URL of transformscript (for example thumb.php)
 
string $url
 The URL corresponding to one of the four basic zones.
 

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 52 of file File.php.

Constructor & Destructor Documentation

◆ __construct()

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
Title | string | bool$title
FileRepo | bool$repo

Reimplemented in FakeDimensionFile, and LocalFile.

Definition at line 167 of file File.php.

References $repo, $title, normalizeTitle(), and title.

Member Function Documentation

◆ __get()

File::__get ( $name)

Definition at line 206 of file File.php.

References and().

◆ allowInlineDisplay()

File::allowInlineDisplay ( )

Alias for canRender()

Returns
bool

Definition at line 784 of file File.php.

References canRender().

Referenced by canAnimateThumbIfAppropriate(), and getIsSafeFileUncached().

◆ assertRepoDefined()

◆ assertTitleDefined()

File::assertTitleDefined ( )
protected

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

Exceptions
MWException

Definition at line 2281 of file File.php.

References title.

Referenced by LocalFile\__construct().

◆ canAnimateThumbIfAppropriate()

File::canAnimateThumbIfAppropriate ( )

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 630 of file File.php.

References $handler, allowInlineDisplay(), MediaHandler\canAnimateThumbnail(), getHandler(), and MediaHandler\isAnimatedImage().

◆ canRender()

File::canRender ( )

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 749 of file File.php.

References $canRender, and(), canRender(), exists(), getHandler(), and handler.

Referenced by allowInlineDisplay(), canRender(), getCanRender(), getViewURL(), transform(), and ForeignAPIFile\transform().

◆ checkExtensionCompatibility()

static File::checkExtensionCompatibility ( File $old,
$new )
static

Checks if file extensions are compatible.

Parameters
File$oldOld file
string$newNew name
Returns
bool|null

Definition at line 250 of file File.php.

References $mimeMagic, and(), getMimeType(), and normalizeExtension().

Referenced by MovePage\isValidFileMove().

◆ compare()

static File::compare ( File $a,
File $b )
static

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

Parameters
File$a
File$b
Returns
int Result of name comparison

Definition at line 289 of file File.php.

References and().

◆ convertMetadataVersion()

File::convertMetadataVersion ( $metadata,
$version )

get versioned metadata

Parameters
array | string$metadataArray or string of (serialized) metadata
int$versionVersion number.
Returns
array Array containing metadata, or what was passed to it on fail (unserializing if not array)

Definition at line 682 of file File.php.

References $handler, and(), MediaHandler\convertMetadataVersion(), getHandler(), and unserialize().

◆ createThumb()

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
int$widthMaximum width of the generated thumbnail
int$heightMaximum height of the image (optional)
Returns
string

Definition at line 1007 of file File.php.

References $params, and transform().

Referenced by getViewURL().

◆ delete()

File::delete ( $reason,
$suppress = false,
$user = null )

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
string$reason
bool$suppressHide content from sysops?
User | null$user
Returns
Status STUB Overridden by LocalFile

Reimplemented in ForeignDBFile, and LocalFile.

Definition at line 1942 of file File.php.

References readOnlyError().

◆ exists()

File::exists ( )

Returns true if file exists in the repository.

Overridden by LocalFile to avoid unnecessary stat calls.

Returns
bool Whether file exists in the repository.

Reimplemented in ForeignAPIFile, LocalFile, OldLocalFile, and UploadStashFile.

Definition at line 892 of file File.php.

References getPath().

Referenced by canRender(), FileDeleteForm\haveDeletableFile(), isVisible(), and OutputPage\setFileVersion().

◆ formatMetadata()

File::formatMetadata ( $context = false)
Parameters
bool | IContextSource$contextContext to use (optional)
Returns
bool

Definition at line 1835 of file File.php.

References $context, and getHandler().

◆ generateAndSaveThumb()

File::generateAndSaveThumb ( $tmpFile,
$transformParams,
$flags )

Generates a thumbnail according to the given parameters and saves it to storage.

Parameters
TempFSFile$tmpFileTemporary file where the rendered thumbnail will be saved
array$transformParams
int$flags
Returns
bool|MediaTransformOutput

Definition at line 1133 of file File.php.

References $handler, $starttime, $wgIgnoreImageErrors, and(), MediaHandler\doTransform(), generateBucketsIfNeeded(), getHandler(), getThumbDisposition(), getThumbPath(), getThumbUrl(), MediaHandler\getTransform(), MediaHandler\normaliseParams(), MediaHandler\supportsBucketing(), thumbName(), and transformErrorOutput().

Referenced by generateBucketsIfNeeded(), and transform().

◆ generateBucketsIfNeeded()

File::generateBucketsIfNeeded ( $params,
$flags = 0 )
protected

Generates chained bucketed thumbnails if needed.

Parameters
array$params
int$flags
Returns
bool Whether at least one bucket was generated

Definition at line 1200 of file File.php.

References $params, $starttime, and(), generateAndSaveThumb(), getBucketThumbPath(), getHandler(), getThumbnailBucket(), and makeTransformTmpFile().

Referenced by generateAndSaveThumb().

◆ generateThumbName()

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|null

Definition at line 968 of file File.php.

References $extension, $name, $params, and(), getExtension(), getHandler(), getMimeType(), getSha1(), and list.

Referenced by thumbName(), and UploadStashFile\thumbName().

◆ getArchivePath()

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 1599 of file File.php.

References assertRepoDefined(), and getArchiveRel().

◆ getArchiveRel()

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 1539 of file File.php.

References $path, and(), and getHashPath().

Referenced by getArchivePath(), getArchiveThumbRel(), OldLocalFile\getRel(), OldLocalFile\getUrlRel(), LocalFile\publishTo(), and OldLocalFile\uploadOld().

◆ getArchiveThumbPath()

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 1612 of file File.php.

References assertRepoDefined(), and getArchiveThumbRel().

Referenced by LocalFile\getThumbnails().

◆ getArchiveThumbRel()

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 1584 of file File.php.

References $path, and getArchiveRel().

Referenced by getArchiveThumbPath().

◆ getArchiveThumbUrl()

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 1669 of file File.php.

References $ext, $path, and(), assertRepoDefined(), getExtension(), and getHashPath().

Referenced by LocalFile\purgeOldThumbnails().

◆ getArchiveUrl()

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 1649 of file File.php.

References $ext, $path, and(), assertRepoDefined(), getExtension(), and getHashPath().

Referenced by LocalFile\delete(), and LocalFile\deleteOld().

◆ getArchiveVirtualUrl()

File::getArchiveVirtualUrl ( $suffix = false)

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 1741 of file File.php.

References $path, and(), assertRepoDefined(), and getHashPath().

◆ getAvailableLanguages()

File::getAvailableLanguages ( )

Gives a (possibly empty) list of languages to render the file in.

If the file doesn't have translations, or if the file format does not support that sort of thing, returns an empty array.

Returns
string[]
Since
1.23

Definition at line 576 of file File.php.

References $handler, MediaHandler\getAvailableLanguages(), and getHandler().

◆ getBitDepth()

File::getBitDepth ( )

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

Returns
int

Reimplemented in LocalFile, and UnregisteredLocalFile.

Definition at line 701 of file File.php.

◆ getBucketThumbName()

File::getBucketThumbName ( $bucket)
protected

Returns the name of the thumb for a given bucket.

Parameters
int$bucket
Returns
string

Definition at line 1335 of file File.php.

References thumbName().

Referenced by getBucketThumbPath().

◆ getBucketThumbPath()

File::getBucketThumbPath ( $bucket)
protected

Returns the repo path of the thumb for a given bucket.

Parameters
int$bucket
Returns
string

Definition at line 1325 of file File.php.

References getBucketThumbName(), and getThumbPath().

Referenced by generateBucketsIfNeeded(), and getThumbnailSource().

◆ getCanonicalUrl()

File::getCanonicalUrl ( )
Returns
string

Definition at line 383 of file File.php.

References getUrl(), PROTO_CANONICAL, and wfExpandUrl().

◆ getCanRender()

File::getCanRender ( )
protected

Accessor for __get()

Returns
bool

Definition at line 761 of file File.php.

References canRender().

◆ getCommonMetaArray()

File::getCommonMetaArray ( )

Like getMetadata but returns a handler independent array of common values.

See also
MediaHandler::getCommonMetaArray()
Returns
array|bool Array or false if not supported
Since
1.23

Definition at line 664 of file File.php.

References $handler, MediaHandler\getCommonMetaArray(), and getHandler().

◆ getContentHeaders()

File::getContentHeaders ( )
Returns
string[] HTTP header name/value map to use for HEAD/GET request responses
Since
1.30

Definition at line 2167 of file File.php.

References $handler, and(), MediaHandler\getContentHeaders(), getHandler(), and getMetadata().

◆ getDefaultRenderLanguage()

File::getDefaultRenderLanguage ( )

In files that support multiple language, what is the default language to use if none specified.

Returns
string|null Lang code, or null if filetype doesn't support multiple languages.
Since
1.23

Definition at line 611 of file File.php.

References $handler, MediaHandler\getDefaultRenderLanguage(), and getHandler().

◆ getDescription()

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

Get description of file revision STUB.

Parameters
int$audienceOne 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
User | null$userUser object to check for, only if FOR_THIS_USER is passed to the $audience parameter
Returns
null|string

Reimplemented in ForeignAPIFile, and LocalFile.

Definition at line 2098 of file File.php.

◆ getDescriptionShortUrl()

File::getDescriptionShortUrl ( )

Get short description URL for a files based on the page ID.

Returns
string|null
Since
1.27

Reimplemented in ForeignAPIFile, ForeignDBFile, and LocalFile.

Definition at line 365 of file File.php.

◆ getDescriptionText()

File::getDescriptionText ( Language $lang = null)

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

Parameters
Language | null$langOptional language to fetch description in
Returns
string|false

Reimplemented in ForeignDBFile, and LocalFile.

Definition at line 2049 of file File.php.

References $cache, $fname, $lang, $res, $wgLang, and(), array(), Http\get(), getName(), and wfDebug().

◆ getDescriptionTouched()

File::getDescriptionTouched ( )

Returns the timestamp (in TS_MW format) of the last change of the description page.

Returns false if the file does not have a description page, or retrieving the timestamp would be expensive.

Since
1.25
Returns
string|bool

Reimplemented in LocalFile.

Definition at line 2120 of file File.php.

◆ getDescriptionUrl()

File::getDescriptionUrl ( )

Get the URL of the image description page.

May return false if it is unknown or not applicable.

Returns
string

Reimplemented in ForeignAPIFile, ForeignDBFile, LocalFile, and UploadStashFile.

Definition at line 2035 of file File.php.

References getName().

Referenced by ForeignDBFile\getDescriptionUrl(), and transform().

◆ getDimensionsString()

File::getDimensionsString ( )
Returns
string

Definition at line 2213 of file File.php.

References $handler, MediaHandler\getDimensionsString(), and getHandler().

◆ getExtension()

File::getExtension ( )

Get the file extension, e.g.

"svg"

Returns
string

Definition at line 312 of file File.php.

References $extension, and(), getName(), and normalizeExtension().

Referenced by generateThumbName(), getArchiveThumbUrl(), getArchiveUrl(), ForeignAPIFile\getMimeType(), getStorageKey(), getThumbDisposition(), getUrl(), getZoneUrl(), and iconThumb().

◆ getFullUrl()

File::getFullUrl ( )

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 376 of file File.php.

References getUrl(), PROTO_RELATIVE, and wfExpandUrl().

◆ getHandler()

◆ getHashPath()

File::getHashPath ( )

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 1513 of file File.php.

References $hashPath, and(), assertRepoDefined(), and getName().

Referenced by getArchiveRel(), getArchiveThumbUrl(), getArchiveUrl(), getArchiveVirtualUrl(), getRel(), ForeignAPIFile\getThumbPath(), and getUrlRel().

◆ getHeight()

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
int$page
Returns
bool|int False on failure

Reimplemented in ForeignAPIFile, LocalFile, UnregisteredLocalFile, and FakeDimensionFile.

Definition at line 478 of file File.php.

Referenced by getThumbnailSource().

◆ getHistory()

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

Return a fragment of the history of file.

STUB

Parameters
int | null$limitLimit of rows to return
string | int | null$startOnly revisions older than $start will be returned
string | int | null$endOnly revisions newer than $end will be returned
bool$incInclude the endpoints of the time range
Returns
File[]

Reimplemented in LocalFile.

Definition at line 1480 of file File.php.

◆ getImageSize()

File::getImageSize ( $filePath)

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

Loads the image size directly from the file ignoring caches.

Note
Use getWidth()/getHeight() instead of this method unless you have a a good reason. This method skips all caches.
Parameters
string$filePathThe path to the file (e.g. From getLocalRefPath() )
Returns
array|false The width, followed by height, with optionally more things after

Reimplemented in UnregisteredLocalFile.

Definition at line 2021 of file File.php.

References getHandler().

◆ getIsSafeFile()

File::getIsSafeFile ( )
protected

Accessor for __get()

Returns
bool

Definition at line 814 of file File.php.

References isSafeFile().

◆ getIsSafeFileUncached()

File::getIsSafeFileUncached ( )
protected

Uncached accessor.

Returns
bool

Definition at line 823 of file File.php.

References $type, $wgTrustedMediaFormats, allowInlineDisplay(), and(), getMediaType(), getMimeType(), isTrustedFile(), MEDIATYPE_UNKNOWN, and type.

Referenced by isSafeFile().

◆ getLastError()

File::getLastError ( )

Get last thumbnailing error.

Largely obsolete.

Returns
string

Definition at line 1414 of file File.php.

References $lastError.

◆ getLength()

File::getLength ( )

Get the duration of a media file in seconds.

Returns
float|int

Definition at line 542 of file File.php.

References $handler, getHandler(), and MediaHandler\getLength().

◆ getLocalRefPath()

File::getLocalRefPath ( )

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 434 of file File.php.

References $starttime, and(), assertRepoDefined(), and getPath().

Referenced by UnregisteredLocalFile\getBitDepth(), UnregisteredLocalFile\getImageSize(), UnregisteredLocalFile\getMetadata(), UnregisteredLocalFile\getMimeType(), and getThumbnailSource().

◆ getLongDesc()

File::getLongDesc ( )
Returns
string

Definition at line 2189 of file File.php.

References $handler, MediaHandler\getGeneralLongDesc(), getHandler(), and MediaHandler\getLongDesc().

◆ getMatchedLanguage()

File::getMatchedLanguage ( $userPreferredLanguage)

Get the language code from the available languages for this file that matches the language requested by the user.

Parameters
string$userPreferredLanguage
Returns
string|null

Definition at line 592 of file File.php.

References $handler, MediaHandler\getAvailableLanguages(), getHandler(), and MediaHandler\getMatchedLanguage().

◆ getMediaType()

File::getMediaType ( )

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 ForeignAPIFile, and LocalFile.

Definition at line 733 of file File.php.

References MEDIATYPE_UNKNOWN.

Referenced by getIsSafeFileUncached().

◆ getMetadata()

File::getMetadata ( )

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

Returns
bool|array

Reimplemented in ForeignAPIFile, LocalFile, and UnregisteredLocalFile.

Definition at line 654 of file File.php.

Referenced by getContentHeaders().

◆ getMimeType()

File::getMimeType ( )

Returns the MIME type of the file.

Overridden by LocalFile, UnregisteredLocalFile STUB

Returns
string

Reimplemented in ForeignAPIFile, LocalFile, UnregisteredLocalFile, and FakeDimensionFile.

Definition at line 722 of file File.php.

Referenced by checkExtensionCompatibility(), generateThumbName(), getHandler(), getIsSafeFileUncached(), and getViewURL().

◆ getName()

◆ getOriginalTitle()

File::getOriginalTitle ( )

Return the title used to find this file.

Returns
Title

Definition at line 336 of file File.php.

References $title, and getRedirectedTitle().

◆ getPath()

File::getPath ( )

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 418 of file File.php.

References $path, and(), assertRepoDefined(), and getRel().

Referenced by LocalFile\acquireFileLock(), exists(), getLocalRefPath(), getSha1(), LocalFile\getSha1(), getTimestamp(), and LocalFile\releaseFileLock().

◆ getRedirected()

File::getRedirected ( )
Returns
string

Definition at line 2225 of file File.php.

References $redirected.

◆ getRedirectedTitle()

File::getRedirectedTitle ( )
Returns
Title|null

Definition at line 2232 of file File.php.

References $redirectTitle, and NS_FILE.

Referenced by getOriginalTitle().

◆ getRel()

File::getRel ( )

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

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

Returns
string

Reimplemented in OldLocalFile.

Definition at line 1528 of file File.php.

References getHashPath(), and getName().

Referenced by getPath(), getThumbRel(), LocalFile\publish(), and LocalFile\recordUpload2().

◆ getRepo()

◆ getRepoName()

File::getRepoName ( )

Returns the name of the repository.

Returns
string

Definition at line 1857 of file File.php.

◆ getSha1()

File::getSha1 ( )

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

Returns
string

Reimplemented in ForeignAPIFile, and LocalFile.

Definition at line 2129 of file File.php.

References assertRepoDefined(), and getPath().

Referenced by generateThumbName(), and getStorageKey().

◆ getShortDesc()

File::getShortDesc ( )
Returns
string

Definition at line 2201 of file File.php.

References $handler, MediaHandler\getGeneralShortDesc(), getHandler(), and MediaHandler\getShortDesc().

◆ getSize()

File::getSize ( )

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

Returns
bool

Reimplemented in ForeignAPIFile, LocalFile, and UnregisteredLocalFile.

Definition at line 711 of file File.php.

Referenced by getThumbnailSource().

◆ getStorageKey()

File::getStorageKey ( )

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

Returns
string|false

Definition at line 2140 of file File.php.

References $ext, and(), getExtension(), and getSha1().

◆ getThumbDisposition()

File::getThumbDisposition ( $thumbName,
$dispositionType = 'inline' )
Parameters
string$thumbNameThumbnail name
string$dispositionTypeType of disposition (either "attachment" or "inline")
Returns
string Content-Disposition header value

Definition at line 1354 of file File.php.

References $name, FileBackend\extensionFromPath(), getExtension(), and FileBackend\makeContentDisposition().

Referenced by generateAndSaveThumb().

◆ getThumbnailBucket()

File::getThumbnailBucket ( $desiredWidth,
$page = 1 )

Return the smallest bucket from $wgThumbnailBuckets which is at least $wgThumbnailMinimumBucketDistance larger than $desiredWidth.

The returned bucket, if any, will always be bigger than $desiredWidth.

Parameters
int$desiredWidth
int$page
Returns
bool|int

Definition at line 491 of file File.php.

References $wgThumbnailBuckets, $wgThumbnailMinimumBucketDistance, and(), and getWidth().

Referenced by generateBucketsIfNeeded(), and getThumbnailSource().

◆ getThumbnails()

File::getThumbnails ( )

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

Returns
string[]

Reimplemented in ForeignAPIFile.

Definition at line 1424 of file File.php.

Referenced by LocalFile\purgeOldThumbnails(), and LocalFile\purgeThumbnails().

◆ getThumbnailSource()

File::getThumbnailSource ( $params)

Returns the most appropriate source image for the thumbnail, given a target thumbnail size.

Parameters
array$params
Returns
array Source path and width/height of the source

Definition at line 1257 of file File.php.

References $fsFile, $params, and(), PoolCounterWork\execute(), getBucketThumbPath(), getHandler(), getHeight(), getLocalRefPath(), getName(), FSFile\getPath(), getSize(), getThumbnailBucket(), and getWidth().

◆ getThumbPath()

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 ForeignAPIFile, and UploadStashFile.

Definition at line 1625 of file File.php.

References assertRepoDefined(), and getThumbRel().

Referenced by generateAndSaveThumb(), getBucketThumbPath(), LocalFile\getThumbnails(), and transform().

◆ getThumbRel()

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 1557 of file File.php.

References $path, and getRel().

Referenced by getThumbPath(), and getTranscodedPath().

◆ getThumbUrl()

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 1705 of file File.php.

References getZoneUrl().

Referenced by generateAndSaveThumb(), LocalFile\purgeThumbnails(), and transform().

◆ getThumbVirtualUrl()

File::getThumbVirtualUrl ( $suffix = false)

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 1759 of file File.php.

References $path, and(), assertRepoDefined(), and getUrlRel().

◆ getTimestamp()

File::getTimestamp ( )

Get the 14-character timestamp of the file upload.

Returns
string|bool TS_MW timestamp or false on failure

Reimplemented in ForeignAPIFile, and LocalFile.

Definition at line 2107 of file File.php.

References assertRepoDefined(), and getPath().

◆ getTitle()

File::getTitle ( )

Return the associated title object.

Returns
Title

Definition at line 327 of file File.php.

References $title.

Referenced by FileDeleteForm\__construct(), LocalFile\prerenderThumbnails(), purgeDescription(), purgeEverything(), LocalFile\recordUpload(), LocalFile\recordUpload2(), and wasDeleted().

◆ getTranscodedPath()

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 1637 of file File.php.

References assertRepoDefined(), and getThumbRel().

◆ getTranscodedUrl()

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 1715 of file File.php.

References getZoneUrl().

◆ getTransformScript()

File::getTransformScript ( )
Returns
string

Definition at line 909 of file File.php.

References $transformScript, and(), getName(), and wfAppendQuery().

Referenced by transform().

◆ getUnscaledThumb()

File::getUnscaledThumb ( $handlerParams = [])

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

Parameters
array$handlerParams
Returns
ThumbnailImage|MediaTransformOutput|bool False on failure

Definition at line 930 of file File.php.

References $handlerParams, and(), getWidth(), iconThumb(), and transform().

◆ getUrl()

File::getUrl ( )

Return the URL of the file.

Returns
string

Reimplemented in ForeignAPIFile, and UploadStashFile.

Definition at line 349 of file File.php.

References $ext, $url, and(), assertRepoDefined(), getExtension(), and getUrlRel().

Referenced by RevDelFileItem\getApiData(), getCanonicalUrl(), getFullUrl(), getViewURL(), LocalFile\purgeCache(), and LocalFile\recordUpload2().

◆ getUrlRel()

File::getUrlRel ( )

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

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

Returns
string

Reimplemented in OldLocalFile.

Definition at line 1572 of file File.php.

References and(), getHashPath(), and getName().

Referenced by getThumbVirtualUrl(), getUrl(), getVirtualUrl(), and getZoneUrl().

◆ getUser()

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 ForeignAPIFile, and LocalFile.

Definition at line 533 of file File.php.

◆ getViewURL()

File::getViewURL ( )
Returns
string

Definition at line 390 of file File.php.

References canRender(), createThumb(), getMimeType(), getName(), getUrl(), getWidth(), mustRender(), and wfDebug().

◆ getVirtualUrl()

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 1725 of file File.php.

References $path, and(), assertRepoDefined(), and getUrlRel().

Referenced by LocalFile\isMissing(), LocalFile\loadFromFile(), and LocalFile\recordUpload2().

◆ getVisibility()

File::getVisibility ( )

Return the deletion bitfield STUB.

Returns
int

Reimplemented in OldLocalFile.

Definition at line 1896 of file File.php.

◆ getWidth()

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
int$page
Returns
int|bool

Reimplemented in ForeignAPIFile, LocalFile, UnregisteredLocalFile, and FakeDimensionFile.

Definition at line 464 of file File.php.

Referenced by getThumbnailBucket(), getThumbnailSource(), getUnscaledThumb(), and getViewURL().

◆ getZoneUrl()

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 1688 of file File.php.

References $ext, $path, and(), assertRepoDefined(), getExtension(), and getUrlRel().

Referenced by getThumbUrl(), and getTranscodedUrl().

◆ iconThumb()

File::iconThumb ( )

Get a ThumbnailImage representing a file type icon.

Returns
ThumbnailImage

Definition at line 1392 of file File.php.

References $IP, $params, $wgResourceBasePath, and(), and getExtension().

Referenced by getUnscaledThumb(), and transform().

◆ isCacheable()

File::isCacheable ( )

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

Returns
bool

Reimplemented in LocalFile.

Definition at line 2263 of file File.php.

◆ isDeleted()

File::isDeleted ( $field)

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

Parameters
int$fieldOne of DELETED_* bitfield constants
Returns
bool

Reimplemented in OldLocalFile.

Definition at line 1887 of file File.php.

Referenced by LocalFile\getDescription().

◆ isExpensiveToThumbnail()

File::isExpensiveToThumbnail ( )

True if creating thumbnails from the file is large or otherwise resource-intensive.

Returns
bool

Definition at line 2291 of file File.php.

References $handler, getHandler(), and MediaHandler\isExpensiveToThumbnail().

◆ isHashed()

File::isHashed ( )
Returns
bool

Definition at line 1772 of file File.php.

References assertRepoDefined().

◆ isLocal()

File::isLocal ( )

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

Returns
bool

Definition at line 1848 of file File.php.

Referenced by FileDeleteForm\haveDeletableFile().

◆ isMissing()

File::isMissing ( )
Returns
bool

Reimplemented in LocalFile.

Definition at line 2255 of file File.php.

◆ isMultipage()

File::isMultipage ( )

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 1971 of file File.php.

References getHandler(), and handler.

Referenced by LocalFile\getHeight(), and LocalFile\getWidth().

◆ isOld()

File::isOld ( )

Returns true if the image is an old version STUB.

Returns
bool

Reimplemented in OldLocalFile.

Definition at line 1876 of file File.php.

Referenced by LocalFile\publishTo().

◆ isSafeFile()

File::isSafeFile ( )

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 801 of file File.php.

References $isSafeFile, and(), getIsSafeFileUncached(), and isSafeFile().

Referenced by getIsSafeFile(), and isSafeFile().

◆ isTransformedLocally()

File::isTransformedLocally ( )

Whether the thumbnails created on the same server as this code is running.

Since
1.25
Returns
bool

Reimplemented in ForeignAPIFile.

Definition at line 2301 of file File.php.

◆ isTrustedFile()

File::isTrustedFile ( )

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 867 of file File.php.

Referenced by getIsSafeFileUncached().

◆ isVectorized()

File::isVectorized ( )

Return true if the file is vectorized.

Returns
bool

Definition at line 556 of file File.php.

References $handler, getHandler(), and MediaHandler\isVectorized().

Referenced by LocalFile\prerenderThumbnails().

◆ isVisible()

File::isVisible ( )

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
bool Whether file exists in the repository and is includable.

Reimplemented in OldLocalFile.

Definition at line 902 of file File.php.

References exists().

◆ load()

File::load ( $flags = 0)

Load any lazy-loaded file object fields from source.

This is only useful when setting $flags

Overridden by LocalFile to actually query the DB

Parameters
int$flagsBitfield of File::READ_* constants

Reimplemented in LocalFile.

Definition at line 882 of file File.php.

◆ makeTransformTmpFile()

File::makeTransformTmpFile ( $thumbPath)
protected

Creates a temp FS file with the same extension and the thumbnail.

Parameters
string$thumbPathThumbnail path
Returns
TempFSFile|null

Definition at line 1344 of file File.php.

References FileBackend\extensionFromPath(), TempFSFile\factory(), and wfTempDir().

Referenced by generateBucketsIfNeeded(), and transform().

◆ migrateThumbFile()

File::migrateThumbFile ( $thumbName)

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

Parameters
string$thumbName

Definition at line 1370 of file File.php.

◆ move()

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
Title$targetNew file name
Returns
Status

Reimplemented in ForeignDBFile, and LocalFile.

Definition at line 1923 of file File.php.

References readOnlyError().

◆ mustRender()

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

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 775 of file File.php.

References getHandler(), and handler.

Referenced by getViewURL().

◆ nextHistoryLine()

File::nextHistoryLine ( )

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 1493 of file File.php.

◆ normalizeExtension()

static File::normalizeExtension ( $extension)
static

Normalize a file extension to the common form, making it lowercase and checking some synonyms, and ensure it's clean.

Extensions with non-alphanumeric characters will be discarded. Keep in sync with mw.Title.normalizeExtension() in JS.

Parameters
string$extensionFile extension (without the leading dot)
Returns
string File extension in canonical form

Definition at line 225 of file File.php.

References $extension, and and().

Referenced by checkExtensionCompatibility(), getExtension(), UploadStash\getExtensionForPath(), and LocalRepo\hiddenFileHasKey().

◆ normalizeTitle()

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
Title | string$title
string | bool$exceptionUse 'exception' to throw an error on bad titles
Exceptions
MWException
Returns
Title|null

Definition at line 185 of file File.php.

References $ret, $title, and(), NS_FILE, and NS_MEDIA.

Referenced by ArchivedFile\__construct(), __construct(), UnregisteredLocalFile\__construct(), LocalRepo\checkRedirect(), FileRepo\findFile(), RepoGroup\findFile(), RepoGroup\findFiles(), FileRepo\findFiles(), LocalRepo\findFiles(), and FileRepo\newFile().

◆ pageCount()

File::pageCount ( )

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

Returns
string|bool|int

Definition at line 1981 of file File.php.

References $pageCount, and(), getHandler(), handler, and pageCount().

Referenced by pageCount().

◆ publish()

File::publish ( $src,
$flags = 0,
array $options = [] )

Move or copy a file to its public location.

If a file exists at the destination, move it to an archive. Returns a Status 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 | FSFile$srcLocal filesystem path to the source image
int$flagsA bitwise combination of: File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
array$optionsOptional additional parameters
Returns
Status 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 1827 of file File.php.

References readOnlyError().

◆ purgeCache()

File::purgeCache ( $options = [])

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 ForeignAPIFile, and LocalFile.

Definition at line 1435 of file File.php.

Referenced by purgeEverything().

◆ purgeDescription()

File::purgeDescription ( )

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 1443 of file File.php.

References getTitle().

Referenced by LocalFile\deleteOld(), and purgeEverything().

◆ purgeEverything()

File::purgeEverything ( )

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

Definition at line 1455 of file File.php.

References getTitle(), purgeCache(), and purgeDescription().

Referenced by LocalFile\delete().

◆ readOnlyError()

◆ recordUpload()

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
string$oldver
string$desc
string$license
string$copyStatus
string$source
bool$watch
string | bool$timestamp
null | User$userUser object or null to use $wgUser
Returns
bool
Exceptions
MWException

Reimplemented in ForeignDBFile, and LocalFile.

Definition at line 1800 of file File.php.

References readOnlyError().

◆ redirectedFrom()

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

Definition at line 2248 of file File.php.

◆ resetHistory()

File::resetHistory ( )

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 1503 of file File.php.

◆ restore()

File::restore ( $versions = [],
$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 ForeignDBFile, and LocalFile.

Definition at line 1960 of file File.php.

References readOnlyError().

◆ scaleHeight()

static File::scaleHeight ( $srcWidth,
$srcHeight,
$dstWidth )
static

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

Parameters
int$srcWidth
int$srcHeight
int$dstWidth
Returns
int

Definition at line 2002 of file File.php.

References and().

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

◆ splitMime()

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
string[] ("text", "html") etc

Definition at line 274 of file File.php.

References and().

Referenced by MIMEsearchPage\execute(), RefreshImageMetadata\getConditions(), MWFileProps\getPropsFromPath(), ApiQueryAllImages\run(), LocalFile\setProps(), LocalFile\upgradeRow(), and OldLocalFile\upgradeRow().

◆ thumbName()

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
int$flagsBitfield that supports THUMB_* constants
Returns
string|null

Reimplemented in UploadStashFile.

Definition at line 953 of file File.php.

References $params, generateThumbName(), getName(), and THUMB_FULL_NAME.

Referenced by generateAndSaveThumb(), getBucketThumbName(), and transform().

◆ transform()

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.
int$flagsA bitfield, may contain self::RENDER_NOW to force rendering
Returns
ThumbnailImage|MediaTransformOutput|bool False on failure

Reimplemented in ForeignAPIFile.

Definition at line 1049 of file File.php.

References $handler, $params, $wgThumbnailEpoch, and(), canRender(), generateAndSaveThumb(), getDescriptionUrl(), getHandler(), MediaHandler\getScriptedTransform(), getThumbPath(), getThumbUrl(), MediaHandler\getTransform(), getTransformScript(), iconThumb(), makeTransformTmpFile(), MediaHandler\normaliseParams(), PROTO_CANONICAL, thumbName(), transformErrorOutput(), wfDebug(), and wfExpandUrl().

Referenced by createThumb(), and getUnscaledThumb().

◆ transformErrorOutput()

File::transformErrorOutput ( $thumbPath,
$thumbUrl,
$params,
$flags )
protected

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

Parameters
string$thumbPathThumbnail storage path
string$thumbUrlThumbnail URL
array$params
int$flags
Returns
MediaTransformOutput

Definition at line 1029 of file File.php.

References $handler, $params, $wgIgnoreImageErrors, getHandler(), MediaHandler\getTransform(), and wfMessage().

Referenced by generateAndSaveThumb(), and transform().

◆ upgradeRow()

File::upgradeRow ( )

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

Reimplemented in LocalFile, and OldLocalFile.

Definition at line 264 of file File.php.

◆ userCan()

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
int$field
User | null$userUser object to check, or null to use $wgUser
Returns
bool

Reimplemented in OldLocalFile.

Definition at line 2159 of file File.php.

Referenced by LocalFile\getDescription().

◆ wasDeleted()

File::wasDeleted ( )

Was this file ever deleted from the wiki?

Returns
bool

Definition at line 1905 of file File.php.

References getTitle().

Member Data Documentation

◆ $canRender

bool File::$canRender
protected

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

Definition at line 144 of file File.php.

Referenced by canRender().

◆ $extension

string File::$extension
protected

File extension.

Definition at line 121 of file File.php.

Referenced by generateThumbName(), getExtension(), and normalizeExtension().

◆ $fsFile

FSFile bool File::$fsFile
protected

False if undefined.

Definition at line 112 of file File.php.

Referenced by getThumbnailSource(), and UnregisteredLocalFile\setLocalReference().

◆ $handler

◆ $hashPath

string File::$hashPath
protected

Relative path including trailing slash.

Definition at line 130 of file File.php.

Referenced by getHashPath().

◆ $isSafeFile

bool File::$isSafeFile
protected

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

Definition at line 149 of file File.php.

Referenced by isSafeFile().

◆ $lastError

string File::$lastError
protected

Text of last error.

Definition at line 103 of file File.php.

Referenced by getLastError().

◆ $name

string File::$name
protected

The name of a file from its title object.

Definition at line 124 of file File.php.

Referenced by UnregisteredLocalFile\__construct(), generateThumbName(), getName(), and getThumbDisposition().

◆ $pageCount

string false File::$pageCount
protected

Number of pages of a multipage document, or false for documents which aren't multipage documents.

Definition at line 135 of file File.php.

Referenced by pageCount().

◆ $path

string File::$path
protected

◆ $redirected

string File::$redirected
protected

Main part of the title, with underscores (Title::getDBkey)

Definition at line 106 of file File.php.

Referenced by getRedirected().

◆ $redirectedTitle

Title File::$redirectedTitle
protected

Definition at line 109 of file File.php.

◆ $redirectTitle

Title File::$redirectTitle
protected

Definition at line 141 of file File.php.

Referenced by getRedirectedTitle().

◆ $repo

FileRepo LocalRepo ForeignAPIRepo 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

Definition at line 97 of file File.php.

Referenced by UploadStashFile\__construct(), __construct(), LocalFile\__construct(), ForeignAPIFile\__construct(), OldLocalFile\__construct(), UnregisteredLocalFile\__construct(), getRepo(), OldLocalFile\newFromArchiveName(), LocalFile\newFromKey(), OldLocalFile\newFromKey(), ForeignDBFile\newFromRow(), LocalFile\newFromRow(), OldLocalFile\newFromRow(), UnregisteredLocalFile\newFromTitle(), OldLocalFile\newFromTitle(), ForeignDBFile\newFromTitle(), LocalFile\newFromTitle(), ForeignAPIFile\newFromTitle(), and LocalFile\publishTo().

◆ $repoClass

string File::$repoClass = FileRepo::class
protected

Required Repository class type.

Definition at line 152 of file File.php.

◆ $title

◆ $tmpBucketedThumbCache

array File::$tmpBucketedThumbCache = []
protected

Cache of tmp filepaths pointing to generated bucket thumbnails, keyed by width.

Definition at line 155 of file File.php.

◆ $transformScript

string File::$transformScript
protected

URL of transformscript (for example thumb.php)

Definition at line 138 of file File.php.

Referenced by getTransformScript().

◆ $url

string File::$url
protected

The URL corresponding to one of the four basic zones.

Definition at line 118 of file File.php.

Referenced by ForeignAPIFile\getDescriptionShortUrl(), ForeignDBFile\getDescriptionShortUrl(), LocalFile\getDescriptionShortUrl(), getUrl(), and ForeignAPIFile\purgeDescriptionPage().

◆ DELETE_SOURCE

const File::DELETE_SOURCE = 1

Definition at line 67 of file File.php.

Referenced by UploadBase\performUpload(), and LocalFile\publishTo().

◆ DELETED_COMMENT

◆ DELETED_FILE

◆ DELETED_RESTRICTED

◆ DELETED_USER

◆ FOR_PUBLIC

const File::FOR_PUBLIC = 1

Definition at line 70 of file File.php.

◆ FOR_THIS_USER

const File::FOR_THIS_USER = 2

Definition at line 71 of file File.php.

Referenced by ImageHistoryList\imageHistoryLine().

◆ RAW

const File::RAW = 3

Definition at line 72 of file File.php.

Referenced by ApiQueryImageInfo\getInfo().

◆ RENDER_FORCE

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 65 of file File.php.

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

◆ RENDER_NOW

◆ THUMB_FULL_NAME

const File::THUMB_FULL_NAME = 1

Definition at line 75 of file File.php.

Referenced by thumbName(), and wfStreamThumb().


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