MediaWiki  1.23.12
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...
 
 delete ( $reason, $suppress=false)
 Delete all versions of the file. More...
 
 exists ()
 Returns true if file exists in the repository. More...
 
 formatMetadata ()
 
 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...
 
 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...
 
 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 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...
 
 getDefaultRenderLanguage ()
 In files that support multiple language, what is the default language to use if none specified. More...
 
 getDescription ( $audience=self::FOR_PUBLIC, User $user=null)
 Get description of file revision STUB. More...
 
 getDescriptionText ( $lang=false)
 Get the HTML text of the description page, if available. More...
 
 getDescriptionUrl ()
 Get the URL of the image description page. More...
 
 getDimensionsString ()
 
 getExtension ()
 Get the file extension, e.g. More...
 
 getFullUrl ()
 Return a fully-qualified URL to the file. More...
 
 getHandler ()
 Get a MediaHandler instance for this file. 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...
 
 getImageSize ( $fileName)
 Get an image size array like that returned by getImageSize(), or false if it can't be determined. 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 ()
 
 getMediaType ()
 Return the type of the media in the file. More...
 
 getMetadata ()
 Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB. 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 ()
 
 getRedirectedTitle ()
 
 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...
 
 getStreamHeaders ()
 
 getThumbDisposition ( $thumbName, $dispositionType='inline')
 
 getThumbnails ()
 Get all thumbnail names previously generated for this file STUB Overridden by LocalFile. 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...
 
 getTransformScript ()
 
 getUnscaledThumb ( $handlerParams=array())
 Get a ThumbnailImage which is the same size as the source. More...
 
 getUrl ()
 Return the URL of the file. More...
 
 getUrlRel ()
 Get urlencoded path of the file relative to the public zone root. More...
 
 getUser ( $type='text')
 Returns ID or name of user who uploaded the file STUB. 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...
 
 getZoneUrl ( $zone, $suffix=false)
 Get the URL of the zone directory, or a particular file if $suffix is specified. 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...
 
 isHashed ()
 
 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...
 
 isTrustedFile ()
 Returns true if the file is flagged as trusted. 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...
 
 migrateThumbFile ( $thumbName)
 Hook into transform() to allow migration of thumbnail files STUB Overridden by LocalFile. 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 ( $srcPath, $flags=0, array $options=array())
 Move or copy a file to its public location. More...
 
 purgeCache ( $options=array())
 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...
 
 readOnlyError ()
 
 recordUpload ( $oldver, $desc, $license='', $copyStatus='', $source='', $watch=false, $timestamp=false, User $user=null)
 Record a file upload in the upload log and the image table STUB Overridden by LocalFile. More...
 
 redirectedFrom ( $from)
 
 resetHistory ()
 Reset the history pointer to the first element of the history. More...
 
 restore ( $versions=array(), $unsuppress=false)
 Restore all or specified deleted revisions to the given file. 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, User $user=null)
 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 getPropsFromPath ( $path, $ext=true)
 Get an associative array containing information about a file in the local filesystem. More...
 
static normalizeExtension ( $ext)
 Normalize a file extension to the common form, 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 sha1Base36 ( $path)
 Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits. 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
 

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...
 
 getCanRender ()
 Accessor for __get() More...
 
 getIsSafeFile ()
 Accessor for __get() More...
 
 getIsSafeFileUncached ()
 Uncached accessor. More...
 
 transformErrorOutput ( $thumbPath, $thumbUrl, $params, $flags)
 Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors) More...
 

Protected Attributes

bool $canRender
 Wether 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 $hashPath
 Relative path including trailing slash *. More...
 
bool $isSafeFile
 Wether 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 $name
 The name of a file from its title object *. More...
 
string $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'
 Required Repository class type *. More...
 
Title string bool $title
 
string $transformScript
 URL of transformscript (for example thumb.php) *. More...
 
string $url
 The URL corresponding to one of the four basic zones *. More...
 

Detailed Description

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

Contains stub functionality for unimplemented public methods.

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

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

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

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

Definition at line 50 of file File.php.

Constructor & Destructor Documentation

◆ __construct()

File::__construct (   $title,
  $repo 
)

Call this constructor from child classes.

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

Parameters
Title | string | bool$title
FileRepo | bool$repo

