MediaWiki
1.23.2
|
Format Image metadata values into a human readable form. More...
Public Member Functions | |
collapseContactInfo ( $vals) | |
Format the contact info field into a single value. More... | |
fetchExtendedMetadata (File $file) | |
Get an array of extended metadata. More... | |
flattenArrayReal ( $vals, $type='ul', $noHtml=false) | |
A function to collapse multivalued tags into a single value. More... | |
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. More... | |
setSingleLanguage ( $val) | |
Trigger only outputting single language for multilanguage fields. More... | |
Public Member Functions inherited from ContextSource | |
canUseWikiPage () | |
Check whether a WikiPage object can be get with getWikiPage(). More... | |
exportSession () | |
Export the resolved user IP, HTTP headers, user ID, and session ID. More... | |
getConfig () | |
Get the Config object. More... | |
getContext () | |
Get the RequestContext object. More... | |
getLang () | |
Get the Language object. More... | |
getLanguage () | |
Get the Language object. More... | |
getOutput () | |
Get the OutputPage object. More... | |
getRequest () | |
Get the WebRequest object. More... | |
getSkin () | |
Get the Skin object. More... | |
getTitle () | |
Get the Title object. More... | |
getUser () | |
Get the User object. More... | |
getWikiPage () | |
Get the WikiPage object. More... | |
msg () | |
Get a Message object with context set Parameters are the same as wfMessage() More... | |
setContext (IContextSource $context) | |
Set the IContextSource object. More... | |
Static Public Member Functions | |
static | flattenArray ( $vals, $type='ul', $noHtml=false, $context=false) |
Flatten an array, using the user language for any messages. More... | |
static | flattenArrayContentLang ( $vals, $type='ul', $noHtml=false, $context=false) |
Flatten an array, using the content language for any messages. More... | |
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. More... | |
static | getVisibleFields () |
Get a list of fields that are visible by default. More... | |
Protected Member Functions | |
getExtendedMetadataFromFile (File $file) | |
Get file-based metadata in standardized format. More... | |
getExtendedMetadataFromHook (File $file, array $extendedMetadata, &$maxCacheTime) | |
Get additional metadata from hooks in standardized format. More... | |
getPriorityLanguages () | |
Returns a list of languages (first is best) to use when formatting multilang fields, based on user and site preferences. More... | |
resolveMultilangMetadata (&$metadata) | |
Takes an array returned by the getExtendedMetadata* functions, and resolves multi-language values in it. More... | |
resolveMultilangValue ( $value) | |
Turns an XMP-style multilang array into a single value. More... | |
sanitizeArrayForXml (&$arr) | |
Makes sure the given array is a valid API response fragment (can be transformed into XML) More... | |
sanitizeKeyForXml ( $key) | |
Turns a string into a valid XML identifier. More... | |
Protected Attributes | |
bool | $singleLang = false |
Only output a single language for multi-language fields. More... | |
Private Member Functions | |
convertNewsCode ( $val) | |
Fetch the human readable version of a news code. More... | |
exifMsg ( $tag, $val, $arg=null, $arg2=null) | |
Convenience function for getFormattedData() More... | |
formatCoords ( $coord, $type) | |
Format a coordinate value, convert numbers from floating point into degree minute second representation. More... | |
formatFraction ( $num) | |
Format a rational number, reducing fractions. More... | |
formatNum ( $num, $round=false) | |
Format a number, convert numbers from fractions into floating point numbers, joins arrays of numbers with commas. More... | |
gcd ( $a, $b) | |
Calculate the greatest common divisor of two integers. More... | |
langItem ( $value, $lang, $default=false, $noHtml=false) | |
Helper function for creating lists of translations. More... | |
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 49 of file FormatMetadata.php.
FormatMetadata::collapseContactInfo | ( | $vals | ) |
Format the contact info field into a single value.
This function might be called from JpegHandler::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 1456 of file FormatMetadata.php.
References array(), as, flattenArrayReal(), 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 1338 of file FormatMetadata.php.
References exifMsg().
Referenced by makeFormattedData().
|
private |
Convenience function for getFormattedData()
string | $tag | The tag name to pass on |
string | $val | The value of the tag |
string | $arg | An argument to pass ($1) |
string | $arg2 | A 2nd argument to pass ($2) |
Definition at line 1229 of file FormatMetadata.php.
References $wgContLang, global, ContextSource\msg(), and text.
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 1595 of file FormatMetadata.php.
References $file, $wgMemc, array(), File\DELETED_FILE, getExtendedMetadataFromFile(), getExtendedMetadataFromHook(), ContextSource\getLanguage(), global, resolveMultilangMetadata(), sanitizeArrayForXml(), wfMemcKey(), wfProfileIn(), wfProfileOut(), wfRunHooks(), and wfTimestampNow().
|
static |
Flatten an array, using the user 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 | $noHtml | If to avoid returning anything resembling HTML. (Ugly hack for backwards compatibility with old MediaWiki). |
bool | IContextSource | $context |
Definition at line 1018 of file FormatMetadata.php.
References ContextSource\$context, $type, and ContextSource\setContext().
Referenced by FormatMetadataTest\testFlattenArray().
|
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 | $noHtml | If to avoid returning anything resembling HTML. (Ugly hack for backwards compatibility with old MediaWiki). |
bool | IContextSource | $context |
Definition at line 990 of file FormatMetadata.php.
References ContextSource\$context, $type, $wgContLang, global, and ContextSource\setContext().
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. |
$noHtml | Boolean If to avoid returning anything resembling HTML. (Ugly hack for backwards compatibility with old mediawiki). |
Definition at line 1043 of file FormatMetadata.php.
References $type, array(), as, getPriorityLanguages(), langItem(), Html\rawElement(), and wfDebug().
Referenced by collapseContactInfo(), and makeFormattedData().
|
private |
Format a coordinate value, convert numbers from floating point into degree minute second representation.
int | $coord | Degrees, minutes and seconds |
string | $type | Latitude or longitude (for if its a NWS or E) |
Definition at line 1413 of file FormatMetadata.php.
References $type, formatNum(), and ContextSource\msg().
Referenced by makeFormattedData().
|
private |
Format a rational number, reducing fractions.
mixed | $num | The value to format |
Definition at line 1283 of file FormatMetadata.php.
References array(), 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. |
Definition at line 1247 of file FormatMetadata.php.
References $out, array(), as, and ContextSource\getLanguage().
Referenced by formatCoords(), formatFraction(), and makeFormattedData().
|
private |
Calculate the greatest common divisor of two integers.
int | $a | Numerator |
int | $b | Denominator |
Definition at line 1306 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 1650 of file FormatMetadata.php.
References $file, $name, $title, $value, array(), as, TS_ISO_8601, wfProfileIn(), wfProfileOut(), 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 1714 of file FormatMetadata.php.
References $file, $value, array(), as, ContextSource\getContext(), wfProfileIn(), wfProfileOut(), and wfRunHooks().
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 ) |
bool | IContextSource | $context | Context to use (optional) |
Definition at line 79 of file FormatMetadata.php.
References ContextSource\$context, and ContextSource\setContext().
Referenced by MediaHandler\formatMetadataHelper(), and FormatExif\getFormattedData().
|
protected |
Returns a list of languages (first is best) to use when formatting multilang fields, based on user and site preferences.
Definition at line 1861 of file FormatMetadata.php.
References array(), Language\getFallbacksIncludingSiteLanguage(), and ContextSource\getLanguage().
Referenced by flattenArrayReal(), and resolveMultilangValue().
|
static |
Get a list of fields that are visible by default.
Definition at line 1574 of file FormatMetadata.php.
References $line, $lines, $matches, array(), as, text, and wfMessage().
Referenced by MediaHandler\visibleMetadataFields().
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 1166 of file FormatMetadata.php.
References $value, Language\fetchLanguageName(), list, and ContextSource\msg().
Referenced by flattenArrayReal().
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 99 of file FormatMetadata.php.
References $e, $n, $s, $time, $type, array(), as, collapseContactInfo(), convertNewsCode(), exifMsg(), Language\fetchLanguageName(), flattenArrayReal(), formatCoords(), formatFraction(), formatNum(), ContextSource\getLanguage(), list, ContextSource\msg(), TS_MW, and wfTimestamp().
|
protected |
Takes an array returned by the getExtendedMetadata* functions, and resolves multi-language values in it.
array | $metadata |
Definition at line 1785 of file FormatMetadata.php.
References as, and 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 1747 of file FormatMetadata.php.
References $value, as, and getPriorityLanguages().
Referenced by resolveMultilangMetadata().
|
protected |
Makes sure the given array is a valid API response fragment (can be transformed into XML)
array | $arr |
Definition at line 1801 of file FormatMetadata.php.
References $value, as, and sanitizeKeyForXml().
Referenced by fetchExtendedMetadata().
|
protected |
Turns a string into a valid XML identifier.
Used to ensure that keys of an associative array in the API response do not break the XML formatter.
string | $key |
Definition at line 1835 of file FormatMetadata.php.
Referenced by sanitizeArrayForXml().
FormatMetadata::setSingleLanguage | ( | $val | ) |
Trigger only outputting single language for multilanguage fields.
bool | $val |
Definition at line 62 of file FormatMetadata.php.
Referenced by ApiQueryImageInfo\getInfo().
|
protected |
Only output a single language for multi-language fields.
Definition at line 54 of file FormatMetadata.php.