MediaWiki  master
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. More...
 
 __get ( $name)
 
 allowInlineDisplay ()
 Alias for canRender() More...
 
 canAnimateThumbIfAppropriate ()
 Will the thumbnail be animated if one would expect it to be. More...
 
 canRender ()
 Checks if the output of transform() for this file is likely to be valid. More...
 
 convertMetadataVersion ( $metadata, $version)
 get versioned metadata More...
 
 createThumb ( $width, $height=-1)
 Create a thumbnail of the image having the specified width/height. More...
 
 deleteFile ( $reason, UserIdentity $user, $suppress=false)
 Delete all versions of the file. More...
 
 exists ()
 Returns true if file exists in the repository. More...
 
 formatMetadata ( $context=false)
 
 generateAndSaveThumb ( $tmpFile, $transformParams, $flags)
 Generates a thumbnail according to the given parameters and saves it to storage. More...
 
 generateThumbName ( $name, $params)
 Generate a thumbnail file name from a name and specified parameters. More...
 
 getArchivePath ( $suffix=false)
 Get the path of the archived file. More...
 
 getArchiveRel ( $suffix=false)
 Get the path of an archived file relative to the public zone root. More...
 
 getArchiveThumbPath ( $archiveName, $suffix=false)
 Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified. More...
 
 getArchiveThumbUrl ( $archiveName, $suffix=false)
 Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified. More...
 
 getArchiveUrl ( $suffix=false)
 Get the URL of the archive directory, or a particular file if $suffix is specified. More...
 
 getArchiveVirtualUrl ( $suffix=false)
 Get the public zone virtual URL for an archived version source file. More...
 
 getAvailableLanguages ()
 Gives a (possibly empty) list of IETF languages to render the file in. More...
 
 getBitDepth ()
 Return the bit depth of the file Overridden by LocalFile STUB. More...
 
 getCanonicalUrl ()
 
 getCommonMetaArray ()
 Like getMetadata but returns a handler independent array of common values. More...
 
 getContentHeaders ()
 
 getDefaultRenderLanguage ()
 In files that support multiple language, what is the default language to use if none specified. More...
 
 getDescription ( $audience=self::FOR_PUBLIC, Authority $performer=null)
 Get description of file revision STUB. More...
 
 getDescriptionShortUrl ()
 Get short description URL for a files based on the page ID. More...
 
 getDescriptionText (Language $lang=null)
 Get the HTML text of the description page, if available. More...
 
 getDescriptionTouched ()
 Returns the timestamp (in TS_MW format) of the last change of the description page. More...
 
 getDescriptionUrl ()
 Get the URL of the image description page. More...
 
 getDimensionsString ()
 
 getDisplayWidthHeight ( $maxWidth, $maxHeight, $page=1)
 Get the width and height to display image at. More...
 
 getExtension ()
 Get the file extension, e.g. More...
 
 getFilePageThumbUrl ( $url)
 Append a version parameter to the end of a file URL Only to be used on File pages. More...
 
 getFullUrl ()
 Return a fully-qualified URL to the file. More...
 
 getHandler ()
 Get a MediaHandler instance for this file. More...
 
 getHandlerState (string $key)
 Get a value, or null if it does not exist. More...
 
 getHashPath ()
 Get the filename hash component of the directory including trailing slash, e.g. More...
 
 getHeight ( $page=1)
 Return the height of the image. More...
 
 getHistory ( $limit=null, $start=null, $end=null, $inc=true)
 Return a fragment of the history of file. More...
 
 getLastError ()
 Get last thumbnailing error. More...
 
 getLength ()
 Get the duration of a media file in seconds. More...
 
 getLocalRefPath ()
 Get an FS copy or original of this file and return the path. More...
 
 getLongDesc ()
 
 getMatchedLanguage ( $userPreferredLanguage)
 Get the IETF language code from the available languages for this file that matches the language requested by the user. More...
 
 getMediaType ()
 Return the type of the media in the file. More...
 
 getMetadata ()
 Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB. More...
 
 getMetadataArray ()
 Get the unserialized handler-specific metadata STUB. More...
 
 getMetadataItem (string $itemName)
 Get a specific element of the unserialized handler-specific metadata. More...
 
 getMetadataItems (array $itemNames)
 Get multiple elements of the unserialized handler-specific metadata. More...
 
 getMimeType ()
 Returns the MIME type of the file. More...
 
 getName ()
 Return the name of this file. More...
 
 getOriginalTitle ()
 Return the title used to find this file. More...
 
 getPath ()
 Return the storage path to the file. More...
 
 getRedirected ()
 
 getRel ()
 Get the path of the file relative to the public zone root. More...
 
 getRepo ()
 Returns the repository. More...
 
 getRepoName ()
 Returns the name of the repository. More...
 
 getSha1 ()
 Get the SHA-1 base 36 hash of the file. More...
 
 getShortDesc ()
 
 getSize ()
 Return the size of the image file, in bytes Overridden by LocalFile, UnregisteredLocalFile STUB. More...
 
 getStorageKey ()
 Get the deletion archive key, "<sha1>.<ext>". More...
 
 getThumbDisposition ( $thumbName, $dispositionType='inline')
 
 getThumbnailBucket ( $desiredWidth, $page=1)
 Return the smallest bucket from $wgThumbnailBuckets which is at least $wgThumbnailMinimumBucketDistance larger than $desiredWidth. More...
 
 getThumbnailSource ( $params)
 Returns the most appropriate source image for the thumbnail, given a target thumbnail size. More...
 
 getThumbPath ( $suffix=false)
 Get the path of the thumbnail directory, or a particular file if $suffix is specified. More...
 
 getThumbRel ( $suffix=false)
 Get the path, relative to the thumbnail zone root, of the thumbnail directory or a particular file if $suffix is specified. More...
 
 getThumbUrl ( $suffix=false)
 Get the URL of the thumbnail directory, or a particular file if $suffix is specified. More...
 
 getThumbVirtualUrl ( $suffix=false)
 Get the virtual URL for a thumbnail file or directory. More...
 
 getTimestamp ()
 Get the 14-character timestamp of the file upload. More...
 
 getTitle ()
 Return the associated title object. More...
 
 getTranscodedPath ( $suffix=false)
 Get the path of the transcoded directory, or a particular file if $suffix is specified. More...
 
 getTranscodedUrl ( $suffix=false)
 Get the URL of the transcoded directory, or a particular file if $suffix is specified. More...
 
 getUnscaledThumb ( $handlerParams=[])
 Get a ThumbnailImage which is the same size as the source. More...
 
 getUploader (int $audience=self::FOR_PUBLIC, Authority $performer=null)
 Get the identity of the file uploader. More...
 
 getUrl ()
 Return the URL of the file. More...
 
 getUrlRel ()
 Get urlencoded path of the file relative to the public zone root. More...
 
 getViewURL ()
 
 getVirtualUrl ( $suffix=false)
 Get the public zone virtual URL for a current version source file. More...
 
 getVisibility ()
 Return the deletion bitfield STUB. More...
 
 getWidth ( $page=1)
 Return the width of the image. More...
 
 iconThumb ()
 Get a ThumbnailImage representing a file type icon. More...
 
 isCacheable ()
 Check if this file object is small and can be cached. More...
 
 isDeleted ( $field)
 Is this file a "deleted" file in a private archive? STUB. More...
 
 isExpensiveToThumbnail ()
 True if creating thumbnails from the file is large or otherwise resource-intensive. More...
 
 isLocal ()
 Returns true if the file comes from the local file repository. More...
 
 isMissing ()
 
 isMultipage ()
 Returns 'true' if this file is a type which supports multiple pages, e.g. More...
 
 isOld ()
 Returns true if the image is an old version STUB. More...
 
 isSafeFile ()
 Determines if this media file is in a format that is unlikely to contain viruses or malicious content. More...
 
 isTransformedLocally ()
 Whether the thumbnails created on the same server as this code is running. More...
 
 isVectorized ()
 Return true if the file is vectorized. More...
 
 isVisible ()
 Returns true if file exists in the repository and can be included in a page. More...
 
 load ( $flags=0)
 Load any lazy-loaded file object fields from source. More...
 
 move ( $target)
 Move file to the new title. More...
 
 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. More...
 
 nextHistoryLine ()
 Return the history of this file, line by line. More...
 
 pageCount ()
 Returns the number of pages of a multipage document, or false for documents which aren't multipage documents. More...
 
 publish ( $src, $flags=0, array $options=[])
 Move or copy a file to its public location. More...
 
 purgeCache ( $options=[])
 Purge shared caches such as thumbnails and DB data caching STUB Overridden by LocalFile. More...
 
 purgeDescription ()
 Purge the file description page, but don't go after pages using the file. More...
 
 purgeEverything ()
 Purge metadata and all affected pages when the file is created, deleted, or majorly updated. More...
 
 redirectedFrom ( $from)
 
 resetHistory ()
 Reset the history pointer to the first element of the history. More...
 
 restore ( $versions=[], $unsuppress=false)
 Restore all or specified deleted revisions to the given file. More...
 
 setHandlerState (string $key, $value)
 Set a value. More...
 
 thumbName ( $params, $flags=0)
 Return the file name of a thumbnail with the specified parameters. More...
 
 transform ( $params, $flags=0)
 Transform a media file. More...
 
 upgradeRow ()
 Upgrade the database row if there is one Called by ImagePage STUB. More...
 
 userCan ( $field, Authority $performer)
 Determine if the current user is allowed to view a particular field of this file, if it's marked as deleted. More...
 
 wasDeleted ()
 Was this file ever deleted from the wiki? More...
 

