MediaWiki REL1_37
|
Format Image metadata values into a human readable form. More...
Public Member Functions | |
collapseContactInfo (array $vals) | |
Format the contact info field into a single value. | |
fetchExtendedMetadata (File $file) | |
Get an array of extended metadata. | |
flattenArrayReal ( $vals, $type='ul', $noHtml=false) | |
A function to collapse multivalued tags into a single value. | |
makeFormattedData ( $tags) | |
Numbers given by Exif user agents are often magical, that is they should be replaced by a detailed explanation depending on their value which most of the time are plain integers. | |
setSingleLanguage ( $val) | |
Trigger only outputting single language for multilanguage fields. | |
Public Member Functions inherited from ContextSource | |
canUseWikiPage () | |
Check whether a WikiPage object can be get with getWikiPage(). | |
exportSession () | |
Export the resolved user IP, HTTP headers, user ID, and session ID. | |
getAuthority () | |
getConfig () | |
getContext () | |
Get the base IContextSource object. | |
getCsrfTokenSet () | |
Get a repository to obtain and match CSRF tokens. | |
getLanguage () | |
getOutput () | |
getRequest () | |
getSkin () | |
getStats () | |
getTiming () | |
getTitle () | |
getUser () | |
getWikiPage () | |
Get the WikiPage object. | |
msg ( $key,... $params) | |
Get a Message object with context set Parameters are the same as wfMessage() | |
setContext (IContextSource $context) | |
Static Public Member Functions | |
static | flattenArrayContentLang ( $vals, $type='ul', $noHtml=false, $context=false) |
Flatten an array, using the content language for any messages. | |
static | getFormattedData ( $tags, $context=false) |
Numbers given by Exif user agents are often magical, that is they should be replaced by a detailed explanation depending on their value which most of the time are plain integers. | |
static | getVisibleFields () |
Get a list of fields that are visible by default. | |
Protected Member Functions | |
discardMultipleValues (&$metadata) | |
Takes an array returned by the getExtendedMetadata* functions, and turns all fields into single-valued ones by dropping extra values. | |
getExtendedMetadataFromFile (File $file) | |
Get file-based metadata in standardized format. | |
getExtendedMetadataFromHook (File $file, array $extendedMetadata, &$maxCacheTime) | |
Get additional metadata from hooks in standardized format. | |
getPriorityLanguages () | |
Returns a list of languages (first is best) to use when formatting multilang fields, based on user and site preferences. | |
literal ( $val) | |
Convenience function for getFormattedData() | |
resolveMultilangMetadata (&$metadata) | |
Takes an array returned by the getExtendedMetadata* functions, and resolves multi-language values in it. | |
resolveMultilangValue ( $value) | |
Turns an XMP-style multilang array into a single value. | |
resolveMultivalueValue ( $value) | |
Turns an XMP-style multivalue array into a single value by dropping all but the first value. | |
sanitizeArrayForAPI (&$arr) | |
Makes sure the given array is a valid API response fragment. | |
sanitizeKeyForAPI ( $key) | |
Turns a string into a valid API identifier. | |
Protected Attributes | |
bool | $singleLang = false |
Only output a single language for multi-language fields. | |
Private Member Functions | |
convertNewsCode ( $val) | |
Fetch the human readable version of a news code. | |
exifMsg ( $tag, $val, $arg=null, $arg2=null) | |
Convenience function for getFormattedData() | |
formatCoords ( $coord, string $type) | |
Format a coordinate value, convert numbers from floating point into degree minute second representation. | |
formatFraction ( $num) | |
Format a rational number, reducing fractions. | |
formatNum ( $num, $round=false, $tagName=null) | |
Format a number, convert numbers from fractions into floating point numbers, joins arrays of numbers with commas. | |
gcd ( $a, $b) | |
Calculate the greatest common divisor of two integers. | |
langItem ( $value, $lang, $default=false, $noHtml=false) | |
Helper function for creating lists of translations. | |
Format Image metadata values into a human readable form.
Note lots of these messages use the prefix 'exif' even though they may not be exif properties. For example 'exif-ImageDescription' can be the Exif ImageDescription, or it could be the iptc-iim caption property, or it could be the xmp dc:description property. This is because these messages should be independent of how the data is stored, sine the user doesn't care if the description is stored in xmp, exif, etc only that its a description. (Additionally many of these properties are merged together following the MWG standard, such that for example, exif properties override XMP properties that mean the same thing if there is a conflict).
It should perhaps use a prefix like 'metadata' instead, but there is already a large number of messages using the 'exif' prefix.
Definition at line 54 of file FormatMetadata.php.
FormatMetadata::collapseContactInfo | ( | array | $vals | ) |
Format the contact info field into a single value.
This function might be called from ExifBitmapHandler::convertMetadataVersion which is why it is public.
array | $vals | Array with fields of the ContactInfo struct defined in the IPTC4XMP spec. Or potentially an array with one element that is a free form text value from the older iptc iim 1:118 prop. |
Definition at line 1598 of file FormatMetadata.php.
References flattenArrayReal(), literal(), and ContextSource\msg().
Referenced by ExifBitmapHandler\convertMetadataVersion(), and makeFormattedData().
|
private |
Fetch the human readable version of a news code.
A news code is an 8 digit code. The first two digits are a general classification, so we just translate that.
Note, leading 0's are significant, so this is a string, not an int.
string | $val | The 8 digit news code. |
Definition at line 1474 of file FormatMetadata.php.
References exifMsg(), and literal().
Referenced by makeFormattedData().
|
protected |
Takes an array returned by the getExtendedMetadata* functions, and turns all fields into single-valued ones by dropping extra values.
array | &$metadata |
Definition at line 1946 of file FormatMetadata.php.
References resolveMultivalueValue().
Referenced by fetchExtendedMetadata().
|
private |
Convenience function for getFormattedData()
string | $tag | The tag name to pass on |
string | int | $val | The value of the tag |
string | null | $arg | A wikitext argument to pass ($1) |
string | null | $arg2 | A 2nd wikitext argument to pass ($2) |
Definition at line 1354 of file FormatMetadata.php.
References ContextSource\msg().
Referenced by convertNewsCode(), and makeFormattedData().
FormatMetadata::fetchExtendedMetadata | ( | File | $file | ) |
Get an array of extended metadata.
(See the imageinfo API for format.)
]], or [] on error
Definition at line 1735 of file FormatMetadata.php.
References $cache, $file, discardMultipleValues(), getExtendedMetadataFromFile(), getExtendedMetadataFromHook(), ContextSource\getLanguage(), resolveMultilangMetadata(), sanitizeArrayForAPI(), and wfTimestampNow().
|
static |
Flatten an array, using the content language for any messages.
array | $vals | Array of values |
string | $type | Type of array (either lang, ul, ol). lang = language assoc array with keys being the lang code ul = unordered list, ol = ordered list type can also come from the '_type' member of $vals. |
bool | IContextSource | $noHtml | If to avoid returning anything resembling HTML. (Ugly hack for backwards compatibility with old MediaWiki). Setting this parameter to true is deprecated since 1.36. This parameter can be set to a context, in which case it will be used for $context and $noHtml will default to false. |
bool | IContextSource | $context |
Definition at line 1115 of file FormatMetadata.php.
References ContextSource\$context, $type, ContextSource\setContext(), and wfDeprecated().
FormatMetadata::flattenArrayReal | ( | $vals, | |
$type = 'ul' , |
|||
$noHtml = false |
|||
) |
A function to collapse multivalued tags into a single value.
This turns an array of (for example) authors into a bulleted list.
This is public on the basis it might be useful outside of this class.
array | $vals | Array of values |
string | $type | Type of array (either lang, ul, ol). lang = language assoc array with keys being the lang code ul = unordered list, ol = ordered list type can also come from the '_type' member of $vals. |
bool | $noHtml | If to avoid returning anything resembling HTML. (Ugly hack for backwards compatibility with old mediawiki). |
Definition at line 1154 of file FormatMetadata.php.
References $content, $lang, $type, getPriorityLanguages(), langItem(), and wfDebug().
Referenced by collapseContactInfo(), and makeFormattedData().
|
private |
Format a coordinate value, convert numbers from floating point into degree minute second representation.
float | string | $coord | Expected to be a number or numeric string in degrees |
string | $type | "latitude" or "longitude" |
Definition at line 1549 of file FormatMetadata.php.
References $type, formatNum(), literal(), ContextSource\msg(), and wfDebugLog().
Referenced by makeFormattedData().
|
private |
Format a rational number, reducing fractions.
mixed | $num | The value to format |
Definition at line 1420 of file FormatMetadata.php.
References formatNum(), and gcd().
Referenced by makeFormattedData().
|
private |
Format a number, convert numbers from fractions into floating point numbers, joins arrays of numbers with commas.
mixed | $num | The value to format |
float | int | bool | $round | Digits to round to or false. |
string | null | $tagName | (optional) The name of the tag (for debugging) |
Definition at line 1375 of file FormatMetadata.php.
References formatNum(), ContextSource\getLanguage(), and literal().
Referenced by formatCoords(), formatFraction(), formatNum(), and makeFormattedData().
|
private |
Calculate the greatest common divisor of two integers.
int | $a | Numerator |
int | $b | Denominator |
Definition at line 1442 of file FormatMetadata.php.
Referenced by formatFraction().
|
protected |
Get file-based metadata in standardized format.
Note that for a remote file, this might return metadata supplied by extensions.
]], or [] on error
Definition at line 1785 of file FormatMetadata.php.
References $file, $title, and wfTimestamp().
Referenced by fetchExtendedMetadata().
|
protected |
Get additional metadata from hooks in standardized format.
File | $file | File to use |
array | $extendedMetadata | |
int | &$maxCacheTime | Hook handlers might use this parameter to override cache time |
]], or [] on error
Definition at line 1834 of file FormatMetadata.php.
References $file, and ContextSource\getContext().
Referenced by fetchExtendedMetadata().
|
static |
Numbers given by Exif user agents are often magical, that is they should be replaced by a detailed explanation depending on their value which most of the time are plain integers.
This function formats Exif (and other metadata) values into human readable form.
This is the usual entry point for this class.
array | $tags | The Exif data to format ( as returned by Exif::getFilteredData() or BitmapMetadataHandler ) |
IContextSource | false | $context |
Definition at line 87 of file FormatMetadata.php.
References ContextSource\$context, and ContextSource\setContext().
Referenced by MediaHandler\formatMetadataHelper().
|
protected |
Returns a list of languages (first is best) to use when formatting multilang fields, based on user and site preferences.
Definition at line 2028 of file FormatMetadata.php.
References ContextSource\getLanguage().
Referenced by flattenArrayReal(), and resolveMultilangValue().
|
static |
Get a list of fields that are visible by default.
Definition at line 1714 of file FormatMetadata.php.
References $line, $lines, $matches, and wfMessage().
Referenced by MediaHandler\visibleMetadataFields().
|
private |
Helper function for creating lists of translations.
string | $value | Value (this is not escaped) |
string | $lang | Lang code of item or false |
bool | $default | If it is default value. |
bool | $noHtml | If to avoid html (for back-compat) |
MWException |
Definition at line 1275 of file FormatMetadata.php.
References $lang, literal(), and ContextSource\msg().
Referenced by flattenArrayReal().
|
protected |
Convenience function for getFormattedData()
string | int | $val | The literal value |
Definition at line 1337 of file FormatMetadata.php.
Referenced by collapseContactInfo(), convertNewsCode(), formatCoords(), formatNum(), langItem(), and makeFormattedData().
FormatMetadata::makeFormattedData | ( | $tags | ) |
Numbers given by Exif user agents are often magical, that is they should be replaced by a detailed explanation depending on their value which most of the time are plain integers.
This function formats Exif (and other metadata) values into human readable form.
array | $tags | The Exif data to format ( as returned by Exif::getFilteredData() or BitmapMetadataHandler ) |
Definition at line 107 of file FormatMetadata.php.
References $lang, $s, $type, collapseContactInfo(), convertNewsCode(), exifMsg(), flattenArrayReal(), formatCoords(), formatFraction(), formatNum(), ContextSource\getLanguage(), literal(), ContextSource\msg(), and wfTimestamp().
|
protected |
Takes an array returned by the getExtendedMetadata* functions, and resolves multi-language values in it.
array | &$metadata |
Definition at line 1929 of file FormatMetadata.php.
References resolveMultilangValue().
Referenced by fetchExtendedMetadata().
|
protected |
Turns an XMP-style multilang array into a single value.
If the value is not a multilang array, it is returned unchanged. See mediawiki.org/wiki/Manual:File_metadata_handling::Multi-language_array_format
mixed | $value |
Definition at line 1863 of file FormatMetadata.php.
References $lang, and getPriorityLanguages().
Referenced by resolveMultilangMetadata().
|
protected |
Turns an XMP-style multivalue array into a single value by dropping all but the first value.
If the value is not a multivalue array (or a multivalue array inside a multilang array), it is returned unchanged. See mediawiki.org/wiki/Manual:File_metadata_handling::Multi-language_array_format
mixed | $value |
Definition at line 1904 of file FormatMetadata.php.
References resolveMultivalueValue().
Referenced by discardMultipleValues(), and resolveMultivalueValue().
|
protected |
Makes sure the given array is a valid API response fragment.
array | &$arr |
Definition at line 1966 of file FormatMetadata.php.
References $keys, sanitizeArrayForAPI(), and sanitizeKeyForAPI().
Referenced by fetchExtendedMetadata(), and sanitizeArrayForAPI().
|
protected |
Turns a string into a valid API identifier.
string | $key |
Definition at line 2004 of file FormatMetadata.php.
Referenced by sanitizeArrayForAPI().
FormatMetadata::setSingleLanguage | ( | $val | ) |
Trigger only outputting single language for multilanguage fields.
bool | $val |
Definition at line 70 of file FormatMetadata.php.
Referenced by ApiQueryImageInfo\getInfo().
|
protected |
Only output a single language for multi-language fields.
Definition at line 62 of file FormatMetadata.php.