BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
File Class Reference
Inheritance diagram for File:
Collaboration diagram for File:

Public Member Functions

 __construct ($title, $repo)
 
 __get ($name)
 
 upgradeRow ()
 
 getName ()
 
 getExtension ()
 
 getTitle ()
 
 getOriginalTitle ()
 
 getUrl ()
 
 getDescriptionShortUrl ()
 
 getFullUrl ()
 
 getCanonicalUrl ()
 
 getViewURL ()
 
 getPath ()
 
 getLocalRefPath ()
 
 getWidth ($page=1)
 
 getHeight ($page=1)
 
 getThumbnailBucket ($desiredWidth, $page=1)
 
 getUser ($type= 'text')
 
 getLength ()
 
 isVectorized ()
 
 getAvailableLanguages ()
 
 getMatchedLanguage ($userPreferredLanguage)
 
 getDefaultRenderLanguage ()
 
 canAnimateThumbIfAppropriate ()
 
 getMetadata ()
 
 getCommonMetaArray ()
 
 convertMetadataVersion ($metadata, $version)
 
 getBitDepth ()
 
 getSize ()
 
 getMimeType ()
 
 getMediaType ()
 
 canRender ()
 
 mustRender ()
 
 allowInlineDisplay ()
 
 isSafeFile ()
 
 isTrustedFile ()
 
 load ($flags=0)
 
 exists ()
 
 isVisible ()
 
 getTransformScript ()
 
 getUnscaledThumb ($handlerParams=[])
 
 thumbName ($params, $flags=0)
 
 generateThumbName ($name, $params)
 
 createThumb ($width, $height=-1)
 
 transform ($params, $flags=0)
 
 getThumbnailSource ($params)
 
 getThumbDisposition ($thumbName, $dispositionType= 'inline')
 
 migrateThumbFile ($thumbName)
 
 getHandler ()
 
 iconThumb ()
 
 getLastError ()
 
 getThumbnails ()
 
 purgeCache ($options=[])
 
 purgeDescription ()
 
 purgeEverything ()
 
 getHistory ($limit=null, $start=null, $end=null, $inc=true)
 
 nextHistoryLine ()
 
 resetHistory ()
 
 getHashPath ()
 
 getRel ()
 
 getArchiveRel ($suffix=false)
 
 getThumbRel ($suffix=false)
 
 getUrlRel ()
 
 getArchiveThumbRel ($archiveName, $suffix=false)
 
 getArchivePath ($suffix=false)
 
 getArchiveThumbPath ($archiveName, $suffix=false)
 
 getThumbPath ($suffix=false)
 
 getTranscodedPath ($suffix=false)
 
 getArchiveUrl ($suffix=false)
 
 getArchiveThumbUrl ($archiveName, $suffix=false)
 
 getZoneUrl ($zone, $suffix=false)
 
 getThumbUrl ($suffix=false)
 
 getTranscodedUrl ($suffix=false)
 
 getVirtualUrl ($suffix=false)
 
 getArchiveVirtualUrl ($suffix=false)
 
 getThumbVirtualUrl ($suffix=false)
 
 isHashed ()
 
 readOnlyError ()
 
 recordUpload ($oldver, $desc, $license= '', $copyStatus= '', $source= '', $watch=false, $timestamp=false, User $user=null)
 
 publish ($src, $flags=0, array $options=[])
 
 formatMetadata ($context=false)
 
 isLocal ()
 
 getRepoName ()
 
 getRepo ()
 
 isOld ()
 
 isDeleted ($field)
 
 getVisibility ()
 
 wasDeleted ()
 
 move ($target)
 
 delete ($reason, $suppress=false, $user=null)
 
 restore ($versions=[], $unsuppress=false)
 
 isMultipage ()
 
 pageCount ()
 
 getImageSize ($filePath)
 
 getDescriptionUrl ()
 
 getDescriptionText ($lang=false)
 
 getDescription ($audience=self::FOR_PUBLIC, User $user=null)
 
 getTimestamp ()
 
 getDescriptionTouched ()
 
 getSha1 ()
 
 getStorageKey ()
 
 userCan ($field, User $user=null)
 
 getStreamHeaders ()
 
 getContentHeaders ()
 
 getLongDesc ()
 
 getShortDesc ()
 
 getDimensionsString ()
 
 getRedirected ()
 
 getRedirectedTitle ()
 
 redirectedFrom ($from)
 
 isMissing ()
 
 isCacheable ()
 
 isExpensiveToThumbnail ()
 
 isTransformedLocally ()
 