Reimplemented in LocalFile.

Definition at line 144 of file File.php.

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

Member Function Documentation

◆ __get()

File::__get (   $name)

Definition at line 182 of file File.php.

References $name, and array().

◆ allowInlineDisplay()

File::allowInlineDisplay ( )

Alias for canRender()

Returns
bool

Definition at line 685 of file File.php.

References canRender().

Referenced by canAnimateThumbIfAppropriate(), and getIsSafeFileUncached().

◆ assertRepoDefined()

◆ assertTitleDefined()

File::assertTitleDefined ( )
protected

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

Exceptions
MWException

Definition at line 1994 of file File.php.

References title.

Referenced by LocalFile\__construct().

◆ canAnimateThumbIfAppropriate()

File::canAnimateThumbIfAppropriate ( )

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

Currently used to add a warning to the image description page

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

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

References $canRender, and getHandler().

Referenced by allowInlineDisplay(), getCanRender(), getViewURL(), ForeignAPIFile\transform(), and 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 225 of file File.php.

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

Referenced by Title\validateFileMoveOperation().

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

References getName().

◆ convertMetadataVersion()

File::convertMetadataVersion (   $metadata,
  $version 
)

get versioned metadata

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

Definition at line 583 of file File.php.

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

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

References $params, array(), and transform().

Referenced by getViewURL().

◆ delete()

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

Delete all versions of the file.

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

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

Parameters
string$reason
bool$suppressHide content from sysops?
Returns
bool on success, false on some kind of failure STUB Overridden by LocalFile

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1641 of file File.php.

References readOnlyError().

Referenced by FileDeleteForm\doDelete().

◆ exists()

File::exists ( )

Returns true if file exists in the repository.

Overridden by LocalFile to avoid unnecessary stat calls.

Returns
bool Whether file exists in the repository.

Reimplemented in LocalFile, UploadStashFile, and ForeignAPIFile.

Definition at line 781 of file File.php.

References getPath().

Referenced by FileDeleteForm\haveDeletableFile(), and isVisible().

◆ formatMetadata()

File::formatMetadata ( )
Returns
bool

Definition at line 1535 of file File.php.

References getHandler(), and getMetadata().

◆ generateThumbName()

File::generateThumbName (   $name,
  $params 
)

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

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

Definition at line 855 of file File.php.

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

Referenced by UploadStashFile\thumbName(), and 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 1298 of file File.php.

References assertRepoDefined(), and getArchiveRel().

◆ getArchiveRel()

File::getArchiveRel (   $suffix = false)

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

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

Definition at line 1236 of file File.php.

References $path, and getHashPath().

Referenced by getArchivePath().

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

References assertRepoDefined(), and getArchiveThumbRel().

Referenced by LocalFile\getThumbnails().

◆ getArchiveThumbRel()

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

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

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

Definition at line 1281 of file File.php.

References $path, and getHashPath().

Referenced by getArchiveThumbPath().

◆ getArchiveThumbUrl()

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

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

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

Definition at line 1368 of file File.php.

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

Referenced by LocalFile\purgeOldThumbnails().

◆ getArchiveUrl()

File::getArchiveUrl (   $suffix = false)

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

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

Definition at line 1348 of file File.php.

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

Referenced by LocalFile\deleteOld().

◆ getArchiveVirtualUrl()

File::getArchiveVirtualUrl (   $suffix = false)

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

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

Definition at line 1442 of file File.php.

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

◆ getAvailableLanguages()

File::getAvailableLanguages ( )

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

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

Returns
Array
Since
1.23

Definition at line 491 of file File.php.

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

◆ getBitDepth()

File::getBitDepth ( )

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

Returns
int

Reimplemented in LocalFile.

Definition at line 602 of file File.php.

◆ getCanonicalUrl()

File::getCanonicalUrl ( )
Returns
string

Definition at line 348 of file File.php.

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

◆ getCanRender()

File::getCanRender ( )
protected

Accessor for __get()

Returns
bool

Definition at line 662 of file File.php.

References canRender().

◆ getCommonMetaArray()

File::getCommonMetaArray ( )

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

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

Definition at line 565 of file File.php.

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

◆ getDefaultRenderLanguage()

