[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/filerepo/file/ -> File.php (summary)

(no description)

File Size: 2214 lines (58 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 125 functions

  __construct()
  normalizeTitle()
  __get()
  normalizeExtension()
  checkExtensionCompatibility()
  upgradeRow()
  splitMime()
  compare()
  getName()
  getExtension()
  getTitle()
  getOriginalTitle()
  getUrl()
  getFullUrl()
  getCanonicalUrl()
  getViewURL()
  getPath()
  getLocalRefPath()
  getWidth()
  getHeight()
  getThumbnailBucket()
  getUser()
  getLength()
  isVectorized()
  getAvailableLanguages()
  getDefaultRenderLanguage()
  canAnimateThumbIfAppropriate()
  getMetadata()
  getCommonMetaArray()
  convertMetadataVersion()
  getBitDepth()
  getSize()
  getMimeType()
  getMediaType()
  canRender()
  getCanRender()
  mustRender()
  allowInlineDisplay()
  isSafeFile()
  getIsSafeFile()
  getIsSafeFileUncached()
  isTrustedFile()
  exists()
  isVisible()
  getTransformScript()
  getUnscaledThumb()
  thumbName()
  generateThumbName()
  createThumb()
  transformErrorOutput()
  transform()
  generateAndSaveThumb()
  generateBucketsIfNeeded()
  getThumbnailSource()
  getBucketThumbPath()
  getBucketThumbName()
  makeTransformTmpFile()
  getThumbDisposition()
  migrateThumbFile()
  getHandler()
  iconThumb()
  getLastError()
  getThumbnails()
  purgeCache()
  purgeDescription()
  purgeEverything()
  getHistory()
  nextHistoryLine()
  resetHistory()
  getHashPath()
  getRel()
  getArchiveRel()
  getThumbRel()
  getUrlRel()
  getArchiveThumbRel()
  getArchivePath()
  getArchiveThumbPath()
  getThumbPath()
  getTranscodedPath()
  getArchiveUrl()
  getArchiveThumbUrl()
  getZoneUrl()
  getThumbUrl()
  getTranscodedUrl()
  getVirtualUrl()
  getArchiveVirtualUrl()
  getThumbVirtualUrl()
  isHashed()
  readOnlyError()
  recordUpload()
  publish()
  formatMetadata()
  isLocal()
  getRepoName()
  getRepo()
  isOld()
  isDeleted()
  getVisibility()
  wasDeleted()
  move()
  delete()
  restore()
  isMultipage()
  pageCount()
  scaleHeight()
  getImageSize()
  getDescriptionUrl()
  getDescriptionText()
  getDescription()
  getTimestamp()
  getSha1()
  getStorageKey()
  userCan()
  getStreamHeaders()
  getLongDesc()
  getShortDesc()
  getDimensionsString()
  getRedirected()
  getRedirectedTitle()
  redirectedFrom()
  isMissing()
  isCacheable()
  assertRepoDefined()
  assertTitleDefined()
  isExpensiveToThumbnail()

Functions
Functions that are not part of a class:

__construct( $title, $repo )   X-Ref
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.

param: Title|string|bool $title
param: FileRepo|bool $repo

normalizeTitle( $title, $exception = false )   X-Ref
Given a string or Title object return either a
valid Title object with namespace NS_FILE or null

param: Title|string $title
param: string|bool $exception Use 'exception' to throw an error on bad titles
return: Title|null

__get( $name )   X-Ref
No description

normalizeExtension( $ext )   X-Ref
Normalize a file extension to the common form, and ensure it's clean.
Extensions with non-alphanumeric characters will be discarded.

param: string $ext (without the .)
return: string

checkExtensionCompatibility( File $old, $new )   X-Ref
Checks if file extensions are compatible

param: File $old Old file
param: string $new New name
return: bool|null

upgradeRow()   X-Ref
Upgrade the database row if there is one
Called by ImagePage
STUB


splitMime( $mime )   X-Ref
Split an internet media type into its two components; if not
a two-part name, set the minor type to 'unknown'.

param: string $mime "text/html" etc
return: array ("text", "html") etc

compare( File $a, File $b )   X-Ref
Callback for usort() to do file sorts by name

param: File $a
param: File $b
return: int Result of name comparison

getName()   X-Ref
Return the name of this file

return: string

getExtension()   X-Ref
Get the file extension, e.g. "svg"

return: string

getTitle()   X-Ref
Return the associated title object

return: Title

getOriginalTitle()   X-Ref
Return the title used to find this file

return: Title

getUrl()   X-Ref
Return the URL of the file

return: string

getFullUrl()   X-Ref
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.

return: string

getCanonicalUrl()   X-Ref

return: string

getViewURL()   X-Ref

return: string

getPath()   X-Ref
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.

return: string|bool ForeignAPIFile::getPath can return false

getLocalRefPath()   X-Ref
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.

return: string|bool False on failure

getWidth( $page = 1 )   X-Ref
Return the width of the image. Returns false if the width is unknown
or undefined.

STUB
Overridden by LocalFile, UnregisteredLocalFile

param: int $page
return: int|bool

getHeight( $page = 1 )   X-Ref
Return the height of the image. Returns false if the height is unknown
or undefined

STUB
Overridden by LocalFile, UnregisteredLocalFile

param: int $page
return: bool|int False on failure

getThumbnailBucket( $desiredWidth, $page = 1 )   X-Ref
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.

param: int $desiredWidth
param: int $page
return: bool|int

getUser( $type = 'text' )   X-Ref
Returns ID or name of user who uploaded the file
STUB

param: string $type 'text' or 'id'
return: string|int

getLength()   X-Ref
Get the duration of a media file in seconds

return: int

isVectorized()   X-Ref
Return true if the file is vectorized

return: bool

getAvailableLanguages()   X-Ref
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.

return: array

getDefaultRenderLanguage()   X-Ref
In files that support multiple language, what is the default language
to use if none specified.

return: string Lang code, or null if filetype doesn't support multiple languages.

canAnimateThumbIfAppropriate()   X-Ref
Will the thumbnail be animated if one would expect it to be.

Currently used to add a warning to the image description page

return: bool False if the main image is both animated

getMetadata()   X-Ref
Get handler-specific metadata
Overridden by LocalFile, UnregisteredLocalFile
STUB

return: bool|array

getCommonMetaArray()   X-Ref
Like getMetadata but returns a handler independent array of common values.

return: array|bool Array or false if not supported

convertMetadataVersion( $metadata, $version )   X-Ref
get versioned metadata

param: array|string $metadata Array or string of (serialized) metadata
param: int $version Version number.
return: array Array containing metadata, or what was passed to it on fail

getBitDepth()   X-Ref
Return the bit depth of the file
Overridden by LocalFile
STUB

return: int

getSize()   X-Ref
Return the size of the image file, in bytes
Overridden by LocalFile, UnregisteredLocalFile
STUB

return: bool

getMimeType()   X-Ref
Returns the MIME type of the file.
Overridden by LocalFile, UnregisteredLocalFile
STUB

return: string

getMediaType()   X-Ref
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

return: string

canRender()   X-Ref
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.

return: bool

getCanRender()   X-Ref
Accessor for __get()

return: bool

mustRender()   X-Ref
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.

return: bool

allowInlineDisplay()   X-Ref
Alias for canRender()

return: bool

isSafeFile()   X-Ref
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.

return: bool

getIsSafeFile()   X-Ref
Accessor for __get()

return: bool

getIsSafeFileUncached()   X-Ref
Uncached accessor

return: bool

isTrustedFile()   X-Ref
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.

return: bool

exists()   X-Ref
Returns true if file exists in the repository.

Overridden by LocalFile to avoid unnecessary stat calls.

return: bool Whether file exists in the repository.

isVisible()   X-Ref
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

return: bool Whether file exists in the repository and is includable.

getTransformScript()   X-Ref

return: string

getUnscaledThumb( $handlerParams = array()   X-Ref
Get a ThumbnailImage which is the same size as the source

param: array $handlerParams
return: string

thumbName( $params, $flags = 0 )   X-Ref
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>".

param: array $params Handler-specific parameters
param: int $flags Bitfield that supports THUMB_* constants
return: string

generateThumbName( $name, $params )   X-Ref
Generate a thumbnail file name from a name and specified parameters

param: string $name
param: array $params Parameters which will be passed to MediaHandler::makeParamString
return: string

createThumb( $width, $height = -1 )   X-Ref
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.

param: int $width Maximum width of the generated thumbnail
param: int $height Maximum height of the image (optional)
return: string

transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags )   X-Ref
Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors)

param: string $thumbPath Thumbnail storage path
param: string $thumbUrl Thumbnail URL
param: array $params
param: int $flags
return: MediaTransformOutput

transform( $params, $flags = 0 )   X-Ref
Transform a media file

param: array $params An associative array of handler-specific parameters.
param: int $flags A bitfield, may contain self::RENDER_NOW to force rendering
return: MediaTransformOutput|bool False on failure

generateAndSaveThumb( $tmpFile, $transformParams, $flags )   X-Ref
Generates a thumbnail according to the given parameters and saves it to storage

param: TempFSFile $tmpFile Temporary file where the rendered thumbnail will be saved
param: array $transformParams
param: int $flags
return: bool|MediaTransformOutput

generateBucketsIfNeeded( $params, $flags = 0 )   X-Ref
Generates chained bucketed thumbnails if needed

param: array $params
param: int $flags
return: bool Whether at least one bucket was generated

getThumbnailSource( $params )   X-Ref
Returns the most appropriate source image for the thumbnail, given a target thumbnail size

param: array $params
return: array Source path and width/height of the source

getBucketThumbPath( $bucket )   X-Ref
Returns the repo path of the thumb for a given bucket

param: int $bucket
return: string

getBucketThumbName( $bucket )   X-Ref
Returns the name of the thumb for a given bucket

param: int $bucket
return: string

makeTransformTmpFile( $thumbPath )   X-Ref
Creates a temp FS file with the same extension and the thumbnail

param: string $thumbPath Thumbnail path
return: TempFSFile

getThumbDisposition( $thumbName, $dispositionType = 'inline' )   X-Ref

param: string $thumbName Thumbnail name
param: string $dispositionType Type of disposition (either "attachment" or "inline")
return: string Content-Disposition header value

migrateThumbFile( $thumbName )   X-Ref
Hook into transform() to allow migration of thumbnail files
STUB
Overridden by LocalFile

param: string $thumbName

getHandler()   X-Ref
Get a MediaHandler instance for this file

return: MediaHandler|bool Registered MediaHandler for file's MIME type

iconThumb()   X-Ref
Get a ThumbnailImage representing a file type icon

return: ThumbnailImage

getLastError()   X-Ref
Get last thumbnailing error.
Largely obsolete.

return: string

getThumbnails()   X-Ref
Get all thumbnail names previously generated for this file
STUB
Overridden by LocalFile

return: array

purgeCache( $options = array()   X-Ref
Purge shared caches such as thumbnails and DB data caching
STUB
Overridden by LocalFile

param: array $options Options, which include:

purgeDescription()   X-Ref
Purge the file description page, but don't go after
pages using the file. Use when modifying file history
but not the current data.


purgeEverything()   X-Ref
Purge metadata and all affected pages when the file is created,
deleted, or majorly updated.


getHistory( $limit = null, $start = null, $end = null, $inc = true )   X-Ref
Return a fragment of the history of file.

STUB
param: int $limit Limit of rows to return
param: string $start Only revisions older than $start will be returned
param: string $end Only revisions newer than $end will be returned
param: bool $inc Include the endpoints of the time range
return: array

nextHistoryLine()   X-Ref
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
return: bool

resetHistory()   X-Ref
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.


getHashPath()   X-Ref
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.

return: string

getRel()   X-Ref
Get the path of the file relative to the public zone root.
This function is overriden in OldLocalFile to be like getArchiveRel().

return: string

getArchiveRel( $suffix = false )   X-Ref
Get the path of an archived file relative to the public zone root

param: bool|string $suffix If not false, the name of an archived thumbnail file
return: string

getThumbRel( $suffix = false )   X-Ref
Get the path, relative to the thumbnail zone root, of the
thumbnail directory or a particular file if $suffix is specified

param: bool|string $suffix If not false, the name of a thumbnail file
return: string

getUrlRel()   X-Ref
Get urlencoded path of the file relative to the public zone root.
This function is overriden in OldLocalFile to be like getArchiveUrl().

return: string

getArchiveThumbRel( $archiveName, $suffix = false )   X-Ref
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.

param: string $archiveName The timestamped name of an archived image
param: bool|string $suffix If not false, the name of a thumbnail file
return: string

getArchivePath( $suffix = false )   X-Ref
Get the path of the archived file.

param: bool|string $suffix If not false, the name of an archived file.
return: string

getArchiveThumbPath( $archiveName, $suffix = false )   X-Ref
Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified

param: string $archiveName The timestamped name of an archived image
param: bool|string $suffix If not false, the name of a thumbnail file
return: string

getThumbPath( $suffix = false )   X-Ref
Get the path of the thumbnail directory, or a particular file if $suffix is specified

param: bool|string $suffix If not false, the name of a thumbnail file
return: string

getTranscodedPath( $suffix = false )   X-Ref
Get the path of the transcoded directory, or a particular file if $suffix is specified

param: bool|string $suffix If not false, the name of a media file
return: string

getArchiveUrl( $suffix = false )   X-Ref
Get the URL of the archive directory, or a particular file if $suffix is specified

param: bool|string $suffix If not false, the name of an archived file
return: string

getArchiveThumbUrl( $archiveName, $suffix = false )   X-Ref
Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified

param: string $archiveName The timestamped name of an archived image
param: bool|string $suffix If not false, the name of a thumbnail file
return: string

getZoneUrl( $zone, $suffix = false )   X-Ref
Get the URL of the zone directory, or a particular file if $suffix is specified

param: string $zone Name of requested zone
param: bool|string $suffix If not false, the name of a file in zone
return: string Path

getThumbUrl( $suffix = false )   X-Ref
Get the URL of the thumbnail directory, or a particular file if $suffix is specified

param: bool|string $suffix If not false, the name of a thumbnail file
return: string Path

getTranscodedUrl( $suffix = false )   X-Ref
Get the URL of the transcoded directory, or a particular file if $suffix is specified

param: bool|string $suffix If not false, the name of a media file
return: string Path

getVirtualUrl( $suffix = false )   X-Ref
Get the public zone virtual URL for a current version source file

param: bool|string $suffix If not false, the name of a thumbnail file
return: string

getArchiveVirtualUrl( $suffix = false )   X-Ref
Get the public zone virtual URL for an archived version source file

param: bool|string $suffix If not false, the name of a thumbnail file
return: string

getThumbVirtualUrl( $suffix = false )   X-Ref
Get the virtual URL for a thumbnail file or directory

param: bool|string $suffix If not false, the name of a thumbnail file
return: string

isHashed()   X-Ref

return: bool

readOnlyError()   X-Ref


recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',$watch = false, $timestamp = false, User $user = null)   X-Ref
Record a file upload in the upload log and the image table
STUB
Overridden by LocalFile

param: string $oldver
param: string $desc
param: string $license
param: string $copyStatus
param: string $source
param: bool $watch
param: string|bool $timestamp
param: null|User $user User object or null to use $wgUser
return: bool

publish( $srcPath, $flags = 0, array $options = array()   X-Ref
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

param: string $srcPath Local filesystem path to the source image
param: int $flags A bitwise combination of:
param: array $options Optional additional parameters
return: FileRepoStatus On success, the value member contains the

formatMetadata()   X-Ref

return: bool

isLocal()   X-Ref
Returns true if the file comes from the local file repository.

return: bool

getRepoName()   X-Ref
Returns the name of the repository.

return: string

getRepo()   X-Ref
Returns the repository

return: FileRepo|LocalRepo|bool

isOld()   X-Ref
Returns true if the image is an old version
STUB

return: bool

isDeleted( $field )   X-Ref
Is this file a "deleted" file in a private archive?
STUB

param: int $field One of DELETED_* bitfield constants
return: bool

getVisibility()   X-Ref
Return the deletion bitfield
STUB

return: int

wasDeleted()   X-Ref
Was this file ever deleted from the wiki?

return: bool

move( $target )   X-Ref
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

param: Title $target New file name
return: FileRepoStatus

delete( $reason, $suppress = false, $user = null )   X-Ref
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.

param: string $reason
param: bool $suppress Hide content from sysops?
param: User|null $user
return: bool Boolean on success, false on some kind of failure

restore( $versions = array()   X-Ref
Restore all or specified deleted revisions to the given file.
Permissions and logging are left to the caller.

May throw database exceptions on error.

param: array $versions Set of record ids of deleted items to restore,
param: bool $unsuppress Remove restrictions on content upon restoration?
return: int|bool The number of file revisions restored if successful,

isMultipage()   X-Ref
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.

return: bool

pageCount()   X-Ref
Returns the number of pages of a multipage document, or false for
documents which aren't multipage documents

return: bool|int

scaleHeight( $srcWidth, $srcHeight, $dstWidth )   X-Ref
Calculate the height of a thumbnail using the source and destination width

param: int $srcWidth
param: int $srcHeight
param: int $dstWidth
return: int

getImageSize( $filePath )   X-Ref
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.

param: string $filePath The path to the file (e.g. From getLocalPathRef() )
return: array The width, followed by height, with optionally more things after

getDescriptionUrl()   X-Ref
Get the URL of the image description page. May return false if it is
unknown or not applicable.

return: string

getDescriptionText( $lang = false )   X-Ref
Get the HTML text of the description page, if available

param: bool|Language $lang Optional language to fetch description in
return: string

getDescription( $audience = self::FOR_PUBLIC, User $user = null )   X-Ref
Get description of file revision
STUB

param: int $audience One of:
param: User $user User object to check for, only if FOR_THIS_USER is
return: string

getTimestamp()   X-Ref
Get the 14-character timestamp of the file upload

return: string|bool TS_MW timestamp or false on failure

getSha1()   X-Ref
Get the SHA-1 base 36 hash of the file

return: string

getStorageKey()   X-Ref
Get the deletion archive key, "<sha1>.<ext>"

return: string

userCan( $field, User $user = null )   X-Ref
Determine if the current user is allowed to view a particular
field of this file, if it's marked as deleted.
STUB

param: int $field
param: User $user User object to check, or null to use $wgUser
return: bool

getStreamHeaders()   X-Ref

return: array HTTP header name/value map to use for HEAD/GET request responses

getLongDesc()   X-Ref

return: string

getShortDesc()   X-Ref

return: string

getDimensionsString()   X-Ref

return: string

getRedirected()   X-Ref

return: string

getRedirectedTitle()   X-Ref

return: Title|null

redirectedFrom( $from )   X-Ref

param: string $from
return: void

isMissing()   X-Ref

return: bool

isCacheable()   X-Ref
Check if this file object is small and can be cached

return: bool

assertRepoDefined()   X-Ref
Assert that $this->repo is set to a valid FileRepo instance


assertTitleDefined()   X-Ref
Assert that $this->title is set to a Title


isExpensiveToThumbnail()   X-Ref
True if creating thumbnails from the file is large or otherwise resource-intensive.

return: bool



Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1