Static Public Member Functions

static normalizeTitle ($title, $exception=false)
 
static normalizeExtension ($extension)
 
static checkExtensionCompatibility (File $old, $new)
 
static splitMime ($mime)
 
static compare (File $a, File $b)
 
static scaleHeight ($srcWidth, $srcHeight, $dstWidth)
 

Public Attributes

const DELETED_FILE = 1
 
const DELETED_COMMENT = 2
 
const DELETED_USER = 4
 
const DELETED_RESTRICTED = 8
 
const RENDER_NOW = 1
 
const RENDER_FORCE = 2
 
const DELETE_SOURCE = 1
 
const FOR_PUBLIC = 1
 
const FOR_THIS_USER = 2
 
const RAW = 3
 
const THUMB_FULL_NAME = 1
 
 $repo
 
- Public Attributes inherited from IDBAccessObject
const READ_NORMAL = 0
 
const READ_LATEST = 1
 
const READ_LOCKING = 3
 
const READ_EXCLUSIVE = 7
 
const READ_LATEST_IMMUTABLE = 8
 
const READ_NONE = -1
 

Protected Member Functions

 getCanRender ()
 
 getIsSafeFile ()
 
 getIsSafeFileUncached ()
 
 transformErrorOutput ($thumbPath, $thumbUrl, $params, $flags)
 
 generateBucketsIfNeeded ($params, $flags=0)
 
 getBucketThumbPath ($bucket)
 
 getBucketThumbName ($bucket)
 
 makeTransformTmpFile ($thumbPath)
 
 assertRepoDefined ()
 
 assertTitleDefined ()
 

Protected Attributes

 $title
 
 $lastError
 
 $redirected
 
 $redirectedTitle
 
 $fsFile
 
 $handler
 
 $url
 
 $extension
 
 $name
 
 $path
 
 $hashPath
 
 $pageCount
 
 $transformScript
 
 $redirectTitle
 
 $canRender
 
 $isSafeFile
 
 $repoClass = FileRepo::class
 
 $tmpBucketedThumbCache = []
 

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.

Constructor & Destructor Documentation

File::__construct (   $title,
  $repo 
)

Call this constructor from child classes.

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

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

Member Function Documentation

File::allowInlineDisplay ( )

Alias for canRender()

Returns
bool
File::assertRepoDefined ( )
protected

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

Exceptions
MWException
File::assertTitleDefined ( )
protected

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

Exceptions
MWException
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.
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
static File::checkExtensionCompatibility ( File  $old,
  $new 
)
static

Checks if file extensions are compatible

Parameters
File$oldOld file
string$newNew name
Returns
bool|null
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
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)
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
File::delete (   $reason,
  $suppress = false,
  $user = null 
)

Delete all versions of the file.

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

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

Parameters
string$reason
bool$suppressHide content from sysops?
User | null$user
Returns
Status STUB Overridden by LocalFile
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.
File::formatMetadata (   $context = false)
Parameters
bool | IContextSource$contextContext to use (optional)
Returns
bool
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
File::generateThumbName (   $name,
  $params 
)

Generate a thumbnail file name from a name and specified parameters

Parameters
string$name
array$paramsParameters which will be passed to MediaHandler::makeParamString
Returns
string|null
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
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
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
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
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
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
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
File::getAvailableLanguages ( )

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

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

Returns
string[]
Since
1.23
File::getBitDepth ( )

Return the bit depth of the file Overridden by LocalFile STUB

Returns
int
File::getBucketThumbName (   $bucket)
protected

Returns the name of the thumb for a given bucket

Parameters
int$bucket
Returns
string
File::getBucketThumbPath (   $bucket)
protected

Returns the repo path of the thumb for a given bucket

Parameters
int$bucket
Returns
string
File::getCanonicalUrl ( )
Returns
string
File::getCanRender ( )
protected

Accessor for __get()