File::getDefaultRenderLanguage ( )

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

Returns
String lang code, or null if filetype doesn't support multiple languages.
Since
1.23

Definition at line 507 of file File.php.

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

◆ getDescription()

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

Get description of file revision STUB.

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

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1795 of file File.php.

◆ getDescriptionText()

File::getDescriptionText (   $lang = false)

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

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

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1745 of file File.php.

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

Referenced by ForeignDBFile\getDescriptionText().

◆ getDescriptionUrl()

File::getDescriptionUrl ( )

Get the URL of the image description page.

May return false if it is unknown or not applicable.

Returns
string

Reimplemented in LocalFile, UploadStashFile, ForeignAPIFile, and ForeignDBFile.

Definition at line 1731 of file File.php.

References getName().

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

◆ getDimensionsString()

File::getDimensionsString ( )
Returns
string

Definition at line 1926 of file File.php.

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

◆ getExtension()

File::getExtension ( )

Get the file extension, e.g.

"svg"

Returns
string

Definition at line 287 of file File.php.

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

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

◆ getFullUrl()

File::getFullUrl ( )

Return a fully-qualified URL to the file.

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

Returns
string

Reimplemented in UploadStashFile.

Definition at line 341 of file File.php.

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

◆ getHandler()

◆ getHashPath()

File::getHashPath ( )

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

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

Returns
string

Definition at line 1210 of file File.php.

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

Referenced by getArchiveRel(), getArchiveThumbRel(), getArchiveThumbUrl(), getArchiveUrl(), getArchiveVirtualUrl(), OldLocalFile\getRel(), getRel(), ForeignAPIFile\getThumbPath(), OldLocalFile\getUrlRel(), getUrlRel(), LocalFile\publishTo(), and OldLocalFile\uploadOld().

◆ getHeight()

File::getHeight (   $page = 1)

Return the height of the image.

Returns false if the height is unknown or undefined

STUB Overridden by LocalFile, UnregisteredLocalFile

Parameters
int$page
Returns
bool|int False on failure

Reimplemented in LocalFile, ForeignAPIFile, UnregisteredLocalFile, and FakeDimensionFile.

Definition at line 437 of file File.php.

Referenced by RevDel_FileItem\getApiData().

◆ getHistory()

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

Return a fragment of the history of file.

STUB

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

Reimplemented in LocalFile.

Definition at line 1177 of file File.php.

References array().

◆ getImageSize()

File::getImageSize (   $fileName)

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

Parameters
string$fileNameThe filename
Returns
array

Reimplemented in UnregisteredLocalFile.

Definition at line 1717 of file File.php.

References getHandler().

◆ getIsSafeFile()

File::getIsSafeFile ( )
protected

Accessor for __get()

Returns
bool

Definition at line 715 of file File.php.

References isSafeFile().

◆ getIsSafeFileUncached()

File::getIsSafeFileUncached ( )
protected

Uncached accessor.

Returns
bool

Definition at line 724 of file File.php.

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

Referenced by isSafeFile().

◆ getLastError()

File::getLastError ( )

Get last thumbnailing error.

Largely obsolete.

Definition at line 1112 of file File.php.

References $lastError.

◆ getLength()

File::getLength ( )

Get the duration of a media file in seconds.

Returns
int

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

References assertRepoDefined(), and getPath().

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

◆ getLongDesc()

File::getLongDesc ( )
Returns
string

Definition at line 1902 of file File.php.

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

◆ getMediaType()

File::getMediaType ( )

Return the type of the media in the file.

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

Returns
string

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 634 of file File.php.

References MEDIATYPE_UNKNOWN.

Referenced by getIsSafeFileUncached().

◆ getMetadata()

File::getMetadata ( )

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

Returns
bool|array

Reimplemented in LocalFile, ForeignAPIFile, and UnregisteredLocalFile.

Definition at line 555 of file File.php.

Referenced by formatMetadata(), GIFHandler\getCommonMetaArray(), PNGHandler\getCommonMetaArray(), and getStreamHeaders().

◆ getMimeType()

File::getMimeType ( )

Returns the mime type of the file.

Overridden by LocalFile, UnregisteredLocalFile STUB

Returns
string

