MediaWiki master
MediaWiki\FileRepo\File\File Class Reference

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

Inherits MediaWiki\Media\MediaHandlerState.

Inherited by MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\UnregisteredLocalFile.

Collaboration diagram for MediaWiki\FileRepo\File\File:

Public Member Functions

 __construct ( $title, $repo)
 Call this constructor from child classes.
 
 __get ( $name)
 
 addToShellboxCommand (BoxedCommand $command, string $boxedName)
 Add the file to a Shellbox command as an input file.
 
 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.
 
 deleteFile ( $reason, UserIdentity $user, $suppress=false)
 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.
 
 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 IETF 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, ?Authority $performer=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 ()
 
 getDisplayWidthHeight ( $maxWidth, $maxHeight, $page=1)
 Get the width and height to display image at.
 
 getExtension ()
 Get the file extension, e.g.
 
 getFilePageThumbUrl ( $url)
 Append a version parameter to the end of a file URL Only to be used on File pages.
 
 getFullUrl ()
 Return a fully-qualified URL to the file.
 
 getHandler ()
 Get a MediaHandler instance for this file.
 
 getHandlerState (string $key)
 Get a value, or null if it does not exist.
Parameters
string$key
Returns
mixed|null

 
 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.
 
 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 ()
 Long description.
 
 getMatchedLanguage ( $userPreferredLanguage)
 Get the IETF 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.
 
 getMetadataArray ()
 Get the unserialized handler-specific metadata STUB.
 
 getMetadataItem (string $itemName)
 Get a specific element of the unserialized handler-specific metadata.
 
 getMetadataItems (array $itemNames)
 Get multiple elements of the unserialized handler-specific metadata.
 
 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 ()
 
 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 ()
 Short description.
 
 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.
 
 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.
 
 getUnscaledThumb ( $handlerParams=[])
 Get a ThumbnailImage which is the same size as the source.
 
 getUploader (int $audience=self::FOR_PUBLIC, ?Authority $performer=null)
 Get the identity of the file uploader.
 
 getUrl ()
 Return the URL of the file.
 
 getUrlRel ()
 Get urlencoded path of the file relative to the public zone root.
 
 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.
 
 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.
 
 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.
 
 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.
 
 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.
 
 redirectedFrom (string $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.
 
 setHandlerState (string $key, $value)
 Set a value.
Parameters
string$key
mixed$value

 
 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, Authority $performer)
 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 (?string $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 false $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
 

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.
 
 getRedirectedTitle ()
 
 getThumbnails ()
 Get all thumbnail names previously generated for this file STUB Overridden by LocalFile.
 
 isHashed ()
 
 isTrustedFile ()
 Returns true if the file is flagged as trusted.
 
 makeTransformTmpFile ( $thumbPath)
 Creates a temp FS file with the same extension and the thumbnail.
 
 readOnlyError ()
 
 transformErrorOutput ( $thumbPath, $thumbUrl, $params, $flags)
 Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors)
 

Protected Attributes

bool null $canRender
 Whether the output of transform() for this file is likely to be valid.
 
string null $extension
 File extension.
 
FSFile false null $fsFile
 False if undefined.
 
MediaHandler null $handler
 
string null $hashPath
 Relative path including trailing slash.
 
bool null $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 null $name
 The name of a file from its title object.
 
int false null $pageCount
 Number of pages of a multipage document, or false for documents which aren't multipage documents.
 
string null $path
 The storage path corresponding to one of the zones.
 
string $redirected
 The name that was used to access the file, before resolving redirects.
 
Title $redirectedTitle
 
Title $redirectTitle
 
string $repoClass = FileRepo::class
 Required Repository class type.
 
Title string false $title
 
array $tmpBucketedThumbCache = []
 Cache of tmp filepaths pointing to generated bucket thumbnails, keyed by width.
 
string false null $transformScript
 URL of transformscript (for example thumb.php)
 
string null $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 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 79 of file File.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\FileRepo\File\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 | false$title
FileRepo | false$repo

Reimplemented in MediaWiki\FileRepo\File\LocalFile.

Definition at line 203 of file File.php.

References MediaWiki\FileRepo\File\File\$repo, MediaWiki\FileRepo\File\File\$title, and MediaWiki\FileRepo\File\File\normalizeTitle().

Member Function Documentation

◆ __get()

MediaWiki\FileRepo\File\File::__get ( $name)

Definition at line 250 of file File.php.

References MediaWiki\FileRepo\File\File\$name.

◆ addToShellboxCommand()