Returns
bool
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
File::getContentHeaders ( )
Returns
string[] HTTP header name/value map to use for HEAD/GET request responses
Since
1.30
File::getDefaultRenderLanguage ( )

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

Returns
string|null Lang code, or null if filetype doesn't support multiple languages.
Since
1.23
File::getDescription (   $audience = self::FOR_PUBLIC,
User  $user = null 
)

Get description of file revision STUB

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

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

Returns
string|null
Since
1.27
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|false
File::getDescriptionTouched ( )

Returns the timestamp (in TS_MW format) of the last change of the description page. Returns false if the file does not have a description page, or retrieving the timestamp would be expensive.

Since
1.25
Returns
string|bool
File::getDescriptionUrl ( )

Get the URL of the image description page. May return false if it is unknown or not applicable.

Returns
string
File::getDimensionsString ( )
Returns
string
File::getExtension ( )

Get the file extension, e.g. "svg"

Returns
string
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
File::getHandler ( )

Get a MediaHandler instance for this file

Returns
MediaHandler|bool Registered MediaHandler for file's MIME type or false if none found
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
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
File::getHistory (   $limit = null,
  $start = null,
  $end = null,
  $inc = true 
)

Return a fragment of the history of file.

STUB

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

Get an image size array like that returned by getImageSize(), or false if it can't be determined. Loads the image size directly from the file ignoring caches.

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

Accessor for __get()

Returns
bool
File::getIsSafeFileUncached ( )
protected

Uncached accessor

Returns
bool
File::getLastError ( )

Get last thumbnailing error. Largely obsolete.

Returns
string
File::getLength ( )

Get the duration of a media file in seconds

Returns
float|int
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
File::getLongDesc ( )
Returns
string
File::getMatchedLanguage (   $userPreferredLanguage)

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

Parameters
string$userPreferredLanguage
Returns
string|null
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
File::getMetadata ( )

Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB

Returns
bool|array
File::getMimeType ( )

Returns the MIME type of the file. Overridden by LocalFile, UnregisteredLocalFile STUB

Returns
string
File::getName ( )

Return the name of this file

Returns
string
File::getOriginalTitle ( )

Return the title used to find this file

Returns
Title
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
File::getRedirected ( )
Returns
string
File::getRedirectedTitle ( )
Returns
Title|null
File::getRel ( )

Get the path of the file relative to the public zone root. This function is overridden in OldLocalFile to be like getArchiveRel().

Returns
string
File::getRepo ( )

Returns the repository

Returns
FileRepo|LocalRepo|bool
File::getRepoName ( )

Returns the name of the repository.

Returns
string
File::getSha1 ( )

Get the SHA-1 base 36 hash of the file

Returns
string
File::getShortDesc ( )
Returns
string
File::getSize ( )

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

Returns
bool
File::getStorageKey ( )

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

Returns
string|false
File::getStreamHeaders ( )
Deprecated:
since 1.30, use File::getContentHeaders instead
File::getThumbDisposition (   $thumbName,
  $dispositionType = 'inline' 
)
Parameters
string$thumbNameThumbnail name
string$dispositionTypeType of disposition (either "attachment" or "inline")
Returns
string Content-Disposition header value
File::getThumbnailBucket (   $desiredWidth,
  $page = 1 
)

Return the smallest bucket from $wgThumbnailBuckets which is at least $wgThumbnailMinimumBucketDistance larger than $desiredWidth. The returned bucket, if any, will always be bigger than $desiredWidth.

Parameters
int$desiredWidth
int$page
Returns
bool|int
File::getThumbnails ( )

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

Returns
string[]
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
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
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
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
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
File::getTimestamp ( )

Get the 14-character timestamp of the file upload

Returns
string|bool TS_MW timestamp or false on failure
File::getTitle ( )

Return the associated title object

Returns
Title
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
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
File::getTransformScript ( )
Returns
string
File::getUnscaledThumb (   $handlerParams = [])

Get a ThumbnailImage which is the same size as the source

Parameters
array$handlerParams
Returns
ThumbnailImage|MediaTransformOutput|bool False on failure
File::getUrl ( )

Return the URL of the file

Returns
string
File::getUrlRel ( )

Get urlencoded path of the file relative to the public zone root. This function is overridden in OldLocalFile to be like getArchiveUrl().

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