Static Public Member Functions

static checkExtensionCompatibility (File $old, $new)
 Checks if file extensions are compatible. More...
 
static compare (File $a, File $b)
 Callback for usort() to do file sorts by name. More...
 
static normalizeExtension ( $extension)
 Normalize a file extension to the common form, making it lowercase and checking some synonyms, and ensure it's clean. More...
 
static normalizeTitle ( $title, $exception=false)
 Given a string or Title object return either a valid Title object with namespace NS_FILE or null. More...
 
static scaleHeight ( $srcWidth, $srcHeight, $dstWidth)
 Calculate the height of a thumbnail using the source and destination width. More...
 
static splitMime ( $mime)
 Split an internet media type into its two components; if not a two-part name, set the minor type to 'unknown'. More...
 

Public Attributes

FileRepo LocalRepo ForeignAPIRepo bool $repo
 Some member variables can be lazy-initialised using __get(). More...
 
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. More...
 
const RENDER_NOW = 1
 Force rendering in the current process. More...
 
const THUMB_FULL_NAME = 1
 
- Public Attributes inherited from IDBAccessObject
const READ_NONE = -1
 Constants for object loading bitfield flags (higher => higher QoS) More...
 

Protected Member Functions

 assertRepoDefined ()
 Assert that $this->repo is set to a valid FileRepo instance. More...
 
 assertTitleDefined ()
 Assert that $this->title is set to a Title. More...
 
 generateBucketsIfNeeded ( $params, $flags=0)
 Generates chained bucketed thumbnails if needed. More...
 
 getBucketThumbName ( $bucket)
 Returns the name of the thumb for a given bucket. More...
 
 getBucketThumbPath ( $bucket)
 Returns the repo path of the thumb for a given bucket. More...
 
 getCanRender ()
 Accessor for __get() More...
 
 getIsSafeFile ()
 Accessor for __get() More...
 
 getIsSafeFileUncached ()
 Uncached accessor. More...
 
 getRedirectedTitle ()
 
 getThumbnails ()
 Get all thumbnail names previously generated for this file STUB Overridden by LocalFile. More...
 
 isHashed ()
 
 isTrustedFile ()
 Returns true if the file is flagged as trusted. More...
 
 makeTransformTmpFile ( $thumbPath)
 Creates a temp FS file with the same extension and the thumbnail. More...
 
 migrateThumbFile ( $thumbName)
 Hook into transform() to allow migration of thumbnail files STUB. More...
 
 readOnlyError ()
 
 transformErrorOutput ( $thumbPath, $thumbUrl, $params, $flags)
 Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors) More...
 