MediaWiki\FileRepo\File\File::addToShellboxCommand ( BoxedCommand $command,
string $boxedName )

Add the file to a Shellbox command as an input file.

Since
1.43
Parameters
BoxedCommand$command
string$boxedName
Returns
StatusValue

Definition at line 520 of file File.php.

References MediaWiki\FileRepo\File\File\getVirtualUrl().

◆ allowInlineDisplay()

MediaWiki\FileRepo\File\File::allowInlineDisplay ( )

Alias for canRender()

Returns
bool

Definition at line 926 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\canAnimateThumbIfAppropriate().

◆ assertRepoDefined()

MediaWiki\FileRepo\File\File::assertRepoDefined ( )
protected

◆ assertTitleDefined()

MediaWiki\FileRepo\File\File::assertTitleDefined ( )
protected

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

Definition at line 2557 of file File.php.

◆ canAnimateThumbIfAppropriate()

MediaWiki\FileRepo\File\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 733 of file File.php.

References MediaWiki\FileRepo\File\File\$handler, MediaWiki\FileRepo\File\File\allowInlineDisplay(), MediaWiki\Media\MediaHandler\canAnimateThumbnail(), MediaWiki\FileRepo\File\File\getHandler(), and MediaWiki\Media\MediaHandler\isAnimatedImage().

◆ canRender()

MediaWiki\FileRepo\File\File::canRender ( )

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

In other words, this will return true if a thumbnail can be provided for this image (e.g. if [[File:...|thumb]] produces a result on a wikitext page).

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

Returns
bool

Definition at line 890 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getViewURL(), and MediaWiki\FileRepo\File\ForeignAPIFile\transform().

◆ checkExtensionCompatibility()

static MediaWiki\FileRepo\File\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 294 of file File.php.

References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\FileRepo\File\File\getMimeType(), and MediaWiki\FileRepo\File\File\normalizeExtension().

◆ compare()

static MediaWiki\FileRepo\File\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 337 of file File.php.

References MediaWiki\FileRepo\File\File\getName().

◆ convertMetadataVersion()

MediaWiki\FileRepo\File\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 825 of file File.php.

◆ createThumb()

MediaWiki\FileRepo\File\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 1216 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getViewURL().

◆ deleteFile()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignDBFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 2201 of file File.php.

◆ exists()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\LocalFile, MediaWiki\FileRepo\File\OldLocalFile, and MediaWiki\Upload\UploadStashFile.

Definition at line 1036 of file File.php.

Referenced by MediaWiki\Api\ApiDelete\canDeleteFile(), MediaWiki\FileRepo\LocalRepo\findFiles(), MediaWiki\Rest\Handler\MediaFileHandler\hasRepresentation(), and MediaWiki\Output\OutputPage\setFileVersion().

◆ formatMetadata()

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

Definition at line 2089 of file File.php.

◆ generateAndSaveThumb()

MediaWiki\FileRepo\File\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
MediaTransformOutput|false

Definition at line 1365 of file File.php.

References wfDebug(), and wfMessage().

◆ generateBucketsIfNeeded()

MediaWiki\FileRepo\File\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 1451 of file File.php.

◆ generateThumbName()

MediaWiki\FileRepo\File\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 1115 of file File.php.

Referenced by MediaWiki\Upload\UploadStashFile\thumbName().

◆ getArchivePath()

MediaWiki\FileRepo\File\File::getArchivePath ( $suffix = false)

Get the path of the archived file.

Parameters
string | false$suffixIf not false, the name of an archived file.
Returns
string

Definition at line 1853 of file File.php.

◆ getArchiveRel()

MediaWiki\FileRepo\File\File::getArchiveRel ( $suffix = false)

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

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

Definition at line 1791 of file File.php.

References $path.

◆ getArchiveThumbPath()

MediaWiki\FileRepo\File\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
string | false$suffixIf not false, the name of a thumbnail file
Returns
string

Definition at line 1866 of file File.php.

◆ getArchiveThumbUrl()

MediaWiki\FileRepo\File\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
string | false$suffixIf not false, the name of a thumbnail file
Returns
string

Definition at line 1926 of file File.php.

References $path.

◆ getArchiveUrl()

MediaWiki\FileRepo\File\File::getArchiveUrl ( $suffix = false)

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

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

Definition at line 1905 of file File.php.

References $path.

◆ getArchiveVirtualUrl()

MediaWiki\FileRepo\File\File::getArchiveVirtualUrl ( $suffix = false)

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

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

Definition at line 2017 of file File.php.

References $path.

◆ getAvailableLanguages()