Reimplemented in LocalFile, ForeignAPIFile, and UnregisteredLocalFile.

Definition at line 623 of file File.php.

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

◆ getName()

◆ getOriginalTitle()

File::getOriginalTitle ( )

Return the title used to find this file.

Returns
Title

Definition at line 311 of file File.php.

References $title, and getRedirectedTitle().

◆ getPath()

File::getPath ( )

Return the storage path to the file.

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

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

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

Returns
string|bool ForeignAPIFile::getPath can return false

Reimplemented in ForeignAPIFile, and FakeDimensionFile.

Definition at line 383 of file File.php.

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

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

◆ getPropsFromPath()

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

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

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

Definition at line 1859 of file File.php.

References $fsFile, $path, FSFile\getProps(), wfDebug(), and wfDeprecated().

◆ getRedirected()

File::getRedirected ( )
Returns
string

Definition at line 1938 of file File.php.

References $redirected.

◆ getRedirectedTitle()

File::getRedirectedTitle ( )
Returns
Title|null

Definition at line 1945 of file File.php.

References $redirectTitle, 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 overriden in OldLocalFile to be like getArchiveRel().

Returns
string

Reimplemented in OldLocalFile.

Definition at line 1225 of file File.php.

References getHashPath(), and getName().

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

◆ getRepo()

File::getRepo ( )

◆ getRepoName()

File::getRepoName ( )

Returns the name of the repository.

Returns
string

Definition at line 1557 of file File.php.

◆ getSha1()

File::getSha1 ( )

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

Returns
string

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1815 of file File.php.

References assertRepoDefined(), and getPath().

Referenced by getStorageKey().

◆ getShortDesc()

File::getShortDesc ( )
Returns
string

Definition at line 1914 of file File.php.

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

◆ getSize()

File::getSize ( )

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

Returns
bool

Reimplemented in LocalFile, ForeignAPIFile, and UnregisteredLocalFile.

Definition at line 612 of file File.php.

Referenced by RevDel_FileItem\getApiData().

◆ getStorageKey()

File::getStorageKey ( )

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

Returns
string

Definition at line 1826 of file File.php.

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

◆ getStreamHeaders()

File::getStreamHeaders ( )
Returns
array HTTP header name/value map to use for HEAD/GET request responses

Definition at line 1890 of file File.php.

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

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

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

Referenced by transform().

◆ getThumbnails()

File::getThumbnails ( )

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

Returns
array

Reimplemented in ForeignAPIFile.

Definition at line 1122 of file File.php.

References array().

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

◆ getThumbPath()

File::getThumbPath (   $suffix = false)

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

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

Reimplemented in UploadStashFile, and ForeignAPIFile.

Definition at line 1324 of file File.php.

References assertRepoDefined(), and getThumbRel().

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

◆ getThumbRel()

File::getThumbRel (   $suffix = false)

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

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

Definition at line 1254 of file File.php.

References $path, and getRel().

Referenced by getThumbPath(), and getTranscodedPath().

◆ getThumbUrl()

File::getThumbUrl (   $suffix = false)

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

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

Reimplemented in UploadStashFile.

Definition at line 1406 of file File.php.

References getZoneUrl().

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

◆ getThumbVirtualUrl()

File::getThumbVirtualUrl (   $suffix = false)

Get the virtual URL for a thumbnail file or directory.

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

Definition at line 1460 of file File.php.

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

◆ getTimestamp()

File::getTimestamp ( )

Get the 14-character timestamp of the file upload.

Returns
string|bool TS_MW timestamp or false on failure

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1804 of file File.php.

References assertRepoDefined(), and getPath().

Referenced by RevDel_FileItem\getApiData().

◆ getTitle()

File::getTitle ( )

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

References assertRepoDefined(), and getThumbRel().

◆ getTranscodedUrl()

File::getTranscodedUrl (   $suffix = false)

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

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

Definition at line 1416 of file File.php.

References getZoneUrl().

◆ getTransformScript()

File::getTransformScript ( )
Returns
string

Definition at line 798 of file File.php.

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

Referenced by transform().

◆ getUnscaledThumb()

File::getUnscaledThumb (   $handlerParams = array())

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

Parameters
array$handlerParams
Returns
string

Definition at line 819 of file File.php.

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