Protected Attributes

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

Private Member Functions

 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. More...
 
 getTransformScript ()
 
 getZoneUrl ( $zone, $suffix=false)
 Get the URL of the zone directory, or a particular file if $suffix is specified. More...
 

Private Attributes

array $handlerState = []
 

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 explicitly outside of the repo class. Instead use the repo's factory functions to generate file objects, for example:

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

Consider the services container below;

$services = MediaWikiServices::getInstance();

The convenience services $services->getRepoGroup()->getLocalRepo()->newFile() and $services->getRepoGroup()->findFile() should be sufficient in most cases.

@TODO: DI - Instead of using MediaWikiServices::getInstance(), a service should ideally accept a RepoGroup in its constructor and then, use $this->repoGroup->findFile() and $this->repoGroup->getLocalRepo()->newFile().

Stability: stable
to extend

Definition at line 68 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.

Stability: stable
to call
Parameters
Title | string | bool$title
FileRepo | bool$repo

Reimplemented in LocalFile.

Definition at line 189 of file File.php.

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

Member Function Documentation

◆ __get()

File::__get (   $name)

Definition at line 237 of file File.php.

References $name.

◆ allowInlineDisplay()

File::allowInlineDisplay ( )

Alias for canRender()

Returns
bool

Definition at line 902 of file File.php.

Referenced by canAnimateThumbIfAppropriate().

◆ assertRepoDefined()

File::assertRepoDefined ( )
protected

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

Exceptions
MWException

Definition at line 2462 of file File.php.

Referenced by LocalFile\__construct(), ForeignAPIFile\__construct(), UnregisteredLocalFile\__construct(), getLocalRefPath(), getName(), getPath(), and getUrl().

◆ assertTitleDefined()

File::assertTitleDefined ( )
protected

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

Exceptions
MWException

Definition at line 2472 of file File.php.

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

Referenced by getViewURL(), 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 281 of file File.php.

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

References getName().

◆ convertMetadataVersion()

File::convertMetadataVersion (   $metadata,
  $version 
)

get versioned metadata

Parameters
array$metadataArray of unserialized metadata
int | string$versionVersion number.
Returns
array Array containing metadata, or what was passed to it on fail

Definition at line 799 of file File.php.

References MediaHandler\convertMetadataVersion().

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

Referenced by getViewURL().

◆ deleteFile()

File::deleteFile (   $reason,
UserIdentity  $user,
  $suppress = false 
)

Delete all versions of the file.

Since
1.35

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
UserIdentity$user
bool$suppressHide content from sysops?
Returns
Status STUB Overridden by LocalFile
Stability: stable
to override

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 2129 of file File.php.

◆ exists()

File::exists ( )

Returns true if file exists in the repository.

Overridden by LocalFile to avoid unnecessary stat calls.