Returns ID or name of user who uploaded the file STUB

Parameters
string$type'text' or 'id'
Returns
string|int
File::getViewURL ( )
Returns
string
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
File::getVisibility ( )

Return the deletion bitfield STUB

Returns
int
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
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
File::iconThumb ( )

Get a ThumbnailImage representing a file type icon

Returns
ThumbnailImage
File::isCacheable ( )

Check if this file object is small and can be cached

Returns
bool
File::isDeleted (   $field)

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

Parameters
int$fieldOne of DELETED_* bitfield constants
Returns
bool
File::isExpensiveToThumbnail ( )

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

Returns
bool
File::isHashed ( )
Returns
bool
File::isLocal ( )

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

Returns
bool
File::isMissing ( )
Returns
bool
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
File::isOld ( )

Returns true if the image is an old version STUB

Returns
bool
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
File::isTransformedLocally ( )

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

Since
1.25
Returns
bool
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
File::isVectorized ( )

Return true if the file is vectorized

Returns
bool
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.
File::load (   $flags = 0)

Load any lazy-loaded file object fields from source

This is only useful when setting $flags

Overridden by LocalFile to actually query the DB

Parameters
int$flagsBitfield of File::READ_* constants
File::makeTransformTmpFile (   $thumbPath)
protected

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

Parameters
string$thumbPathThumbnail path
Returns
TempFSFile|null
File::migrateThumbFile (   $thumbName)

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

Parameters
string$thumbName
File::move (   $target)

Move file to the new title

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

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

Parameters
Title$targetNew file name
Returns
Status
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
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
static File::normalizeExtension (   $extension)
static

Normalize a file extension to the common form, making it lowercase and checking some synonyms, and ensure it's clean. Extensions with non-alphanumeric characters will be discarded. Keep in sync with mw.Title.normalizeExtension() in JS.

Parameters
string$extensionFile extension (without the leading dot)
Returns
string File extension in canonical form
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
File::pageCount ( )

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

Returns
string|bool|int
File::publish (   $src,
  $flags = 0,
array  $options = [] 
)

Move or copy a file to its public location. If a file exists at the destination, move it to an archive. Returns a Status object with the archive name in the "value" member on success.

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

Options to $options include:

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

STUB Overridden by LocalFile

File::purgeCache (   $options = [])

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

Parameters
array$optionsOptions, which include: 'forThumbRefresh' : The purging is only to refresh thumbnails
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.

File::purgeEverything ( )

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

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

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

Parameters
string$oldver
string$desc
string$license
string$copyStatus
string$source
bool$watch
string | bool$timestamp
null | User$userUser object or null to use $wgUser
Returns
bool
Exceptions
MWException
File::redirectedFrom (   $from)
Parameters
string$from
Returns
void
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.

File::restore (   $versions = [],
  $unsuppress = false 
)

Restore all or specified deleted revisions to the given file. Permissions and logging are left to the caller.

May throw database exceptions on error.

Parameters
array$versionsSet of record ids of deleted items to restore, or empty to restore all revisions.
bool$unsuppressRemove restrictions on content upon restoration?
Returns
int|bool The number of file revisions restored if successful, or false on failure STUB Overridden by LocalFile
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
static File::splitMime (   $mime)
static

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

Parameters
string$mime"text/html" etc
Returns
string[] ("text", "html") etc
File::thumbName (   $params,
  $flags = 0 
)

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

Parameters
array$paramsHandler-specific parameters
int$flagsBitfield that supports THUMB_* constants
Returns
string|null
File::transform (   $params,
  $flags = 0 
)

Transform a media file

Parameters
array$paramsAn associative array of handler-specific parameters. Typical keys are width, height and page.
int$flagsA bitfield, may contain self::RENDER_NOW to force rendering
Returns
ThumbnailImage|MediaTransformOutput|bool False on failure
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
File::upgradeRow ( )

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

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

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

Parameters
int$field
User | null$userUser object to check, or null to use $wgUser
Returns
bool
File::wasDeleted ( )

Was this file ever deleted from the wiki?

Returns
bool

Member Data Documentation

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

const File::RENDER_NOW = 1

Force rendering in the current process


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