◆ getUrl()

File::getUrl ( )

Return the URL of the file.

Returns
string

Reimplemented in UploadStashFile, and ForeignAPIFile.

Definition at line 324 of file File.php.

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

Referenced by RevDel_FileItem\getApiData(), getCanonicalUrl(), and getFullUrl().

◆ getUrlRel()

File::getUrlRel ( )

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

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

Returns
string

Reimplemented in OldLocalFile.

Definition at line 1269 of file File.php.

References getHashPath(), and getName().

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

◆ getUser()

File::getUser (   $type = 'text')

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

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

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 448 of file File.php.

Referenced by FileDuplicateSearchPage\doBatchLookups().

◆ getViewURL()

File::getViewURL ( )
Returns
string

Definition at line 355 of file File.php.

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

◆ getVirtualUrl()

File::getVirtualUrl (   $suffix = false)

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

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

Definition at line 1426 of file File.php.

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

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

◆ getVisibility()

File::getVisibility ( )

Return the deletion bitfield STUB.

Returns
int

Reimplemented in OldLocalFile.

Definition at line 1596 of file File.php.

◆ getWidth()

File::getWidth (   $page = 1)

Return the width of the image.

Returns false if the width is unknown or undefined.

STUB Overridden by LocalFile, UnregisteredLocalFile

Parameters
int$page
Returns
int|bool

Reimplemented in LocalFile, ForeignAPIFile, UnregisteredLocalFile, and FakeDimensionFile.

Definition at line 423 of file File.php.

Referenced by RevDel_FileItem\getApiData(), getUnscaledThumb(), and getViewURL().

◆ getZoneUrl()

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

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

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

Definition at line 1389 of file File.php.

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

Referenced by getThumbUrl(), and getTranscodedUrl().

◆ iconThumb()

File::iconThumb ( )

Get a ThumbnailImage representing a file type icon.

Returns
ThumbnailImage

Definition at line 1091 of file File.php.

References $params, $path, array(), as, getExtension(), and global.

Referenced by getUnscaledThumb(), and transform().

◆ isCacheable()

File::isCacheable ( )

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

Returns
bool

Reimplemented in LocalFile.

Definition at line 1976 of file File.php.

◆ isDeleted()

File::isDeleted (   $field)

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

Parameters
int$fieldone of DELETED_* bitfield constants
Returns
bool

Reimplemented in OldLocalFile.

Definition at line 1587 of file File.php.

Referenced by RevDel_FileItem\getApiData(), and LocalFile\getDescription().

◆ isHashed()

File::isHashed ( )
Returns
bool

Definition at line 1473 of file File.php.

References assertRepoDefined().

◆ isLocal()

File::isLocal ( )

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

Returns
bool

Definition at line 1548 of file File.php.

Referenced by FileDuplicateSearchPage\doBatchLookups(), and FileDeleteForm\haveDeletableFile().

◆ isMissing()

File::isMissing ( )
Returns
bool

Reimplemented in LocalFile.

Definition at line 1968 of file File.php.

◆ isMultipage()

File::isMultipage ( )

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

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

Returns
bool

Definition at line 1670 of file File.php.

References getHandler().

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

◆ isOld()

File::isOld ( )

Returns true if the image is an old version STUB.

Returns
bool

Reimplemented in OldLocalFile.

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

References $isSafeFile, and getIsSafeFileUncached().

Referenced by getIsSafeFile().

◆ isTrustedFile()

File::isTrustedFile ( )

Returns true if the file is flagged as trusted.

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

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

Returns
bool

Definition at line 768 of file File.php.

Referenced by getIsSafeFileUncached().

◆ isVectorized()

File::isVectorized ( )

Return true if the file is vectorized.

Returns
bool

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

Returns
bool Whether file exists in the repository and is includable.

Reimplemented in OldLocalFile.

Definition at line 791 of file File.php.

References exists().

◆ migrateThumbFile()

File::migrateThumbFile (   $thumbName)

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

Reimplemented in LocalFile.

Definition at line 1069 of file File.php.

Referenced by transform().

◆ move()

File::move (   $target)

Move file to the new title.

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

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

Parameters
Title$targetNew file name
Returns
FileRepoStatus object.

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1623 of file File.php.