Stability: stable
to override
Returns
bool Whether file exists in the repository.

Reimplemented in UploadStashFile, OldLocalFile, LocalFile, and ForeignAPIFile.

Definition at line 1012 of file File.php.

◆ formatMetadata()

File::formatMetadata (   $context = false)
Parameters
IContextSource | false$context
Returns
array[]|false

Definition at line 2014 of file File.php.

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

References MediaHandler\doTransform(), MediaHandler\getTransform(), MediaHandler\normaliseParams(), MediaHandler\supportsBucketing(), and wfMessage().

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

◆ generateThumbName()

File::generateThumbName (   $name,
  $params 
)

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

Stability: stable
to override
Parameters
string$name
array$paramsParameters which will be passed to MediaHandler::makeParamString
Returns
string|null

Definition at line 1091 of file File.php.

Referenced by 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 1774 of file File.php.

◆ getArchiveRel()

File::getArchiveRel (   $suffix = false)

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

Stability: stable
to override
Parameters
bool | string$suffixIf not false, the name of an archived thumbnail file
Returns
string

Definition at line 1712 of file File.php.

References $path.

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

◆ getArchiveThumbRel()

File::getArchiveThumbRel (   $archiveName,
  $suffix = false 
)
private

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

References $path.

◆ getArchiveThumbUrl()

File::getArchiveThumbUrl (   $archiveName,
  $suffix = false 
)

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

Stability: stable
to override
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 1847 of file File.php.

References $ext, and $path.

◆ getArchiveUrl()

File::getArchiveUrl (   $suffix = false)

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

Stability: stable
to override
Parameters
bool | string$suffixIf not false, the name of an archived file
Returns
string

Definition at line 1826 of file File.php.

References $ext, and $path.

◆ getArchiveVirtualUrl()

File::getArchiveVirtualUrl (   $suffix = false)

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

Stability: stable
to override
Parameters
bool | string$suffixIf not false, the name of a thumbnail file
Returns
string

Definition at line 1938 of file File.php.

References $path.

◆ getAvailableLanguages()

File::getAvailableLanguages ( )

Gives a (possibly empty) list of IETF 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 650 of file File.php.

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

◆ getBitDepth()

File::getBitDepth ( )

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

Stability: stable
to override
Returns
int

Reimplemented in UnregisteredLocalFile, and LocalFile.

Definition at line 815 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 1495 of file File.php.

◆ getBucketThumbPath()

File::getBucketThumbPath (   $bucket)
protected

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

Parameters
int$bucket
Returns
string

Definition at line 1485 of file File.php.

◆ getCanonicalUrl()

File::getCanonicalUrl ( )
Stability: stable
to override
Returns
string

Definition at line 422 of file File.php.

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

◆ getCanRender()

File::getCanRender ( )
protected

Accessor for __get()

Returns
bool

Definition at line 878 of file File.php.

◆ getCommonMetaArray()

File::getCommonMetaArray ( )

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

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

Definition at line 782 of file File.php.

References MediaHandler\getCommonMetaArray().

◆ getContentHeaders()

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

Definition at line 2366 of file File.php.

References MediaHandler\getContentHeaders().

◆ getDefaultRenderLanguage()

File::getDefaultRenderLanguage ( )

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

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

Definition at line 685 of file File.php.

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

◆ getDescription()

File::getDescription (   $audience = self::FOR_PUBLIC,
Authority  $performer = null 
)

Get description of file revision STUB.

Stability: stable
to override
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
Authority | null$performerto check for, only if FOR_THIS_USER is passed to the $audience parameter
Returns
null|string

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 2293 of file File.php.

◆ getDescriptionShortUrl()

File::getDescriptionShortUrl ( )

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

Stability: stable
to override
Returns
string|null
Since
1.27

Reimplemented in LocalFile, ForeignDBFile, and ForeignAPIFile.

Definition at line 402 of file File.php.

◆ getDescriptionText()

File::getDescriptionText ( Language  $lang = null)

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

Stability: stable
to override
Parameters
Language | null$langOptional language to fetch description in
Returns
string|false HTML
-taint escaped

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 2223 of file File.php.

References $cache, $lang, $res, $wgLang, 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
Stability: stable
to override
Returns
string|bool

Reimplemented in LocalFile.

Definition at line 2317 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.

Stability: stable
to override
Returns
string|bool

Reimplemented in UploadStashFile, LocalFile, ForeignDBFile, and ForeignAPIFile.

Definition at line 2207 of file File.php.

Referenced by ForeignDBFile\getDescriptionUrl().

◆ getDimensionsString()

File::getDimensionsString ( )
Returns
string

Definition at line 2402 of file File.php.

References MediaHandler\getDimensionsString().

◆ getDisplayWidthHeight()

File::getDisplayWidthHeight (   $maxWidth,
  $maxHeight,
  $page = 1 
)

Get the width and height to display image at.

Parameters
int$maxWidthMax width to display at
int$maxHeightMax height to display at
int$page
Exceptions
MWException
Returns
array Array (width, height)
Since
1.35