MediaWiki\FileRepo\File\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 679 of file File.php.

References MediaWiki\FileRepo\File\File\$handler, MediaWiki\Media\MediaHandler\getAvailableLanguages(), and MediaWiki\FileRepo\File\File\getHandler().

◆ getBitDepth()

MediaWiki\FileRepo\File\File::getBitDepth ( )

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

Stability: stable
to override
Returns
int

Reimplemented in MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\UnregisteredLocalFile.

Definition at line 841 of file File.php.

◆ getBucketThumbName()

MediaWiki\FileRepo\File\File::getBucketThumbName ( $bucket)
protected

Returns the name of the thumb for a given bucket.

Parameters
int$bucket
Returns
string

Definition at line 1583 of file File.php.

◆ getBucketThumbPath()

MediaWiki\FileRepo\File\File::getBucketThumbPath ( $bucket)
protected

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

Parameters
int$bucket
Returns
string

Definition at line 1573 of file File.php.

◆ getCanonicalUrl()

MediaWiki\FileRepo\File\File::getCanonicalUrl ( )
Stability: stable
to override
Returns
string

Definition at line 438 of file File.php.

References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\FileRepo\File\File\getUrl(), and PROTO_CANONICAL.

◆ getCanRender()

MediaWiki\FileRepo\File\File::getCanRender ( )
protected

Accessor for __get()

Returns
bool

Definition at line 902 of file File.php.

◆ getCommonMetaArray()

MediaWiki\FileRepo\File\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 813 of file File.php.

◆ getContentHeaders()

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

Definition at line 2438 of file File.php.

◆ getDefaultRenderLanguage()

MediaWiki\FileRepo\File\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 714 of file File.php.

References MediaWiki\FileRepo\File\File\$handler, MediaWiki\Media\MediaHandler\getDefaultRenderLanguage(), and MediaWiki\FileRepo\File\File\getHandler().

◆ getDescription()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignAPIFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 2365 of file File.php.

◆ getDescriptionShortUrl()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\ForeignDBFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 417 of file File.php.

◆ getDescriptionText()

MediaWiki\FileRepo\File\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

Reimplemented in MediaWiki\FileRepo\File\ForeignDBFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 2295 of file File.php.

References $wgLang, and wfDebug().

◆ getDescriptionTouched()

MediaWiki\FileRepo\File\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|false

Reimplemented in MediaWiki\FileRepo\File\LocalFile.

Definition at line 2389 of file File.php.

◆ getDescriptionUrl()

MediaWiki\FileRepo\File\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|false

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\ForeignDBFile, MediaWiki\FileRepo\File\LocalFile, and MediaWiki\Upload\UploadStashFile.

Definition at line 2279 of file File.php.

Referenced by MediaWiki\Page\ImagePage\imageDupes().

◆ getDimensionsString()

MediaWiki\FileRepo\File\File::getDimensionsString ( )
Returns
string plain text

Definition at line 2488 of file File.php.

◆ getDisplayWidthHeight()

MediaWiki\FileRepo\File\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
Returns
array Array (width, height)
Since
1.35

Definition at line 609 of file File.php.

References MediaWiki\FileRepo\File\File\getHeight(), and MediaWiki\FileRepo\File\File\getWidth().

◆ getExtension()

MediaWiki\FileRepo\File\File::getExtension ( )

Get the file extension, e.g.

"svg"

Stability: stable
to override
Returns
string

Definition at line 362 of file File.php.

References MediaWiki\FileRepo\File\File\$extension, MediaWiki\FileRepo\File\File\getName(), and MediaWiki\FileRepo\File\File\normalizeExtension().

Referenced by MediaWiki\FileRepo\File\File\getUrl().

◆ getFilePageThumbUrl()

MediaWiki\FileRepo\File\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 1975 of file File.php.

References $url, and wfAppendQuery().

◆ getFullUrl()

MediaWiki\FileRepo\File\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 MediaWiki\Upload\UploadStashFile.

Definition at line 429 of file File.php.

References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\FileRepo\File\File\getUrl(), and PROTO_RELATIVE.

◆ getHandler()

◆ getHandlerState()

MediaWiki\FileRepo\File\File::getHandlerState ( string $key)

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

Parameters
string$key
Returns
mixed|null

Implements MediaWiki\Media\MediaHandlerState.

Definition at line 763 of file File.php.

◆ getHashPath()

MediaWiki\FileRepo\File\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 1763 of file File.php.

◆ getHeight()

MediaWiki\FileRepo\File\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
int|false False on failure

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\UnregisteredLocalFile.