References readOnlyError().

◆ mustRender()

File::mustRender ( )

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

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

Returns
bool

Reimplemented in FakeDimensionFile.

Definition at line 676 of file File.php.

References getHandler().

Referenced by getViewURL().

◆ nextHistoryLine()

File::nextHistoryLine ( )

Return the history of this file, line by line.

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

STUB Overridden in LocalFile

Returns
bool

Reimplemented in LocalFile.

Definition at line 1190 of file File.php.

◆ normalizeExtension()

static File::normalizeExtension (   $ext)
static

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

Extensions with non-alphanumeric characters will be discarded.

Parameters
string$ext(without the .)
Returns
string

Definition at line 200 of file File.php.

References $ext, and array().

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

◆ normalizeTitle()

static File::normalizeTitle (   $title,
  $exception = false 
)
static

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

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

Definition at line 161 of file File.php.

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

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

◆ pageCount()

File::pageCount ( )

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

Returns
bool|int

Definition at line 1680 of file File.php.

References $pageCount, and getHandler().

◆ publish()

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

Move or copy a file to its public location.

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

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

Options to $options include:

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

STUB Overridden by LocalFile

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1528 of file File.php.

References readOnlyError().

◆ purgeCache()

File::purgeCache (   $options = array())

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

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

Reimplemented in LocalFile, and ForeignAPIFile.

Definition at line 1133 of file File.php.

Referenced by purgeEverything().

◆ purgeDescription()

File::purgeDescription ( )

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

Use when modifying file history but not the current data.

Definition at line 1141 of file File.php.

References $title, getTitle(), Title\invalidateCache(), and Title\purgeSquid().

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

◆ purgeEverything()

File::purgeEverything ( )

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

Definition at line 1153 of file File.php.

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

◆ readOnlyError()

◆ recordUpload()

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

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

Parameters
$oldver
$desc
string$license
string$copyStatus
string$source
bool$watch
string | bool$timestamp
null | User$userUser object or null to use $wgUser
Returns
bool
Exceptions
MWException

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1501 of file File.php.

References readOnlyError().

◆ redirectedFrom()

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

Definition at line 1961 of file File.php.

References $from.

◆ resetHistory()

File::resetHistory ( )

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

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

Reimplemented in LocalFile.

Definition at line 1200 of file File.php.

◆ restore()

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

Restore all or specified deleted revisions to the given file.

Permissions and logging are left to the caller.

May throw database exceptions on error.

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

Reimplemented in LocalFile, and ForeignDBFile.

Definition at line 1659 of file File.php.

References readOnlyError().

◆ scaleHeight()

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

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

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

Definition at line 1701 of file File.php.

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

◆ sha1Base36()

static File::sha1Base36 (   $path)
static

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

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

Parameters
$pathstring
Returns
bool|string False on failure
Deprecated:
since 1.19

Definition at line 1879 of file File.php.

References $fsFile, $path, FSFile\getSha1Base36(), and wfDeprecated().

◆ 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
array ("text", "html") etc

Definition at line 249 of file File.php.

References $mime, and array().

Referenced by MIMEsearchPage\execute(), RefreshImageMetadata\getConditions(), FSFile\getProps(), ApiQueryAllImages\run(), LocalFile\setProps(), OldLocalFile\upgradeRow(), 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>".

Parameters
array$paramshandler-specific parameters
int$flagsBitfield that supports THUMB_* constants
Returns
string

Reimplemented in UploadStashFile.

Definition at line 840 of file File.php.

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

Referenced by transform().

◆ transform()

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

Transform a media file.

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

Reimplemented in ForeignAPIFile.

Definition at line 929 of file File.php.

References $flags, $handler, $params, $timestamp, array(), canRender(), MediaHandler\doTransform(), FileBackend\extensionFromPath(), TempFSFile\factory(), false, getDescriptionUrl(), getHandler(), MediaHandler\getScriptedTransform(), getThumbDisposition(), getThumbPath(), getThumbUrl(), MediaHandler\getTransform(), getTransformScript(), global, iconThumb(), migrateThumbFile(), MediaHandler\normaliseParams(), PROTO_CANONICAL, SquidUpdate\purge(), RENDER_NOW, thumbName(), transformErrorOutput(), wfDebug(), wfExpandUrl(), wfProfileIn(), wfProfileOut(), and wfRunHooks().