Definition at line 580 of file File.php.

References getHeight(), and getWidth().

◆ getExtension()

File::getExtension ( )

Get the file extension, e.g.

"svg"

Stability: stable
to override
Returns
string

Definition at line 347 of file File.php.

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

Referenced by getUrl().

◆ getFilePageThumbUrl()

File::getFilePageThumbUrl (   $url)

Append a version parameter to the end of a file URL Only to be used on File pages.

Access: internal
Parameters
string$urlUnversioned URL
Returns
string

Definition at line 1896 of file File.php.

References getTimestamp(), and wfAppendQuery().

◆ 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.

Stability: stable
to override
Returns
string

Reimplemented in UploadStashFile.

Definition at line 414 of file File.php.

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

◆ getHandler()

File::getHandler ( )

◆ getHandlerState()

File::getHandlerState ( string  $key)

Get a value, or null if it does not exist.

Parameters
string$key
Returns
mixed|null

Implements MediaHandlerState.

Definition at line 733 of file File.php.

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

◆ 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

Stability: stable
to override
Parameters
int$page
Returns
bool|int False on failure

Reimplemented in UnregisteredLocalFile, LocalFile, and ForeignAPIFile.

Definition at line 520 of file File.php.

Referenced by getDisplayWidthHeight().

◆ getHistory()

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

Return a fragment of the history of file.

STUB

Stability: stable
to override
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 1649 of file File.php.

◆ getIsSafeFile()

File::getIsSafeFile ( )
protected

Accessor for __get()

Returns
bool

Definition at line 932 of file File.php.

◆ getIsSafeFileUncached()

File::getIsSafeFileUncached ( )
protected

Uncached accessor.

Returns
bool

Definition at line 941 of file File.php.

References $mime, $type, and MEDIATYPE_UNKNOWN.

◆ getLastError()

File::getLastError ( )

Get last thumbnailing error.

Largely obsolete.

Returns
string

Definition at line 1577 of file File.php.

◆ getLength()

File::getLength ( )

Get the duration of a media file in seconds.

Stability: stable
to override
Returns
float|int

Definition at line 616 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 474 of file File.php.

References assertRepoDefined(), and getPath().

Referenced by UnregisteredLocalFile\getMimeType().

◆ getLongDesc()

File::getLongDesc ( )
Returns
string

Definition at line 2378 of file File.php.

References MediaHandler\getGeneralLongDesc(), and MediaHandler\getLongDesc().

◆ getMatchedLanguage()

File::getMatchedLanguage (   $userPreferredLanguage)

Get the IETF 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 666 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

Stability: stable
to override
Returns
string

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 850 of file File.php.

References MEDIATYPE_UNKNOWN.

◆ getMetadata()

File::getMetadata ( )

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

Deprecated:
since 1.37 use getMetadataArray() or getMetadataItem()
Returns
string|false

Reimplemented in UnregisteredLocalFile, LocalFile, and ForeignAPIFile.

Definition at line 729 of file File.php.

◆ getMetadataArray()

File::getMetadataArray ( )

Get the unserialized handler-specific metadata STUB.

Since
1.37
Returns
array

Reimplemented in UnregisteredLocalFile, LocalFile, and ForeignAPIFile.

Definition at line 747 of file File.php.

Referenced by SvgHandler\getAvailableLanguages(), SvgHandler\getCommonMetaArray(), GIFHandler\getCommonMetaArray(), and PNGHandler\getCommonMetaArray().

◆ getMetadataItem()

File::getMetadataItem ( string  $itemName)

Get a specific element of the unserialized handler-specific metadata.

Since
1.37
Parameters
string$itemName
Returns
mixed

Definition at line 758 of file File.php.

◆ getMetadataItems()

File::getMetadataItems ( array  $itemNames)

Get multiple elements of the unserialized handler-specific metadata.

Since
1.37
Parameters
string[]$itemNames
Returns
array

Reimplemented in LocalFile.

Definition at line 770 of file File.php.

◆ getMimeType()

File::getMimeType ( )

Returns the MIME type of the file.

Overridden by LocalFile, UnregisteredLocalFile STUB

Stability: stable
to override
Returns
string

Reimplemented in UnregisteredLocalFile, LocalFile, and ForeignAPIFile.

Definition at line 838 of file File.php.

Referenced by checkExtensionCompatibility(), and getViewURL().

◆ getName()

File::getName ( )

Return the name of this file.

Stability: stable
to override
Returns
string

Definition at line 332 of file File.php.

References $name, and assertRepoDefined().

Referenced by compare(), LocalFile\getCacheKey(), ForeignDBFile\getDescriptionText(), getExtension(), getViewURL(), LocalFile\loadExtraFieldsWithTimestamp(), LocalFile\loadFromDB(), ForeignAPIFile\transform(), and LocalFile\upgradeRow().

◆ getOriginalTitle()

File::getOriginalTitle ( )

Return the title used to find this file.

Returns
Title

Definition at line 371 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.