Definition at line 550 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getDisplayWidthHeight(), and MediaWiki\Media\SvgHandler\getLongDesc().

◆ getHistory()

MediaWiki\FileRepo\File\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[] Guaranteed to be in descending order

Reimplemented in MediaWiki\FileRepo\File\LocalFile.

Definition at line 1728 of file File.php.

◆ getIsSafeFile()

MediaWiki\FileRepo\File\File::getIsSafeFile ( )
protected

Accessor for __get()

Returns
bool

Definition at line 956 of file File.php.

◆ getIsSafeFileUncached()

MediaWiki\FileRepo\File\File::getIsSafeFileUncached ( )
protected

Uncached accessor.

Returns
bool

Definition at line 965 of file File.php.

References MEDIATYPE_UNKNOWN.

◆ getLastError()

MediaWiki\FileRepo\File\File::getLastError ( )

Get last thumbnailing error.

Largely obsolete.

Returns
string

Definition at line 1656 of file File.php.

◆ getLength()

MediaWiki\FileRepo\File\File::getLength ( )

Get the duration of a media file in seconds.

Stability: stable
to override
Returns
float|int

Definition at line 645 of file File.php.

References MediaWiki\FileRepo\File\File\$handler, MediaWiki\FileRepo\File\File\getHandler(), and MediaWiki\Media\MediaHandler\getLength().

◆ getLocalRefPath()

MediaWiki\FileRepo\File\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|false False on failure

Definition at line 491 of file File.php.

References MediaWiki\FileRepo\File\File\assertRepoDefined(), MediaWiki\MediaWikiServices\getInstance(), and MediaWiki\FileRepo\File\File\getPath().

◆ getLongDesc()

MediaWiki\FileRepo\File\File::getLongDesc ( )

Long description.

Shown under image on image description page surrounded by ().

Until MediaWiki 1.45, the return value was poorly documented, and some handlers returned HTML while others returned plain text. When calling this method, you should treat it as returning unsafe HTML, and call Sanitizer::removeSomeTags() on the result.

Returns
string HTML (possibly unsafe, call Sanitizer::removeSomeTags() on the result)

Definition at line 2457 of file File.php.

◆ getMatchedLanguage()

MediaWiki\FileRepo\File\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 695 of file File.php.

References MediaWiki\FileRepo\File\File\$handler, MediaWiki\Media\MediaHandler\getAvailableLanguages(), MediaWiki\FileRepo\File\File\getHandler(), and MediaWiki\Media\MediaHandler\getMatchedLanguage().

◆ getMediaType()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignAPIFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 876 of file File.php.

References MEDIATYPE_UNKNOWN.

◆ getMetadata()

MediaWiki\FileRepo\File\File::getMetadata ( )

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

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

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\UnregisteredLocalFile.

Definition at line 758 of file File.php.

◆ getMetadataArray()

◆ getMetadataItem()

MediaWiki\FileRepo\File\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 789 of file File.php.

◆ getMetadataItems()

MediaWiki\FileRepo\File\File::getMetadataItems ( array $itemNames)

Get multiple elements of the unserialized handler-specific metadata.

Since
1.37
Parameters
string[]$itemNames
Returns
array

Reimplemented in MediaWiki\FileRepo\File\LocalFile.

Definition at line 801 of file File.php.

◆ getMimeType()

MediaWiki\FileRepo\File\File::getMimeType ( )

Returns the MIME type of the file.

Overridden by LocalFile, UnregisteredLocalFile STUB

Stability: stable
to override
Returns
string

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\UnregisteredLocalFile.

Definition at line 864 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\checkExtensionCompatibility(), and MediaWiki\FileRepo\File\File\getViewURL().

◆ getName()

◆ getOriginalTitle()

MediaWiki\FileRepo\File\File::getOriginalTitle ( )

Return the title used to find this file.

Returns
Title

Definition at line 386 of file File.php.

References MediaWiki\FileRepo\File\File\$title, and MediaWiki\FileRepo\File\File\getRedirectedTitle().

◆ getPath()

MediaWiki\FileRepo\File\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|false ForeignAPIFile::getPath can return false

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile.

Definition at line 475 of file File.php.

References MediaWiki\FileRepo\File\File\$path, MediaWiki\FileRepo\File\File\assertRepoDefined(), and MediaWiki\FileRepo\File\File\getRel().

Referenced by MediaWiki\FileRepo\File\File\getLocalRefPath().

◆ getRedirected()

MediaWiki\FileRepo\File\File::getRedirected ( )
Returns
?string The name that was used to access the file, before resolving redirects.