Referenced by createThumb(), FileDuplicateSearchPage\execute(), and getUnscaledThumb().

◆ transformErrorOutput()

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

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

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

Definition at line 909 of file File.php.

References $flags, $handler, $params, getHandler(), MediaHandler\getTransform(), global, text, and wfMessage().

Referenced by transform().

◆ upgradeRow()

File::upgradeRow ( )

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

Reimplemented in LocalFile, and OldLocalFile.

Definition at line 239 of file File.php.

◆ userCan()

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

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

STUB

Parameters
int$field
User$userUser object to check, or null to use $wgUser
Returns
bool

Reimplemented in OldLocalFile.

Definition at line 1845 of file File.php.

Referenced by RevDel_FileItem\getApiData(), and LocalFile\getDescription().

◆ wasDeleted()

File::wasDeleted ( )

Was this file ever deleted from the wiki?

Returns
bool

Definition at line 1605 of file File.php.

References $title, getTitle(), and Title\isDeletedQuick().

Member Data Documentation

◆ $canRender

bool File::$canRender
protected

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

Definition at line 126 of file File.php.

Referenced by canRender().

◆ $extension

string File::$extension
protected

File extension *.

Definition at line 110 of file File.php.

Referenced by generateThumbName(), and getExtension().

◆ $fsFile

FSFile bool File::$fsFile
protected

False if undefined *.

Definition at line 104 of file File.php.

Referenced by getPropsFromPath(), UnregisteredLocalFile\setLocalReference(), and sha1Base36().

◆ $handler

◆ $hashPath

string File::$hashPath
protected

Relative path including trailing slash *.

Definition at line 116 of file File.php.

Referenced by getHashPath().

◆ $isSafeFile

bool File::$isSafeFile
protected

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

Definition at line 130 of file File.php.

Referenced by isSafeFile().

◆ $lastError

string File::$lastError
protected

Text of last error *.

Definition at line 98 of file File.php.

Referenced by getLastError().

◆ $name

◆ $pageCount

string File::$pageCount
protected

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

Definition at line 120 of file File.php.

Referenced by pageCount().

◆ $path

◆ $redirected

string File::$redirected
protected

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

Definition at line 100 of file File.php.

Referenced by getRedirected().

◆ $redirectedTitle

Title File::$redirectedTitle
protected

Definition at line 102 of file File.php.

◆ $redirectTitle

Title File::$redirectTitle
protected

Definition at line 124 of file File.php.

Referenced by getRedirectedTitle().

◆ $repo

FileRepo LocalRepo ForeignAPIRepo bool File::$repo

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

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

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

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

Definition at line 94 of file File.php.

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

◆ $repoClass

string File::$repoClass = 'FileRepo'
protected

Required Repository class type *.

Definition at line 132 of file File.php.

◆ $title

◆ $transformScript

string File::$transformScript
protected

URL of transformscript (for example thumb.php) *.

Definition at line 122 of file File.php.

Referenced by getTransformScript().

◆ $url

string File::$url
protected

The URL corresponding to one of the four basic zones *.

Definition at line 108 of file File.php.

Referenced by getUrl(), and ForeignAPIFile\purgeDescriptionPage().

◆ DELETE_SOURCE

const File::DELETE_SOURCE = 1

Definition at line 65 of file File.php.

Referenced by WikiRevision\importUpload(), LocalFile\publishTo(), and OldLocalFile\uploadOld().

◆ DELETED_COMMENT

◆ DELETED_FILE

◆ DELETED_RESTRICTED

◆ DELETED_USER

const File::DELETED_USER = 4

◆ FOR_PUBLIC

const File::FOR_PUBLIC = 1

Definition at line 68 of file File.php.

◆ FOR_THIS_USER

const File::FOR_THIS_USER = 2

Definition at line 69 of file File.php.

◆ RAW

const File::RAW = 3

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

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

◆ RENDER_NOW

const File::RENDER_NOW = 1

◆ THUMB_FULL_NAME

const File::THUMB_FULL_NAME = 1

Definition at line 73 of file File.php.

Referenced by thumbName(), and wfStreamThumb().


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