Stability: stable
to override
Returns
string|bool ForeignAPIFile::getPath can return false

Reimplemented in ForeignAPIFile.

Definition at line 458 of file File.php.

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

Referenced by getLocalRefPath().

◆ getRedirected()

File::getRedirected ( )
Returns
string

Definition at line 2414 of file File.php.

◆ getRedirectedTitle()

File::getRedirectedTitle ( )
protected
Returns
Title|null

Definition at line 2421 of file File.php.

References Title\makeTitle(), 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().

Stability: stable
to override
Returns
string

Reimplemented in OldLocalFile.

Definition at line 1700 of file File.php.

Referenced by getPath().

◆ getRepo()

File::getRepo ( )

Returns the repository.

Stability: stable
to override
Returns
FileRepo|bool

Reimplemented in LocalFile, ForeignDBFile, and ForeignAPIFile.

Definition at line 2046 of file File.php.

◆ getRepoName()

File::getRepoName ( )

Returns the name of the repository.

Returns
string

Definition at line 2036 of file File.php.

◆ getSha1()

File::getSha1 ( )

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

Stability: stable
to override
Returns
string|false

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 2327 of file File.php.

◆ getShortDesc()

File::getShortDesc ( )
Returns
string

Definition at line 2390 of file File.php.

References MediaHandler\getGeneralShortDesc(), and MediaHandler\getShortDesc().

◆ getSize()

File::getSize ( )

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

Stability: stable
to override
Returns
int|false

Reimplemented in UnregisteredLocalFile, LocalFile, and ForeignAPIFile.

Definition at line 826 of file File.php.

◆ getStorageKey()

File::getStorageKey ( )

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

Returns
string|false

Definition at line 2338 of file File.php.

References $ext.

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

References FileBackend\extensionFromPath(), and FileBackend\makeContentDisposition().

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

References getWidth().

◆ getThumbnails()

File::getThumbnails ( )
protected

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

Stability: stable
to override
Returns
string[]

Reimplemented in ForeignAPIFile.

Definition at line 1588 of file File.php.

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

References PoolCounterWork\execute().

◆ getThumbPath()

File::getThumbPath (   $suffix = false)

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

Stability: stable
to override
Parameters
bool | string$suffixIf not false, the name of a thumbnail file
Returns
string

Reimplemented in UploadStashFile, and ForeignAPIFile.

Definition at line 1801 of file File.php.

◆ 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.

Stability: stable
to override
Parameters
bool | string$suffixIf not false, the name of a thumbnail file
Returns
string

Definition at line 1731 of file File.php.

References $path.

◆ getThumbUrl()

File::getThumbUrl (   $suffix = false)

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

Stability: stable
to override
Parameters
bool | string$suffixIf not false, the name of a thumbnail file
Returns
string Path

Reimplemented in UploadStashFile.

Definition at line 1884 of file File.php.

◆ getThumbVirtualUrl()

File::getThumbVirtualUrl (   $suffix = false)

Get the virtual URL for a thumbnail file or directory.

Stability: stable
to override
Parameters
bool | string$suffixIf not false, the name of a thumbnail file
Returns
string

Definition at line 1957 of file File.php.

References $path.

◆ getTimestamp()

File::getTimestamp ( )

Get the 14-character timestamp of the file upload.

Stability: stable
to override
Returns
string|bool TS_MW timestamp or false on failure

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 2303 of file File.php.

◆ getTitle()

File::getTitle ( )

Return the associated title object.

Returns
Title

Definition at line 362 of file File.php.

References $title.

Referenced by SpecialFileDuplicateSearch\doBatchLookups().

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

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

◆ getTransformScript()

File::getTransformScript ( )
private
Returns
string|false

Definition at line 1030 of file File.php.

References wfAppendQuery().

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

◆ getUploader()

File::getUploader ( int  $audience = self::FOR_PUBLIC,
Authority  $performer = null 
)

Get the identity of the file uploader.

Note
if the file does not exist, this will return null regardless of the permissions.
Stability: stable
to override
Since
1.37
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
Authority | null$performerto check for, only if FOR_THIS_USER is passed to the $audience parameter
Returns
UserIdentity|null

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 2276 of file File.php.

Referenced by SpecialFileDuplicateSearch\doBatchLookups().

◆ getUrl()

File::getUrl ( )

Return the URL of the file.

Stability: stable
to override
Returns
string

Reimplemented in UploadStashFile, and ForeignAPIFile.

Definition at line 385 of file File.php.

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

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

◆ 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().

Stability: stable
to override
Returns
string

Reimplemented in OldLocalFile.

Definition at line 1747 of file File.php.

Referenced by getUrl().

◆ getViewURL()

File::getViewURL ( )
Returns
string

Definition at line 429 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.

Stability: stable
to override
Parameters
bool | string$suffixIf not false, the name of a thumbnail file
Returns
string

Definition at line 1921 of file File.php.

References $path.

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

◆ getVisibility()

File::getVisibility ( )

Return the deletion bitfield STUB.

Stability: stable
to override
Returns
int