Definition at line 2501 of file File.php.

Referenced by MediaWiki\Api\ApiDelete\canDeleteFile().

◆ getRedirectedTitle()

MediaWiki\FileRepo\File\File::getRedirectedTitle ( )
protected
Returns
Title|null

Definition at line 2508 of file File.php.

References NS_FILE.

Referenced by MediaWiki\FileRepo\File\File\getOriginalTitle().

◆ getRel()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\OldLocalFile.

Definition at line 1779 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getPath().

◆ getRepo()

MediaWiki\FileRepo\File\File::getRepo ( )

Returns the repository.

Stability: stable
to override
Returns
FileRepo|false

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\ForeignDBFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 2118 of file File.php.

Referenced by MediaWiki\FileRepo\ThumbnailEntryPoint\generateThumbnail(), and MediaWiki\Page\ImagePage\imageDupes().

◆ getRepoName()

MediaWiki\FileRepo\File\File::getRepoName ( )

Returns the name of the repository.

Returns
string

Definition at line 2108 of file File.php.

◆ getSha1()

MediaWiki\FileRepo\File\File::getSha1 ( )

◆ getShortDesc()

MediaWiki\FileRepo\File\File::getShortDesc ( )

Short description.

Shown on Special:Search results.

Until MediaWiki 1.45, the return value was poorly documented, and some handlers returned HTML while others returned plain text. When calling this method, you should treat it as returning unsafe HTML, and call Sanitizer::removeSomeTags() on the result.

Returns
string HTML (possibly unsafe, call Sanitizer::removeSomeTags() on the result)

Definition at line 2476 of file File.php.

◆ getSize()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\UnregisteredLocalFile.

Definition at line 852 of file File.php.

Referenced by MediaWiki\Media\SvgHandler\getLongDesc().

◆ getStorageKey()

MediaWiki\FileRepo\File\File::getStorageKey ( )

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

Returns
string|false

Definition at line 2410 of file File.php.

◆ getThumbDisposition()

MediaWiki\FileRepo\File\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 1603 of file File.php.

◆ getThumbnailBucket()

MediaWiki\FileRepo\File\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
int|false

Definition at line 563 of file File.php.

References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\FileRepo\File\File\getWidth(), MediaWiki\MainConfigNames\ThumbnailBuckets, and MediaWiki\MainConfigNames\ThumbnailMinimumBucketDistance.

◆ getThumbnails()

MediaWiki\FileRepo\File\File::getThumbnails ( )
protected

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

Stability: stable
to override
Returns
string[]

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile.

Definition at line 1667 of file File.php.

◆ getThumbnailSource()

MediaWiki\FileRepo\File\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 1507 of file File.php.

◆ getThumbPath()

MediaWiki\FileRepo\File\File::getThumbPath ( $suffix = false)

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

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

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile, and MediaWiki\Upload\UploadStashFile.

Definition at line 1880 of file File.php.

◆ getThumbRel()

MediaWiki\FileRepo\File\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
string | false$suffixIf not false, the name of a thumbnail file
Returns
string

Definition at line 1810 of file File.php.

References $path.

◆ getThumbUrl()

MediaWiki\FileRepo\File\File::getThumbUrl ( $suffix = false)

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

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

Reimplemented in MediaWiki\Upload\UploadStashFile.

Definition at line 1963 of file File.php.

Referenced by MediaWiki\JobQueue\Jobs\ThumbnailRenderJob\hitThumbUrl().

◆ getThumbVirtualUrl()

MediaWiki\FileRepo\File\File::getThumbVirtualUrl ( $suffix = false)

Get the virtual URL for a thumbnail file or directory.

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

Definition at line 2036 of file File.php.

References $path.

◆ getTimestamp()

MediaWiki\FileRepo\File\File::getTimestamp ( )

Get the 14-character timestamp of the file upload.

Stability: stable
to override
Returns
string|false TS::MW timestamp or false on failure

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 2375 of file File.php.

Referenced by MediaWiki\FileRepo\LocalRepo\findFiles(), and MediaWiki\Media\FormatMetadata\getExtendedMetadataFromFile().

◆ getTitle()

MediaWiki\FileRepo\File\File::getTitle ( )

◆ getTranscodedPath()

MediaWiki\FileRepo\File\File::getTranscodedPath ( $suffix = false)

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

Parameters
string | false$suffixIf not false, the name of a media file
Returns
string

Definition at line 1892 of file File.php.

◆ getTranscodedUrl()

MediaWiki\FileRepo\File\File::getTranscodedUrl ( $suffix = false)

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

