[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/ -> MimeMagic.php (summary)

Module defining helper functions for detecting and dealing with MIME types. 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: 1150 lines (36 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class

MimeMagic:: (19 methods):
  __construct()
  singleton()
  addExtraTypes()
  addExtraInfo()
  getExtensionsForType()
  getTypesForExtension()
  guessTypesForExtension()
  isMatchingExtension()
  isPHPImageType()
  isRecognizableExtension()
  improveTypeFromExtension()
  guessMimeType()
  doGuessMimeType()
  detectZipType()
  detectMimeType()
  getMediaType()
  findMediaType()
  getIEMimeTypes()
  getIEContentAnalyzer()


Class: MimeMagic  - X-Ref

Implements functions related to MIME types such as detection and mapping to
file extension.

Instances of this class are stateless, there only needs to be one global instance
of MimeMagic. Please use MimeMagic::singleton() to get that instance.
__construct( Config $config = null )   X-Ref


singleton()   X-Ref
Get an instance of this class

return: MimeMagic

addExtraTypes( $types )   X-Ref
Adds to the list mapping MIME to file extensions.
As an extension author, you are encouraged to submit patches to
MediaWiki's core to add new MIME types to mime.types.

param: string $types

addExtraInfo( $info )   X-Ref
Adds to the list mapping MIME to media type.
As an extension author, you are encouraged to submit patches to
MediaWiki's core to add new MIME info to mime.info.

param: string $info

getExtensionsForType( $mime )   X-Ref
Returns a list of file extensions for a given MIME type as a space
separated string or null if the MIME type was unrecognized. Resolves
MIME type aliases.

param: string $mime
return: string|null

getTypesForExtension( $ext )   X-Ref
Returns a list of MIME types for a given file extension as a space
separated string or null if the extension was unrecognized.

param: string $ext
return: string|null

guessTypesForExtension( $ext )   X-Ref
Returns a single MIME type for a given file extension or null if unknown.
This is always the first type from the list returned by getTypesForExtension($ext).

param: string $ext
return: string|null

isMatchingExtension( $extension, $mime )   X-Ref
Tests if the extension matches the given MIME type. Returns true if a
match was found, null if the MIME type is unknown, and false if the
MIME type is known but no matches where found.

param: string $extension
param: string $mime
return: bool|null

isPHPImageType( $mime )   X-Ref
Returns true if the MIME type is known to represent an image format
supported by the PHP GD library.

param: string $mime
return: bool

isRecognizableExtension( $extension )   X-Ref
Returns true if the extension represents a type which can
be reliably detected from its content. Use this to determine
whether strict content checks should be applied to reject
invalid uploads; if we can't identify the type we won't
be able to say if it's invalid.

param: string $extension
return: bool

improveTypeFromExtension( $mime, $ext )   X-Ref
Improves a MIME type using the file extension. Some file formats are very generic,
so their MIME type is not very meaningful. A more useful MIME type can be derived
by looking at the file extension. Typically, this method would be called on the
result of guessMimeType().

param: string $mime The MIME type, typically guessed from a file's content.
param: string $ext The file extension, as taken from the file name
return: string The MIME type

guessMimeType( $file, $ext = true )   X-Ref
MIME type detection. This uses detectMimeType to detect the MIME type
of the file, but applies additional checks to determine some well known
file formats that may be missed or misinterpreted by the default MIME
detection (namely XML based formats like XHTML or SVG, as well as ZIP
based formats like OPC/ODF files).

param: string $file The file to check
param: string|bool $ext The file extension, or true (default) to extract it from the filename.
return: string The MIME type of $file

doGuessMimeType( $file, $ext )   X-Ref
Guess the MIME type from the file contents.

param: string $file
param: mixed $ext
return: bool|string

detectZipType( $header, $tail = null, $ext = false )   X-Ref
Detect application-specific file type of a given ZIP file from its
header data.  Currently works for OpenDocument and OpenXML types...
If can't tell, returns 'application/zip'.

param: string $header Some reasonably-sized chunk of file header
param: string|null $tail The tail of the file
param: string|bool $ext The file extension, or true to extract it from the filename.
return: string

detectMimeType( $file, $ext = true )   X-Ref
Internal MIME type detection. Detection is done using an external
program, if $wgMimeDetectorCommand is set. Otherwise, the fileinfo
extension is tried if it is available. If detection fails and $ext
is not false, the MIME type is guessed from the file extension,
using guessTypesForExtension.

If the MIME type is still unknown, getimagesize is used to detect the
MIME type if the file is an image. If no MIME type can be determined,
this function returns 'unknown/unknown'.

param: string $file The file to check
param: string|bool $ext The file extension, or true (default) to extract it from the filename.
return: string The MIME type of $file

getMediaType( $path = null, $mime = null )   X-Ref
Determine the media type code for a file, using its MIME type, name and
possibly its contents.

This function relies on the findMediaType(), mapping extensions and MIME
types to media types.

param: string $path Full path to the image file, in case we have to look at the contents
param: string $mime MIME type. If null it will be guessed using guessMimeType.
return: string A value to be used with the MEDIATYPE_xxx constants.

findMediaType( $extMime )   X-Ref
Returns a media code matching the given MIME type or file extension.
File extensions are represented by a string starting with a dot (.) to
distinguish them from MIME types.

This function relies on the mapping defined by $this->mMediaTypes
param: string $extMime
return: int|string

getIEMimeTypes( $fileName, $chunk, $proposed )   X-Ref
Get the MIME types that various versions of Internet Explorer would
detect from a chunk of the content.

param: string $fileName The file name (unused at present)
param: string $chunk The first 256 bytes of the file
param: string $proposed The MIME type proposed by the server
return: array

getIEContentAnalyzer()   X-Ref
Get a cached instance of IEContentAnalyzer

return: IEContentAnalyzer



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