Reimplemented in OldLocalFile.

Definition at line 2079 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

Stability: stable
to override
Parameters
int$page
Returns
int|bool

Reimplemented in UnregisteredLocalFile, LocalFile, and ForeignAPIFile.

Definition at line 505 of file File.php.

Referenced by getDisplayWidthHeight(), getThumbnailBucket(), and getViewURL().

◆ getZoneUrl()

File::getZoneUrl (   $zone,
  $suffix = false 
)
private

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

References $ext, and $path.

◆ iconThumb()

File::iconThumb ( )

Get a ThumbnailImage representing a file type icon.

Returns
ThumbnailImage|null

Definition at line 1553 of file File.php.

References $IP.

◆ isCacheable()

File::isCacheable ( )

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

Stability: stable
to override
Returns
bool

Reimplemented in LocalFile.

Definition at line 2454 of file File.php.

◆ isDeleted()

File::isDeleted (   $field)

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

Stability: stable
to override
Parameters
int$fieldOne of DELETED_* bitfield constants
Returns
bool

Reimplemented in OldLocalFile.

Definition at line 2069 of file File.php.

◆ isExpensiveToThumbnail()

File::isExpensiveToThumbnail ( )

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

Returns
bool

Definition at line 2482 of file File.php.

References MediaHandler\isExpensiveToThumbnail().

◆ isHashed()

File::isHashed ( )
protected
Returns
bool

Definition at line 1970 of file File.php.

◆ isLocal()

File::isLocal ( )

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

Returns
bool

Definition at line 2027 of file File.php.

Referenced by SpecialFileDuplicateSearch\doBatchLookups().

◆ isMissing()

File::isMissing ( )
Stability: stable
to override
Returns
bool

Reimplemented in LocalFile.

Definition at line 2445 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.

Stability: stable
to override
Returns
bool

Definition at line 2159 of file File.php.

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

◆ isOld()

File::isOld ( )

Returns true if the image is an old version STUB.

Stability: stable
to override
Returns
bool

Reimplemented in OldLocalFile.

Definition at line 2057 of file File.php.

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

◆ isTransformedLocally()

File::isTransformedLocally ( )

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

Since
1.25
Stability: stable
to override
Returns
bool

Reimplemented in ForeignAPIFile.

Definition at line 2493 of file File.php.

◆ isTrustedFile()

File::isTrustedFile ( )
protected

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 cryptographic signatures or such.

Returns
bool

Definition at line 985 of file File.php.

◆ isVectorized()

File::isVectorized ( )

Return true if the file is vectorized.

Returns
bool

Definition at line 630 of file File.php.

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

◆ 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

Stability: stable
to override
Returns
bool Whether file exists in the repository and is includable.

Reimplemented in OldLocalFile.

Definition at line 1023 of file File.php.

◆ 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

Stability: stable
to override
Parameters
int$flagsBitfield of File::READ_* constants

Reimplemented in LocalFile.

Definition at line 1001 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 1504 of file File.php.

References FileBackend\extensionFromPath().

◆ migrateThumbFile()

File::migrateThumbFile (   $thumbName)
protected

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

Stability: stable
to override
Parameters
string$thumbName

Definition at line 1531 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

Stability: stable
to override
Parameters
Title$targetNew file name
Returns
Status

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 2107 of file File.php.

◆ 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.

Stability: stable
to override
Returns
bool

Definition at line 893 of file File.php.

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

Stability: stable
to override Overridden in LocalFile
Returns
bool

Reimplemented in LocalFile.

Definition at line 1663 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 256 of file File.php.

References $extension.

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

Definition at line 207 of file File.php.

References $title, Title\castFromLinkTarget(), Title\castFromPageIdentity(), Title\makeTitleSafe(), NS_FILE, and NS_MEDIA.

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

◆ pageCount()

File::pageCount ( )

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

Stability: stable
to override
Returns
int|false

Definition at line 2170 of file File.php.

◆ 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 recordUpload3 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

Stability: stable
to override

Reimplemented in ForeignDBFile, and LocalFile.

Definition at line 2006 of file File.php.

◆ purgeCache()

File::purgeCache (   $options = [])

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

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

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1600 of file File.php.

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

References $title, and getTitle().

◆ purgeEverything()

File::purgeEverything ( )

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

Definition at line 1621 of file File.php.

References $job, $title, getTitle(), and HTMLCacheUpdateJob\newForBacklinks().

◆ readOnlyError()

File::readOnlyError ( )
protected
Exceptions
MWException
Returns
never

Definition at line 1980 of file File.php.

Referenced by ForeignDBFile\deleteFile(), ForeignDBFile\move(), ForeignDBFile\publish(), and ForeignDBFile\restore().

◆ redirectedFrom()

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

Definition at line 2437 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.

Stability: stable
to override

Reimplemented in LocalFile.

Definition at line 1674 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
int[]$versionsSet of record ids of deleted items to restore, or empty to restore all revisions.
bool$unsuppressRemove restrictions on content upon restoration?
Returns
Status STUB Overridden by LocalFile
Stability: stable
to override

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 2147 of file File.php.

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

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