Parameters
string | false$suffixIf not false, the name of a media file
Returns
string Path

Definition at line 1989 of file File.php.

◆ getUnscaledThumb()

MediaWiki\FileRepo\File\File::getUnscaledThumb ( $handlerParams = [])

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

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

Definition at line 1075 of file File.php.

◆ getUploader()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignAPIFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 2348 of file File.php.

Referenced by MediaWiki\Upload\UploadBase\userCanReUpload().

◆ getUrl()

◆ getUrlRel()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\OldLocalFile.

Definition at line 1826 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getUrl().

◆ getViewURL()

◆ getVirtualUrl()

MediaWiki\FileRepo\File\File::getVirtualUrl ( $suffix = false)

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

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

Definition at line 2000 of file File.php.

References $path.

Referenced by MediaWiki\FileRepo\File\File\addToShellboxCommand().

◆ getVisibility()

MediaWiki\FileRepo\File\File::getVisibility ( )

Return the deletion bitfield STUB.

Stability: stable
to override
Returns
int

Reimplemented in MediaWiki\FileRepo\File\OldLocalFile.

Definition at line 2151 of file File.php.

◆ getWidth()

MediaWiki\FileRepo\File\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|false

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile, MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\UnregisteredLocalFile.

Definition at line 535 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getDisplayWidthHeight(), MediaWiki\Media\SvgHandler\getLongDesc(), MediaWiki\FileRepo\File\File\getThumbnailBucket(), and MediaWiki\FileRepo\File\File\getViewURL().

◆ iconThumb()

MediaWiki\FileRepo\File\File::iconThumb ( )

Get a ThumbnailImage representing a file type icon.

Returns
ThumbnailImage|null

Definition at line 1632 of file File.php.

References $IP.

◆ isCacheable()

MediaWiki\FileRepo\File\File::isCacheable ( )

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

Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\FileRepo\File\LocalFile.

Definition at line 2541 of file File.php.

◆ isDeleted()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\OldLocalFile.

Definition at line 2141 of file File.php.

Referenced by MediaWiki\Media\FormatMetadata\fetchExtendedMetadata(), and MediaWiki\FileRepo\LocalRepo\findFiles().

◆ isExpensiveToThumbnail()

MediaWiki\FileRepo\File\File::isExpensiveToThumbnail ( )

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

Returns
bool

Definition at line 2567 of file File.php.

Referenced by MediaWiki\FileRepo\ThumbnailEntryPoint\generateThumbnail().

◆ isHashed()

MediaWiki\FileRepo\File\File::isHashed ( )
protected
Returns
bool

Definition at line 2049 of file File.php.

◆ isLocal()

MediaWiki\FileRepo\File\File::isLocal ( )

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

Returns
bool

Definition at line 2099 of file File.php.

Referenced by MediaWiki\Api\ApiDelete\canDeleteFile(), and MediaWiki\Page\ImagePage\imageDupes().

◆ isMissing()

MediaWiki\FileRepo\File\File::isMissing ( )
Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\FileRepo\File\LocalFile.

Definition at line 2532 of file File.php.

◆ isMultipage()

MediaWiki\FileRepo\File\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 2231 of file File.php.

◆ isOld()

MediaWiki\FileRepo\File\File::isOld ( )

Returns true if the image is an old version STUB.

Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\FileRepo\File\OldLocalFile.

Definition at line 2129 of file File.php.

Referenced by MediaWiki\FileRepo\LocalRepo\findFiles().

◆ isSafeFile()

MediaWiki\FileRepo\File\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 943 of file File.php.

◆ isTransformedLocally()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignAPIFile.

Definition at line 2578 of file File.php.

◆ isTrustedFile()

MediaWiki\FileRepo\File\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 1009 of file File.php.

◆ isVectorized()

MediaWiki\FileRepo\File\File::isVectorized ( )

Return true if the file is vectorized.

Returns
bool

Definition at line 659 of file File.php.

References MediaWiki\FileRepo\File\File\$handler, MediaWiki\FileRepo\File\File\getHandler(), and MediaWiki\Media\MediaHandler\isVectorized().

◆ isVisible()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\OldLocalFile.

Definition at line 1047 of file File.php.

◆ load()

MediaWiki\FileRepo\File\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 IDBAccessObject::READ_* constants

Reimplemented in MediaWiki\FileRepo\File\LocalFile.

Definition at line 1025 of file File.php.

◆ makeTransformTmpFile()

MediaWiki\FileRepo\File\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 1592 of file File.php.

