3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
20 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason, 2009 Brent Garber, 2010 Brian Wolff
21 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
22 * @see http://exif.org/Exif2-2.PDF The Exif 2.2 specification
28 * Format Image metadata values into a human readable form.
30 * Note lots of these messages use the prefix 'exif' even though
31 * they may not be exif properties. For example 'exif-ImageDescription'
32 * can be the Exif ImageDescription, or it could be the iptc-iim caption
33 * property, or it could be the xmp dc:description property. This
34 * is because these messages should be independent of how the data is
35 * stored, sine the user doesn't care if the description is stored in xmp,
36 * exif, etc only that its a description. (Additionally many of these properties
37 * are merged together following the MWG standard, such that for example,
38 * exif properties override XMP properties that mean the same thing if
39 * there is a conflict).
41 * It should perhaps use a prefix like 'metadata' instead, but there
42 * is already a large number of messages using the 'exif' prefix.
46 class FormatMetadata
{
49 * Numbers given by Exif user agents are often magical, that is they
50 * should be replaced by a detailed explanation depending on their
51 * value which most of the time are plain integers. This function
52 * formats Exif (and other metadata) values into human readable form.
54 * @param $tags Array: the Exif data to format ( as returned by
55 * Exif::getFilteredData() or BitmapMetadataHandler )
58 public static function getFormattedData( $tags ) {
61 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
62 unset( $tags['ResolutionUnit'] );
64 foreach ( $tags as $tag => &$vals ) {
66 // This seems ugly to wrap non-array's in an array just to unwrap again,
67 // especially when most of the time it is not an array
68 if ( !is_array( $tags[$tag] ) ) {
69 $vals = Array( $vals );
72 // _type is a special value to say what array type
73 if ( isset( $tags[$tag]['_type'] ) ) {
74 $type = $tags[$tag]['_type'];
75 unset( $vals['_type'] );
77 $type = 'ul'; // default unordered list.
80 //This is done differently as the tag is an array.
81 if ($tag == 'GPSTimeStamp' && count($vals) === 3) {
84 $h = explode('/', $vals[0]);
85 $m = explode('/', $vals[1]);
86 $s = explode('/', $vals[2]);
88 // this should already be validated
89 // when loaded from file, but it could
90 // come from a foreign repo, so be
101 $tags[$tag] = intval( $h[0] / $h[1] )
102 . ':' . str_pad( intval( $m[0] / $m[1] ), 2, '0', STR_PAD_LEFT
)
103 . ':' . str_pad( intval( $s[0] / $s[1] ), 2, '0', STR_PAD_LEFT
);
105 $time = wfTimestamp( TS_MW
, '1971:01:01 ' . $tags[$tag] );
106 // the 1971:01:01 is just a placeholder, and not shown to user.
108 $tags[$tag] = $wgLang->time( $time );
113 // The contact info is a multi-valued field
114 // instead of the other props which are single
115 // valued (mostly) so handle as a special case.
116 if ( $tag === 'Contact' ) {
117 $vals = self
::collapseContactInfo( $vals );
121 foreach ( $vals as &$val ) {
126 case 1: case 2: case 3: case 4:
127 case 5: case 6: case 7: case 8:
128 case 32773: case 32946: case 34712:
129 $val = self
::msg( $tag, $val );
132 /* If not recognized, display as is. */
137 case 'PhotometricInterpretation':
140 $val = self
::msg( $tag, $val );
143 /* If not recognized, display as is. */
150 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
151 $val = self
::msg( $tag, $val );
154 /* If not recognized, display as is. */
159 case 'PlanarConfiguration':
162 $val = self
::msg( $tag, $val );
165 /* If not recognized, display as is. */
170 // TODO: YCbCrSubSampling
171 case 'YCbCrPositioning':
175 $val = self
::msg( $tag, $val );
178 /* If not recognized, display as is. */
185 switch( $resolutionunit ) {
187 $val = self
::msg( 'XYResolution', 'i', self
::formatNum( $val ) );
190 $val = self
::msg( 'XYResolution', 'c', self
::formatNum( $val ) );
193 /* If not recognized, display as is. */
198 // TODO: YCbCrCoefficients #p27 (see annex E)
199 case 'ExifVersion': case 'FlashpixVersion':
206 $val = self
::msg( $tag, $val );
209 /* If not recognized, display as is. */
214 case 'ComponentsConfiguration':
216 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
217 $val = self
::msg( $tag, $val );
220 /* If not recognized, display as is. */
226 case 'DateTimeOriginal':
227 case 'DateTimeDigitized':
228 case 'DateTimeReleased':
229 case 'DateTimeExpires':
232 case 'DateTimeMetadata':
233 if ( $val == '0000:00:00 00:00:00' ||
$val == ' : : : : ' ) {
234 $val = wfMsg( 'exif-unknowndate' );
235 } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/D', $val ) ) {
236 $time = wfTimestamp( TS_MW
, $val );
238 $val = $wgLang->timeanddate( $time );
240 } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d)$/D', $val ) ) {
241 // If only the date but not the time is filled in.
242 $time = wfTimestamp( TS_MW
, substr( $val, 0, 4 )
243 . substr( $val, 5, 2 )
244 . substr( $val, 8, 2 )
247 $val = $wgLang->date( $time );
250 // else it will just output $val without formatting it.
253 case 'ExposureProgram':
255 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
256 $val = self
::msg( $tag, $val );
259 /* If not recognized, display as is. */
264 case 'SubjectDistance':
265 $val = self
::msg( $tag, '', self
::formatNum( $val ) );
270 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
271 $val = self
::msg( $tag, $val );
274 /* If not recognized, display as is. */
281 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
282 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
283 case 21: case 22: case 23: case 24: case 255:
284 $val = self
::msg( $tag, $val );
287 /* If not recognized, display as is. */
293 $flashDecode = array(
294 'fired' => $val & bindec( '00000001' ),
295 'return' => ( $val & bindec( '00000110' ) ) >> 1,
296 'mode' => ( $val & bindec( '00011000' ) ) >> 3,
297 'function' => ( $val & bindec( '00100000' ) ) >> 5,
298 'redeye' => ( $val & bindec( '01000000' ) ) >> 6,
299 // 'reserved' => ($val & bindec( '10000000' )) >> 7,
302 # We do not need to handle unknown values since all are used.
303 foreach ( $flashDecode as $subTag => $subValue ) {
304 # We do not need any message for zeroed values.
305 if ( $subTag != 'fired' && $subValue == 0 ) {
308 $fullTag = $tag . '-' . $subTag ;
309 $flashMsgs[] = self
::msg( $fullTag, $subValue );
311 $val = $wgLang->commaList( $flashMsgs );
314 case 'FocalPlaneResolutionUnit':
317 $val = self
::msg( $tag, $val );
320 /* If not recognized, display as is. */
325 case 'SensingMethod':
327 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
328 $val = self
::msg( $tag, $val );
331 /* If not recognized, display as is. */
339 $val = self
::msg( $tag, $val );
342 /* If not recognized, display as is. */
350 $val = self
::msg( $tag, $val );
353 /* If not recognized, display as is. */
358 case 'CustomRendered':
361 $val = self
::msg( $tag, $val );
364 /* If not recognized, display as is. */
371 case 0: case 1: case 2:
372 $val = self
::msg( $tag, $val );
375 /* If not recognized, display as is. */
383 $val = self
::msg( $tag, $val );
386 /* If not recognized, display as is. */
391 case 'SceneCaptureType':
393 case 0: case 1: case 2: case 3:
394 $val = self
::msg( $tag, $val );
397 /* If not recognized, display as is. */
404 case 0: case 1: case 2: case 3: case 4:
405 $val = self
::msg( $tag, $val );
408 /* If not recognized, display as is. */
415 case 0: case 1: case 2:
416 $val = self
::msg( $tag, $val );
419 /* If not recognized, display as is. */
426 case 0: case 1: case 2:
427 $val = self
::msg( $tag, $val );
430 /* If not recognized, display as is. */
437 case 0: case 1: case 2:
438 $val = self
::msg( $tag, $val );
441 /* If not recognized, display as is. */
446 case 'SubjectDistanceRange':
448 case 0: case 1: case 2: case 3:
449 $val = self
::msg( $tag, $val );
452 /* If not recognized, display as is. */
457 //The GPS...Ref values are kept for compatibility, probably won't be reached.
458 case 'GPSLatitudeRef':
459 case 'GPSDestLatitudeRef':
462 $val = self
::msg( 'GPSLatitude', $val );
465 /* If not recognized, display as is. */
470 case 'GPSLongitudeRef':
471 case 'GPSDestLongitudeRef':
474 $val = self
::msg( 'GPSLongitude', $val );
477 /* If not recognized, display as is. */
484 $val = self
::msg( 'GPSAltitude', 'below-sealevel', self
::formatNum( -$val, 3 ) );
486 $val = self
::msg( 'GPSAltitude', 'above-sealevel', self
::formatNum( $val, 3 ) );
493 $val = self
::msg( $tag, $val );
496 /* If not recognized, display as is. */
501 case 'GPSMeasureMode':
504 $val = self
::msg( $tag, $val );
507 /* If not recognized, display as is. */
514 case 'GPSImgDirectionRef':
515 case 'GPSDestBearingRef':
518 $val = self
::msg( 'GPSDirection', $val );
521 /* If not recognized, display as is. */
527 case 'GPSDestLatitude':
528 $val = self
::formatCoords( $val, 'latitude' );
531 case 'GPSDestLongitude':
532 $val = self
::formatCoords( $val, 'longitude' );
537 case 'K': case 'M': case 'N':
538 $val = self
::msg( 'GPSSpeed', $val );
541 /* If not recognized, display as is. */
546 case 'GPSDestDistanceRef':
548 case 'K': case 'M': case 'N':
549 $val = self
::msg( 'GPSDestDistance', $val );
552 /* If not recognized, display as is. */
558 // See http://en.wikipedia.org/wiki/Dilution_of_precision_(GPS)
560 $val = self
::msg( $tag, 'excellent', self
::formatNum( $val ) );
561 } elseif ( $val <= 5 ) {
562 $val = self
::msg( $tag, 'good', self
::formatNum( $val ) );
563 } elseif ( $val <= 10 ) {
564 $val = self
::msg( $tag, 'moderate', self
::formatNum( $val ) );
565 } elseif ( $val <= 20 ) {
566 $val = self
::msg( $tag, 'fair', self
::formatNum( $val ) );
568 $val = self
::msg( $tag, 'poor', self
::formatNum( $val ) );
572 // This is not in the Exif standard, just a special
573 // case for our purposes which enables wikis to wikify
574 // the make, model and software name to link to their articles.
577 $val = self
::msg( $tag, '', $val );
581 if ( is_array( $val ) ) {
582 //if its a software, version array.
583 $val = wfMsg( 'exif-software-version-value', $val[0], $val[1] );
585 $val = self
::msg( $tag, '', $val );
590 // Show the pretty fraction as well as decimal version
591 $val = wfMsg( 'exif-exposuretime-format',
592 self
::formatFraction( $val ), self
::formatNum( $val ) );
594 case 'ISOSpeedRatings':
595 // If its = 65535 that means its at the
596 // limit of the size of Exif::short and
598 if ( $val == '65535' ) {
599 $val = self
::msg( $tag, 'overflow' );
601 $val = self
::formatNum( $val );
605 $val = wfMsg( 'exif-fnumber-format',
606 self
::formatNum( $val ) );
609 case 'FocalLength': case 'FocalLengthIn35mmFilm':
610 $val = wfMsg( 'exif-focallength-format',
611 self
::formatNum( $val ) );
614 case 'MaxApertureValue':
615 if ( strpos( $val, '/' ) !== false ) {
616 // need to expand this earlier to calculate fNumber
617 list($n, $d) = explode('/', $val);
618 if ( is_numeric( $n ) && is_numeric( $d ) ) {
622 if ( is_numeric( $val ) ) {
623 $fNumber = pow( 2, $val / 2 );
624 if ( $fNumber !== false ) {
625 $val = wfMsg( 'exif-maxaperturevalue-value',
626 self
::formatNum( $val ),
627 self
::formatNum( $fNumber, 2 )
634 switch( strtolower( $val ) ) {
635 // See pg 29 of IPTC photo
636 // metadata standard.
637 case 'ace': case 'clj':
638 case 'dis': case 'fin':
639 case 'edu': case 'evn':
640 case 'hth': case 'hum':
641 case 'lab': case 'lif':
642 case 'pol': case 'rel':
643 case 'sci': case 'soi':
644 case 'spo': case 'war':
652 case 'SubjectNewsCode':
653 // Essentially like iimCategory.
654 // 8 (numeric) digit hierarchical
655 // classification. We decode the
656 // first 2 digits, which provide
658 $val = self
::convertNewsCode( $val );
661 // 1-8 with 1 being highest, 5 normal
662 // 0 is reserved, and 9 is 'user-defined'.
664 if ( $val == 0 ||
$val == 9 ) {
666 } elseif ( $val < 5 && $val > 1 ) {
668 } elseif ( $val == 5 ) {
670 } elseif ( $val <= 8 && $val > 5) {
674 if ( $urgency !== '' ) {
675 $val = self
::msg( 'urgency',
681 // Things that have a unit of pixels.
682 case 'OriginalImageHeight':
683 case 'OriginalImageWidth':
684 case 'PixelXDimension':
685 case 'PixelYDimension':
688 $val = self
::formatNum( $val ) . ' ' . wfMsg( 'unit-pixel' );
691 // Do not transform fields with pure text.
692 // For some languages the formatNum()
693 // conversion results to wrong output like
694 // foo,bar@example,com or foo٫bar@example٫com.
695 // Also some 'numeric' things like Scene codes
696 // are included here as we really don't want
698 case 'ImageDescription':
701 case 'RelatedSoundFile':
702 case 'ImageUniqueID':
703 case 'SpectralSensitivity':
704 case 'GPSSatellites':
708 case 'WorldRegionDest':
710 case 'CountryCodeDest':
711 case 'ProvinceOrStateDest':
713 case 'SublocationDest':
714 case 'WorldRegionCreated':
715 case 'CountryCreated':
716 case 'CountryCodeCreated':
717 case 'ProvinceOrStateCreated':
719 case 'SublocationCreated':
721 case 'SpecialInstructions':
726 case 'FixtureIdentifier':
728 case 'LocationDestCode':
730 case 'JPEGFileComment':
731 case 'iimSupplementalCategory':
732 case 'OriginalTransmissionRef':
734 case 'dc-contributor':
743 case 'CameraOwnerName':
746 case 'RightsCertificate':
747 case 'CopyrightOwner':
750 case 'OriginalDocumentID':
752 case 'MorePermissionsUrl':
753 case 'AttributionUrl':
754 case 'PreferredAttributionName':
755 case 'PNGFileComment':
757 case 'ContentWarning':
758 case 'GIFFileComment':
760 case 'IntellectualGenre':
762 case 'OrginisationInImage':
763 case 'PersonInImage':
765 $val = htmlspecialchars( $val );
770 case 'a': case 'p': case 'b':
771 $val = self
::msg( $tag, $val );
774 $val = htmlspecialchars( $val );
780 case 'True': case 'False':
781 $val = self
::msg( $tag, $val );
786 if ( $val == '-1' ) {
787 $val = self
::msg( $tag, 'rejected' );
789 $val = self
::formatNum( $val );
794 $lang = $wgLang->getLanguageName( strtolower( $val ) );
796 $val = htmlspecialchars( $lang );
798 $val = htmlspecialchars( $val );
803 $val = self
::formatNum( $val );
807 // End formatting values, start flattening arrays.
808 $vals = self
::flattenArray( $vals, $type );
815 * A function to collapse multivalued tags into a single value.
816 * This turns an array of (for example) authors into a bulleted list.
818 * This is public on the basis it might be useful outside of this class.
820 * @param $vals Array array of values
821 * @param $type String Type of array (either lang, ul, ol).
822 * lang = language assoc array with keys being the lang code
823 * ul = unordered list, ol = ordered list
824 * type can also come from the '_type' member of $vals.
825 * @param $noHtml Boolean If to avoid returning anything resembling
826 * html. (Ugly hack for backwards compatibility with old mediawiki).
827 * @return String single value (in wiki-syntax).
829 public static function flattenArray( $vals, $type = 'ul', $noHtml = false ) {
830 if ( isset( $vals['_type'] ) ) {
831 $type = $vals['_type'];
832 unset( $vals['_type'] );
835 if ( !is_array( $vals ) ) {
836 return $vals; // do nothing if not an array;
838 elseif ( count( $vals ) === 1 && $type !== 'lang' ) {
841 elseif ( count( $vals ) === 0 ) {
842 wfDebug( __METHOD__
. ' metadata array with 0 elements!' );
843 return ""; // paranoia. This should never happen
845 /* Fixme: This should hide some of the list entries if there are
846 * say more than four. Especially if a field is translated into 20
847 * languages, we don't want to show them all by default
853 // Display default, followed by ContLang,
854 // followed by the rest in no particular
857 // Todo: hide some items if really long list.
861 $cLang = $wgContLang->getCode();
862 $defaultItem = false;
863 $defaultLang = false;
865 // If default is set, save it for later,
866 // as we don't know if it's equal to
867 // one of the lang codes. (In xmp
868 // you specify the language for a
869 // default property by having both
870 // a default prop, and one in the language
871 // that are identical)
872 if ( isset( $vals['x-default'] ) ) {
873 $defaultItem = $vals['x-default'];
874 unset( $vals['x-default'] );
876 // Do contentLanguage.
877 if ( isset( $vals[$cLang] ) ) {
879 if ( $vals[$cLang] === $defaultItem ) {
880 $defaultItem = false;
883 $content .= self
::langItem(
884 $vals[$cLang], $cLang,
885 $isDefault, $noHtml );
887 unset( $vals[$cLang] );
891 foreach ( $vals as $lang => $item ) {
892 if ( $item === $defaultItem ) {
893 $defaultLang = $lang;
896 $content .= self
::langItem( $item,
897 $lang, false, $noHtml );
899 if ( $defaultItem !== false ) {
900 $content = self
::langItem( $defaultItem,
901 $defaultLang, true, $noHtml )
907 return '<ul class="metadata-langlist">' .
912 return "\n#" . implode( "\n#", $vals );
914 return "<ol><li>" . implode( "</li>\n<li>", $vals ) . '</li></ol>';
918 return "\n*" . implode( "\n*", $vals );
920 return "<ul><li>" . implode( "</li>\n<li>", $vals ) . '</li></ul>';
925 /** Helper function for creating lists of translations.
927 * @param $value String value (this is not escaped)
928 * @param $lang String lang code of item or false
929 * @param $default Boolean if it is default value.
930 * @param $noHtml Boolean If to avoid html (for back-compat)
931 * @return language item (Note: despite how this looks,
932 * this is treated as wikitext not html).
934 private static function langItem( $value, $lang, $default = false, $noHtml = false ) {
936 if ( $lang === false && $default === false) {
937 throw new MWException('$lang and $default cannot both '
942 $wrappedValue = $value;
944 $wrappedValue = '<span class="mw-metadata-lang-value">'
945 . $value . '</span>';
948 if ( $lang === false ) {
950 return wfMsg( 'metadata-langitem-default',
951 $wrappedValue ) . "\n\n";
953 return '<li class="mw-metadata-lang-default">'
954 . wfMsg( 'metadata-langitem-default',
959 $lowLang = strtolower( $lang );
960 $langName = $wgContLang->getLanguageName( $lowLang );
961 if ( $langName === '' ) {
962 //try just the base language name. (aka en-US -> en ).
963 list( $langPrefix ) = explode( '-', $lowLang, 2 );
964 $langName = $wgContLang->getLanguageName( $langPrefix );
965 if ( $langName === '' ) {
970 // else we have a language specified
973 return '*' . wfMsg( 'metadata-langitem',
974 $wrappedValue, $langName, $lang );
977 $item = '<li class="mw-metadata-lang-code-'
980 $item .= ' mw-metadata-lang-default';
982 $item .= '" lang="' . $lang . '">';
983 $item .= wfMsg( 'metadata-langitem',
984 $wrappedValue, $langName, $lang );
990 * Convenience function for getFormattedData()
994 * @param $tag String: the tag name to pass on
995 * @param $val String: the value of the tag
996 * @param $arg String: an argument to pass ($1)
997 * @param $arg2 String: a 2nd argument to pass ($2)
998 * @return string A wfMsg of "exif-$tag-$val" in lower case
1000 static function msg( $tag, $val, $arg = null, $arg2 = null ) {
1005 return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg, $arg2 );
1009 * Format a number, convert numbers from fractions into floating point
1010 * numbers, joins arrays of numbers with commas.
1014 * @param $num Mixed: the value to format
1015 * @param $round digits to round to or false.
1016 * @return mixed A floating point number or whatever we were fed
1018 static function formatNum( $num, $round = false ) {
1021 if( is_array($num) ) {
1023 foreach( $num as $number ) {
1024 $out[] = self
::formatNum($number);
1026 return $wgLang->commaList( $out );
1028 if ( preg_match( '/^(-?\d+)\/(\d+)$/', $num, $m ) ) {
1030 $newNum = $m[1] / $m[2];
1031 if ( $round !== false ) {
1032 $newNum = round( $newNum, $round );
1038 return $wgLang->formatNum( $newNum );
1040 if ( is_numeric( $num ) && $round !== false ) {
1041 $num = round( $num, $round );
1043 return $wgLang->formatNum( $num );
1048 * Format a rational number, reducing fractions
1052 * @param $num Mixed: the value to format
1053 * @return mixed A floating point number or whatever we were fed
1055 static function formatFraction( $num ) {
1057 if ( preg_match( '/^(-?\d+)\/(\d+)$/', $num, $m ) ) {
1058 $numerator = intval( $m[1] );
1059 $denominator = intval( $m[2] );
1060 $gcd = self
::gcd( abs( $numerator ), $denominator );
1062 // 0 shouldn't happen! ;)
1063 return self
::formatNum( $numerator / $gcd ) . '/' . self
::formatNum( $denominator / $gcd );
1066 return self
::formatNum( $num );
1070 * Calculate the greatest common divisor of two integers.
1072 * @param $a Integer: Numerator
1073 * @param $b Integer: Denominator
1077 static function gcd( $a, $b ) {
1079 // http://en.wikipedia.org/wiki/Euclidean_algorithm
1080 // Recursive form would be:
1084 return gcd( $b, $a % $b );
1087 $remainder = $a %
$b;
1089 // tail recursion...
1096 /** Fetch the human readable version of a news code.
1097 * A news code is an 8 digit code. The first two
1098 * digits are a general classification, so we just
1101 * Note, leading 0's are significant, so this is
1102 * a string, not an int.
1104 * @param $val String: The 8 digit news code.
1105 * @return The human readable form
1107 static private function convertNewsCode( $val ) {
1108 if ( !preg_match( '/^\d{8}$/D', $val ) ) {
1109 // Not a valid news code.
1113 switch( substr( $val , 0, 2 ) ) {
1166 if ( $cat !== '' ) {
1167 $catMsg = self
::msg( 'iimcategory', $cat );
1168 $val = self
::msg( 'subjectnewscode', '', $val, $catMsg );
1174 * Format a coordinate value, convert numbers from floating point
1175 * into degree minute second representation.
1177 * @param $coords Array: degrees, minutes and seconds
1178 * @param $type String: latitude or longitude (for if its a NWS or E)
1179 * @return mixed A floating point number or whatever we were fed
1181 static function formatCoords( $coord, $type ) {
1185 if ( $type === 'latitude' ) {
1188 elseif ( $type === 'longitude' ) {
1194 if ( $type === 'latitude' ) {
1197 elseif ( $type === 'longitude' ) {
1202 $deg = floor( $nCoord );
1203 $min = floor( ( $nCoord - $deg ) * 60.0 );
1204 $sec = round( ( ( $nCoord - $deg ) - $min / 60 ) * 3600, 2 );
1206 $deg = self
::formatNum( $deg );
1207 $min = self
::formatNum( $min );
1208 $sec = self
::formatNum( $sec );
1210 return wfMsg( 'exif-coordinate-format', $deg, $min, $sec, $ref, $coord );
1214 * Format the contact info field into a single value.
1216 * @param $vals Array array with fields of the ContactInfo
1217 * struct defined in the IPTC4XMP spec. Or potentially
1218 * an array with one element that is a free form text
1219 * value from the older iptc iim 1:118 prop.
1221 * This function might be called from
1222 * JpegHandler::convertMetadataVersion which is why it is
1225 * @return String of html-ish looking wikitext
1227 public static function collapseContactInfo( $vals ) {
1228 if( ! ( isset( $vals['CiAdrExtadr'] )
1229 ||
isset( $vals['CiAdrCity'] )
1230 ||
isset( $vals['CiAdrCtry'] )
1231 ||
isset( $vals['CiEmailWork'] )
1232 ||
isset( $vals['CiTelWork'] )
1233 ||
isset( $vals['CiAdrPcode'] )
1234 ||
isset( $vals['CiAdrRegion'] )
1235 ||
isset( $vals['CiUrlWork'] )
1237 // We don't have any sub-properties
1238 // This could happen if its using old
1239 // iptc that just had this as a free-form
1241 // Note: We run this through htmlspecialchars
1242 // partially to be consistent, and partially
1243 // because people often insert >, etc into
1244 // the metadata which should not be interpreted
1245 // but we still want to auto-link urls.
1246 foreach( $vals as &$val ) {
1247 $val = htmlspecialchars( $val );
1249 return self
::flattenArray( $vals );
1251 // We have a real ContactInfo field.
1252 // Its unclear if all these fields have to be
1253 // set, so assume they do not.
1254 $url = $tel = $street = $city = $country = '';
1255 $email = $postal = $region = '';
1257 // Also note, some of the class names this uses
1258 // are similar to those used by hCard. This is
1259 // mostly because they're sensible names. This
1260 // does not (and does not attempt to) output
1261 // stuff in the hCard microformat. However it
1262 // might output in the adr microformat.
1264 if ( isset( $vals['CiAdrExtadr'] ) ) {
1265 // Todo: This can potentially be multi-line.
1266 // Need to check how that works in XMP.
1267 $street = '<span class="extended-address">'
1269 $vals['CiAdrExtadr'] )
1272 if ( isset( $vals['CiAdrCity'] ) ) {
1273 $city = '<span class="locality">'
1274 . htmlspecialchars( $vals['CiAdrCity'] )
1277 if ( isset( $vals['CiAdrCtry'] ) ) {
1278 $country = '<span class="country-name">'
1279 . htmlspecialchars( $vals['CiAdrCtry'] )
1282 if ( isset( $vals['CiEmailWork'] ) ) {
1284 // Have to split multiple emails at commas/new lines.
1285 $splitEmails = explode( "\n", $vals['CiEmailWork'] );
1286 foreach ( $splitEmails as $e1 ) {
1287 // Also split on comma
1288 foreach ( explode( ',', $e1 ) as $e2 ) {
1289 $finalEmail = trim( $e2 );
1290 if ( $finalEmail == ',' ||
$finalEmail == '' ) {
1293 if ( strpos( $finalEmail, '<' ) !== false ) {
1294 // Don't do fancy formatting to
1295 // "My name" <foo@bar.com> style stuff
1296 $emails[] = $finalEmail;
1298 $emails[] = '[mailto:'
1300 . ' <span class="email">'
1306 $email = implode( ', ', $emails );
1308 if ( isset( $vals['CiTelWork'] ) ) {
1309 $tel = '<span class="tel">'
1310 . htmlspecialchars( $vals['CiTelWork'] )
1313 if ( isset( $vals['CiAdrPcode'] ) ) {
1314 $postal = '<span class="postal-code">'
1316 $vals['CiAdrPcode'] )
1319 if ( isset( $vals['CiAdrRegion'] ) ) {
1320 // Note this is province/state.
1321 $region = '<span class="region">'
1323 $vals['CiAdrRegion'] )
1326 if ( isset( $vals['CiUrlWork'] ) ) {
1327 $url = '<span class="url">'
1328 . htmlspecialchars( $vals['CiUrlWork'] )
1331 return wfMsg( 'exif-contact-value', $email, $url,
1332 $street, $city, $region, $postal, $country,
1338 /** For compatability with old FormatExif class
1339 * which some extensions use.
1341 * @deprecated since 1.18
1346 function FormatExif ( $meta ) {
1347 wfDeprecated(__METHOD__
);
1348 $this->meta
= $meta;
1351 function getFormattedData ( ) {
1352 return FormatMetadata
::getFormattedData( $this->meta
);