◆ setHandlerState()

File::setHandlerState ( string  $key,
  $value 
)

Set a value.

Parameters
string$key
mixed$value

Implements MediaHandlerState.

Definition at line 737 of file File.php.

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

References $mime.

Referenced by SpecialMIMESearch\execute(), LocalFileRestoreBatch\execute(), RefreshImageMetadata\getConditions(), MWFileProps\getPropsFromPath(), ApiQueryAllImages\run(), LocalFile\setProps(), and LocalFile\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>".

Stability: stable
to override
Parameters
array$paramsHandler-specific parameters
int$flagsBitfield that supports THUMB_* constants
Returns
string|null

Reimplemented in UploadStashFile.

Definition at line 1075 of file File.php.

◆ transform()

File::transform (   $params,
  $flags = 0 
)

Transform a media file.

Stability: stable
to override
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 1174 of file File.php.

References MediaHandler\getScriptedTransform(), MediaHandler\getTransform(), MediaHandler\normaliseParams(), PROTO_CANONICAL, wfDebug(), wfExpandUrl(), and wfMessage().

Referenced by SpecialFileDuplicateSearch\execute().

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

References MediaHandler\getTransform(), and wfMessage().

◆ upgradeRow()

File::upgradeRow ( )

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

Stability: stable
to override

Reimplemented in OldLocalFile, and LocalFile.

Definition at line 297 of file File.php.

◆ userCan()

File::userCan (   $field,
Authority  $performer 
)

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

STUB

Stability: stable
to override
Parameters
int$field
Authority$performeruser object to check
Returns
bool

Reimplemented in OldLocalFile.

Definition at line 2358 of file File.php.

◆ wasDeleted()

File::wasDeleted ( )

Was this file ever deleted from the wiki?

Returns
bool

Definition at line 2088 of file File.php.

References $title, and getTitle().

Referenced by UploadBase\checkLocalFileWasDeleted().

Member Data Documentation

◆ $canRender

bool File::$canRender
protected

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

Definition at line 162 of file File.php.

◆ $extension

string File::$extension
protected

File extension.

Definition at line 139 of file File.php.

Referenced by getExtension(), and normalizeExtension().

◆ $fsFile

FSFile bool File::$fsFile
protected

False if undefined.

Definition at line 130 of file File.php.

◆ $handler

◆ $handlerState

array File::$handlerState = []
private

Definition at line 176 of file File.php.

◆ $hashPath

string null File::$hashPath
protected

Relative path including trailing slash.

Definition at line 148 of file File.php.

◆ $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 167 of file File.php.

◆ $lastError

string File::$lastError
protected

Text of last error.

Definition at line 121 of file File.php.

◆ $name

string null File::$name
protected

The name of a file from its title object.

Definition at line 142 of file File.php.

Referenced by UnregisteredLocalFile\__construct(), __get(), getName(), and LocalFile\unprefixRow().

◆ $pageCount

int false File::$pageCount
protected

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

Definition at line 153 of file File.php.

◆ $path

string File::$path
protected

The storage path corresponding to one of the zones.

Definition at line 145 of file File.php.

Referenced by getPath(), and LocalFile\loadFromFile().

◆ $redirected

string File::$redirected
protected

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

Definition at line 124 of file File.php.

◆ $redirectedTitle

Title File::$redirectedTitle
protected

Definition at line 127 of file File.php.

◆ $redirectTitle

Title File::$redirectTitle
protected

Definition at line 159 of file File.php.

◆ $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 115 of file File.php.

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

◆ $repoClass

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

Required Repository class type.

Definition at line 170 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 173 of file File.php.

◆ $transformScript

string false File::$transformScript
protected

URL of transformscript (for example thumb.php)

Definition at line 156 of file File.php.

◆ $url

string File::$url
protected

The URL corresponding to one of the four basic zones.

Definition at line 136 of file File.php.

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

◆ DELETE_SOURCE

const File::DELETE_SOURCE = 1

Definition at line 85 of file File.php.

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

◆ DELETED_COMMENT

◆ DELETED_FILE

◆ DELETED_RESTRICTED

◆ DELETED_USER

const File::DELETED_USER = 4

◆ FOR_PUBLIC

const File::FOR_PUBLIC = 1

Definition at line 88 of file File.php.

Referenced by ApiQueryDuplicateFiles\run(), and XmlDumpWriter\writeUpload().

◆ FOR_THIS_USER

◆ RAW

const File::RAW = 3

Definition at line 90 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 83 of file File.php.

◆ RENDER_NOW

const File::RENDER_NOW = 1

Force rendering in the current process.

Definition at line 78 of file File.php.

Referenced by SpecialUploadStash\outputLocallyScaledThumb(), ThumbnailRenderJob\run(), and wfGenerateThumbnail().

◆ THUMB_FULL_NAME

const File::THUMB_FULL_NAME = 1

Definition at line 93 of file File.php.

Referenced by wfStreamThumb().


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