◆ move()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignDBFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 2179 of file File.php.

◆ mustRender()

MediaWiki\FileRepo\File\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 917 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getViewURL().

◆ nextHistoryLine()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\LocalFile.

Definition at line 1742 of file File.php.

◆ normalizeExtension()

static MediaWiki\FileRepo\File\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 269 of file File.php.

References MediaWiki\FileRepo\File\File\$extension.

Referenced by MediaWiki\FileRepo\File\File\checkExtensionCompatibility(), and MediaWiki\FileRepo\File\File\getExtension().

◆ normalizeTitle()

static MediaWiki\FileRepo\File\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 | false$exceptionUse 'exception' to throw an error on bad titles
Returns
Title|null

Definition at line 220 of file File.php.

References MediaWiki\FileRepo\File\File\$title, NS_FILE, and NS_MEDIA.

Referenced by MediaWiki\FileRepo\File\ArchivedFile\__construct(), and MediaWiki\FileRepo\File\File\__construct().

◆ pageCount()

MediaWiki\FileRepo\File\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 2242 of file File.php.

Referenced by MediaWiki\Media\MediaHandler\getEntireText().

◆ publish()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\ForeignDBFile.

Definition at line 2081 of file File.php.

◆ purgeCache()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignAPIFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 1679 of file File.php.

◆ purgeDescription()

MediaWiki\FileRepo\File\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 1687 of file File.php.

◆ purgeEverything()

MediaWiki\FileRepo\File\File::purgeEverything ( )

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

Definition at line 1700 of file File.php.

References $job.

◆ readOnlyError()

MediaWiki\FileRepo\File\File::readOnlyError ( )
protected

Definition at line 2055 of file File.php.

◆ redirectedFrom()

MediaWiki\FileRepo\File\File::redirectedFrom ( string $from)
Parameters
string$fromThe name that was used to access the file, before resolving redirects.

Definition at line 2524 of file File.php.

Referenced by MediaWiki\FileRepo\LocalRepo\findFiles().

◆ resetHistory()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\LocalFile.

Definition at line 1753 of file File.php.

◆ restore()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\ForeignDBFile, and MediaWiki\FileRepo\File\LocalFile.

Definition at line 2219 of file File.php.

◆ scaleHeight()

static MediaWiki\FileRepo\File\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 2263 of file File.php.

◆ setHandlerState()

MediaWiki\FileRepo\File\File::setHandlerState ( string $key,
$value )

Set a value.

Parameters
string$key
mixed$value

Implements MediaWiki\Media\MediaHandlerState.

Definition at line 768 of file File.php.

◆ splitMime()

