[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/media/ -> MediaHandler.php (summary)

Media-handling base classes and generic functionality. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

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

Defines 46 functions

  getHandler()
  resetCache()
  getMetadata()
  getMetadataVersion()
  convertMetadataVersion()
  getMetadataType()
  isMetadataValid()
  getCommonMetaArray()
  getScriptedTransform()
  getTransform()
  getThumbType()
  getStreamHeaders()
  canRender()
  mustRender()
  isMultiPage()
  pageCount()
  isVectorized()
  isAnimatedImage()
  canAnimateThumbnail()
  isEnabled()
  getPageDimensions()
  getPageText()
  getEntireText()
  formatMetadata()
  formatMetadataHelper()
  visibleMetadataFields()
  addMeta()
  getShortDesc()
  getLongDesc()
  getGeneralShortDesc()
  getGeneralLongDesc()
  fitBoxWidth()
  getDimensionsString()
  parserTransformHook()
  verifyUpload()
  removeBadFile()
  filterThumbnailPurgeList()
  canRotate()
  getRotation()
  logErrorForExternalProcess()
  getAvailableLanguages()
  getDefaultRenderLanguage()
  getLength()
  isExpensiveToThumbnail()
  supportsBucketing()
  sanitizeParamsForBucketing()

Functions
Functions that are not part of a class:

getHandler( $type )   X-Ref
Get a MediaHandler for a given MIME type from the instance cache

param: string $type
return: MediaHandler

resetCache()   X-Ref
Resets all static caches


getMetadata( $image, $path )   X-Ref
Get handler-specific metadata which will be saved in the img_metadata field.

param: File $image The image object, or false if there isn't one.
param: string $path The filename
return: string A string of metadata in php serialized form (Run through serialize())

getMetadataVersion()   X-Ref
Get metadata version.

This is not used for validating metadata, this is used for the api when returning
metadata, since api content formats should stay the same over time, and so things
using ForeignApiRepo can keep backwards compatibility

All core media handlers share a common version number, and extensions can
use the GetMetadataVersion hook to append to the array (they should append a unique
string so not to get confusing). If there was a media handler named 'foo' with metadata
version 3 it might add to the end of the array the element 'foo=3'. if the core metadata
version is 2, the end version string would look like '2;foo=3'.

return: string Version string

convertMetadataVersion( $metadata, $version = 1 )   X-Ref
Convert metadata version.

By default just returns $metadata, but can be used to allow
media handlers to convert between metadata versions.

param: string|array $metadata Metadata array (serialized if string)
param: int $version Target version
return: array Serialized metadata in specified version, or $metadata on fail.

getMetadataType( $image )   X-Ref
Get a string describing the type of metadata, for display purposes.

param: File $image
return: string

isMetadataValid( $image, $metadata )   X-Ref
Check if the metadata string is valid for this handler.
If it returns MediaHandler::METADATA_BAD (or false), Image
will reload the metadata from the file and update the database.
MediaHandler::METADATA_GOOD for if the metadata is a-ok,
MediaHandler::METADATA_COMPATIBLE if metadata is old but backwards
compatible (which may or may not trigger a metadata reload).

param: File $image
param: string $metadata The metadata in serialized form
return: bool

getCommonMetaArray( File $file )   X-Ref
Get an array of standard (FormatMetadata type) metadata values.

The returned data is largely the same as that from getMetadata(),
but formatted in a standard, stable, handler-independent way.
The idea being that some values like ImageDescription or Artist
are universal and should be retrievable in a handler generic way.

The specific properties are the type of properties that can be
handled by the FormatMetadata class. These values are exposed to the
user via the filemetadata parser function.

Details of the response format of this function can be found at
https://www.mediawiki.org/wiki/Manual:File_metadata_handling
tl/dr: the response is an associative array of
properties keyed by name, but the value can be complex. You probably
want to call one of the FormatMetadata::flatten* functions on the
property values before using them, or call
FormatMetadata::getFormattedData() on the full response array, which
transforms all values into prettified, human-readable text.

Subclasses overriding this function must return a value which is a
valid API response fragment (all associative array keys are valid
XML tagnames).

Note, if the file simply has no metadata, but the handler supports
this interface, it should return an empty array, not false.

param: File $file
return: array|bool False if interface not supported

getScriptedTransform( $image, $script, $params )   X-Ref
Get a MediaTransformOutput object representing an alternate of the transformed
output which will call an intermediary thumbnail assist script.

Used when the repository has a thumbnailScriptUrl option configured.

Return false to fall back to the regular getTransform().
param: File $image
param: string $script
param: array $params
return: bool|ThumbnailImage

getTransform( $image, $dstPath, $dstUrl, $params )   X-Ref
Get a MediaTransformOutput object representing the transformed output. Does not
actually do the transform.

param: File $image The image object
param: string $dstPath Filesystem destination path
param: string $dstUrl Destination URL to use in output HTML
param: array $params Arbitrary set of parameters validated by $this->validateParam()
return: MediaTransformOutput

getThumbType( $ext, $mime, $params = null )   X-Ref
Get the thumbnail extension and MIME type for a given source MIME type

param: string $ext Extension of original file
param: string $mime MIME type of original file
param: array $params Handler specific rendering parameters
return: array Thumbnail extension and MIME type

getStreamHeaders( $metadata )   X-Ref
Get useful response headers for GET/HEAD requests for a file with the given metadata

param: mixed $metadata Result of the getMetadata() function of this handler for a file
return: array

canRender( $file )   X-Ref
True if the handled types can be transformed

param: File $file
return: bool

mustRender( $file )   X-Ref
True if handled types cannot be displayed directly in a browser
but can be rendered

param: File $file
return: bool

isMultiPage( $file )   X-Ref
True if the type has multi-page capabilities

param: File $file
return: bool

pageCount( $file )   X-Ref
Page count for a multi-page document, false if unsupported or unknown

param: File $file
return: bool

isVectorized( $file )   X-Ref
The material is vectorized and thus scaling is lossless

param: File $file
return: bool

isAnimatedImage( $file )   X-Ref
The material is an image, and is animated.
In particular, video material need not return true.

param: File $file
return: bool

canAnimateThumbnail( $file )   X-Ref
If the material is animated, we can animate the thumbnail

param: File $file
return: bool If material is not animated, handler may return any value.

isEnabled()   X-Ref
False if the handler is disabled for all files

return: bool

getPageDimensions( $image, $page )   X-Ref
Get an associative array of page dimensions
Currently "width" and "height" are understood, but this might be
expanded in the future.
Returns false if unknown.

It is expected that handlers for paged media (e.g. DjVuHandler)
will override this method so that it gives the correct results
for each specific page of the file, using the $page argument.

param: File $image
param: int $page What page to get dimensions of
return: array|bool

getPageText( $image, $page )   X-Ref
Generic getter for text layer.
Currently overloaded by PDF and DjVu handlers

param: File $image
param: int $page Page number to get information for
return: bool|string Page text or false when no text found or if

getEntireText( File $file )   X-Ref
Get the text of the entire document.

param: File $file
return: bool|string The text of the document or false if unsupported.

formatMetadata( $image )   X-Ref

param: File $image
return: array|bool

formatMetadataHelper( $metadataArray )   X-Ref
No description

visibleMetadataFields()   X-Ref
Get a list of metadata items which should be displayed when
the metadata table is collapsed.

return: array Array of strings

addMeta( &$array, $visibility, $type, $id, $value, $param = false )   X-Ref
This is used to generate an array element for each metadata value
That array is then used to generate the table of metadata values
on the image page

param: array &$array An array containing elements for each type of visibility
param: string $visibility ('visible' or 'collapsed') if this value is hidden
param: string $type Type of metadata tag (currently always 'exif')
param: string $id The name of the metadata tag (like 'artist' for example).
param: string $value Thingy goes into a wikitext table; it used to be escaped but
param: bool|string $param Value to pass to the message for the name of the field

getShortDesc( $file )   X-Ref
Short description. Shown on Special:Search results.

param: File $file
return: string

getLongDesc( $file )   X-Ref
Long description. Shown under image on image description page surounded by ().

param: File $file
return: string

getGeneralShortDesc( $file )   X-Ref
Used instead of getShortDesc if there is no handler registered for file.

param: File $file
return: string

getGeneralLongDesc( $file )   X-Ref
Used instead of getLongDesc if there is no handler registered for file.

param: File $file
return: string

fitBoxWidth( $boxWidth, $boxHeight, $maxHeight )   X-Ref
Calculate the largest thumbnail width for a given original file size
such that the thumbnail's height is at most $maxHeight.

param: int $boxWidth Width of the thumbnail box.
param: int $boxHeight Height of the thumbnail box.
param: int $maxHeight Maximum height expected for the thumbnail.
return: int

getDimensionsString( $file )   X-Ref
Shown in file history box on image description page.

param: File $file
return: string Dimensions

parserTransformHook( $parser, $file )   X-Ref
Modify the parser object post-transform.

This is often used to do $parser->addOutputHook(),
in order to add some javascript to render a viewer.
See TimedMediaHandler or OggHandler for an example.

param: Parser $parser
param: File $file

verifyUpload( $fileName )   X-Ref
File validation hook called on upload.

If the file at the given local path is not valid, or its MIME type does not
match the handler class, a Status object should be returned containing
relevant errors.

param: string $fileName The local path to the file.
return: Status

removeBadFile( $dstPath, $retval = 0 )   X-Ref
Check for zero-sized thumbnails. These can be generated when
no disk space is available or some other error occurs

param: string $dstPath The location of the suspect file
param: int $retval Return value of some shell process, file will be deleted if this is non-zero
return: bool True if removed, false otherwise

filterThumbnailPurgeList( &$files, $options )   X-Ref
Remove files from the purge list.

This is used by some video handlers to prevent ?action=purge
from removing a transcoded video, which is expensive to
regenerate.

param: array $files
param: array $options Purge options. Currently will always be

canRotate()   X-Ref
True if the handler can rotate the media

return: bool

getRotation( $file )   X-Ref
On supporting image formats, try to read out the low-level orientation
of the file and return the angle that the file needs to be rotated to
be viewed.

This information is only useful when manipulating the original file;
the width and height we normally work with is logical, and will match
any produced output views.

For files we don't know, we return 0.

param: File $file
return: int 0, 90, 180 or 270

logErrorForExternalProcess( $retval, $err, $cmd )   X-Ref
Log an error that occurred in an external process

Moved from BitmapHandler to MediaHandler with MediaWiki 1.23

param: int $retval
param: string $err Error reported by command. Anything longer than
param: string $cmd

getAvailableLanguages( File $file )   X-Ref
Get list of languages file can be viewed in.

param: File $file
return: string[] Array of language codes, or empty array if unsupported.

getDefaultRenderLanguage( File $file )   X-Ref
On file types that support renderings in multiple languages,
which language is used by default if unspecified.

If getAvailableLanguages returns a non-empty array, this must return
a valid language code. Otherwise can return null if files of this
type do not support alternative language renderings.

param: File $file
return: string|null Language code or null if multi-language not supported for filetype.

getLength( $file )   X-Ref
If its an audio file, return the length of the file. Otherwise 0.

File::getLength() existed for a long time, but was calling a method
that only existed in some subclasses of this class (The TMH ones).

param: File $file
return: float Length in seconds

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

param: File $file
return: bool

supportsBucketing()   X-Ref
Returns whether or not this handler supports the chained generation of thumbnails according
to buckets

return: bool

sanitizeParamsForBucketing( $params )   X-Ref
Returns a normalised params array for which parameters have been cleaned up for bucketing
purposes

param: array $params
return: array



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