static MediaWiki\FileRepo\File\File::splitMime ( ?string $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 320 of file File.php.

Referenced by MediaWiki\FileRepo\File\LocalFileRestoreBatch\execute().

◆ thumbName()

MediaWiki\FileRepo\File\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 MediaWiki\Upload\UploadStashFile.

Definition at line 1099 of file File.php.

Referenced by MediaWiki\JobQueue\Jobs\ThumbnailRenderJob\hitThumbUrl().

◆ transform()

MediaWiki\FileRepo\File\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|false False on failure

Reimplemented in MediaWiki\FileRepo\File\ForeignAPIFile.

Definition at line 1260 of file File.php.

References PROTO_CANONICAL, wfDebug(), and wfMessage().

Referenced by MediaWiki\FileRepo\ThumbnailEntryPoint\generateThumbnail().

◆ transformErrorOutput()

MediaWiki\FileRepo\File\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 1238 of file File.php.

References wfMessage().

◆ upgradeRow()

MediaWiki\FileRepo\File\File::upgradeRow ( )

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

Stability: stable
to override

Reimplemented in MediaWiki\FileRepo\File\LocalFile, and MediaWiki\FileRepo\File\OldLocalFile.

Definition at line 310 of file File.php.

◆ userCan()

MediaWiki\FileRepo\File\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 MediaWiki\FileRepo\File\OldLocalFile.

Definition at line 2430 of file File.php.

Referenced by MediaWiki\FileRepo\LocalRepo\findFiles().

◆ wasDeleted()

MediaWiki\FileRepo\File\File::wasDeleted ( )

Was this file ever deleted from the wiki?

Returns
bool

Definition at line 2160 of file File.php.

Member Data Documentation

◆ $canRender

bool null MediaWiki\FileRepo\File\File::$canRender
protected

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

Definition at line 176 of file File.php.

◆ $extension

string null MediaWiki\FileRepo\File\File::$extension
protected

File extension.

Definition at line 153 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getExtension(), and MediaWiki\FileRepo\File\File\normalizeExtension().

◆ $fsFile

FSFile false null MediaWiki\FileRepo\File\File::$fsFile
protected

False if undefined.

Definition at line 144 of file File.php.

◆ $handler

◆ $hashPath

string null MediaWiki\FileRepo\File\File::$hashPath
protected

Relative path including trailing slash.

Definition at line 162 of file File.php.

◆ $isSafeFile

bool null MediaWiki\FileRepo\File\File::$isSafeFile
protected

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

Definition at line 181 of file File.php.

◆ $lastError

string MediaWiki\FileRepo\File\File::$lastError
protected

Text of last error.

Definition at line 132 of file File.php.

◆ $name

string null MediaWiki\FileRepo\File\File::$name
protected

The name of a file from its title object.

Definition at line 156 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\__get(), and MediaWiki\FileRepo\File\File\getName().

◆ $pageCount

int false null MediaWiki\FileRepo\File\File::$pageCount
protected

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

Definition at line 167 of file File.php.

◆ $path

string null MediaWiki\FileRepo\File\File::$path
protected

The storage path corresponding to one of the zones.

Definition at line 159 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getPath().

◆ $redirected

string MediaWiki\FileRepo\File\File::$redirected
protected

The name that was used to access the file, before resolving redirects.

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

Definition at line 138 of file File.php.

◆ $redirectedTitle

Title MediaWiki\FileRepo\File\File::$redirectedTitle
protected

Definition at line 141 of file File.php.

◆ $redirectTitle

Title MediaWiki\FileRepo\File\File::$redirectTitle
protected

Definition at line 173 of file File.php.

◆ $repo

FileRepo LocalRepo ForeignAPIRepo false MediaWiki\FileRepo\File\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 126 of file File.php.

Referenced by MediaWiki\Upload\UploadStashFile\__construct(), MediaWiki\FileRepo\File\File\__construct(), MediaWiki\FileRepo\File\ForeignAPIFile\__construct(), MediaWiki\FileRepo\File\ForeignAPIFile\getRepo(), MediaWiki\FileRepo\File\ForeignDBFile\getRepo(), and MediaWiki\FileRepo\File\ForeignAPIFile\newFromTitle().

◆ $repoClass

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

Required Repository class type.

Definition at line 184 of file File.php.

◆ $title

◆ $tmpBucketedThumbCache

array MediaWiki\FileRepo\File\File::$tmpBucketedThumbCache = []
protected

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

Definition at line 187 of file File.php.

◆ $transformScript

string false null MediaWiki\FileRepo\File\File::$transformScript
protected

URL of transformscript (for example thumb.php)

Definition at line 170 of file File.php.

◆ $url

string null MediaWiki\FileRepo\File\File::$url
protected

The URL corresponding to one of the four basic zones.

Definition at line 150 of file File.php.

Referenced by MediaWiki\FileRepo\File\File\getUrl().

◆ DELETE_SOURCE

const MediaWiki\FileRepo\File\File::DELETE_SOURCE = 1

Definition at line 96 of file File.php.

◆ DELETED_COMMENT

const MediaWiki\FileRepo\File\File::DELETED_COMMENT = 2

Definition at line 84 of file File.php.

Referenced by MediaWiki\Page\ImageHistoryList\imageHistoryLine().

◆ DELETED_FILE

◆ DELETED_RESTRICTED

const MediaWiki\FileRepo\File\File::DELETED_RESTRICTED = 8

Definition at line 86 of file File.php.

Referenced by MediaWiki\Page\ImageHistoryList\imageHistoryLine().

◆ DELETED_USER

const MediaWiki\FileRepo\File\File::DELETED_USER = 4

Definition at line 85 of file File.php.

◆ FOR_PUBLIC

const MediaWiki\FileRepo\File\File::FOR_PUBLIC = 1

Definition at line 99 of file File.php.

◆ FOR_THIS_USER

const MediaWiki\FileRepo\File\File::FOR_THIS_USER = 2

◆ RAW

const MediaWiki\FileRepo\File\File::RAW = 3

Definition at line 101 of file File.php.

◆ RENDER_FORCE

const MediaWiki\FileRepo\File\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 94 of file File.php.

◆ RENDER_NOW

const MediaWiki\FileRepo\File\File::RENDER_NOW = 1

Force rendering in the current process.

Definition at line 89 of file File.php.

◆ THUMB_FULL_NAME

const MediaWiki\FileRepo\File\File::THUMB_FULL_NAME = 1

Definition at line 104 of file File.php.


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