2 if ( !defined( 'MEDIAWIKI' ) ) die();
7 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
8 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * http://www.gnu.org/copyleft/gpl.html
26 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
31 * Exif tag type definition
33 define('MW_EXIF_BYTE', 1); # An 8-bit unsigned integer.
34 define('MW_EXIF_ASCII', 2); # An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.
35 define('MW_EXIF_SHORT', 3); # A 16-bit (2-byte) unsigned integer.
36 define('MW_EXIF_LONG', 4); # A 32-bit (4-byte) unsigned integer.
37 define('MW_EXIF_RATIONAL', 5); # Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator
38 define('MW_EXIF_UNDEFINED', 7); # An 8-bit byte that can take any value depending on the field definition
39 define('MW_EXIF_SLONG', 9); # A 32-bit (4-byte) signed integer (2's complement notation),
40 define('MW_EXIF_SRATIONAL', 10); # Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.
46 * @subpackage Metadata
55 * Exif tags grouped by category, the tagname itself is the key and the type
56 * is the value, in the case of more than one possible value type they are
57 * seperated by commas.
62 * A one dimentional array of all Exif tags
67 * The raw Exif data returned by exif_read_data()
72 * A Filtered version of $mRawExifData that has been pruned of invalid
73 * tags and tags that contain content they shouldn't contain according
74 * to the Exif specification
76 var $mFilteredExifData;
79 * Filtered and formatted Exif data, see FormatExif::getFormattedData()
81 var $mFormattedExifData;
90 function Exif( $file ) {
92 * Page numbers here refer to pages in the EXIF 2.2 standard
94 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
96 $this->mExifTags
= array(
97 # TIFF Rev. 6.0 Attribute Information (p22)
99 # Tags relating to image structure
100 'structure' => array(
101 'ImageWidth' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image width
102 'ImageLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image height
103 'BitsPerSample' => MW_EXIF_SHORT
, # Number of bits per component
104 # "When a primary image is JPEG compressed, this designation is not"
105 # "necessary and is omitted." (p23)
106 'Compression' => MW_EXIF_SHORT
, # Compression scheme #p23
107 'PhotometricInterpretation' => MW_EXIF_SHORT
, # Pixel composition #p23
108 'Orientation' => MW_EXIF_SHORT
, # Orientation of image #p24
109 'SamplesPerPixel' => MW_EXIF_SHORT
, # Number of components
110 'PlanarConfiguration' => MW_EXIF_SHORT
, # Image data arrangement #p24
111 'YCbCrSubSampling' => MW_EXIF_SHORT
, # Subsampling ratio of Y to C #p24
112 'YCbCrPositioning' => MW_EXIF_SHORT
, # Y and C positioning #p24-25
113 'XResolution' => MW_EXIF_RATIONAL
, # Image resolution in width direction
114 'YResolution' => MW_EXIF_RATIONAL
, # Image resolution in height direction
115 'ResolutionUnit' => MW_EXIF_SHORT
, # Unit of X and Y resolution #(p26)
118 # Tags relating to recording offset
120 'StripOffsets' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image data location
121 'RowsPerStrip' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Number of rows per strip
122 'StripByteCounts' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes per compressed strip
123 'JPEGInterchangeFormat' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Offset to JPEG SOI
124 'JPEGInterchangeFormatLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes of JPEG data
127 # Tags relating to image data characteristics
128 'characteristics' => array(
129 'TransferFunction' => MW_EXIF_SHORT
, # Transfer function
130 'WhitePoint' => MW_EXIF_RATIONAL
, # White point chromaticity
131 'PrimaryChromaticities' => MW_EXIF_RATIONAL
, # Chromaticities of primarities
132 'YCbCrCoefficients' => MW_EXIF_RATIONAL
, # Color space transformation matrix coefficients #p27
133 'ReferenceBlackWhite' => MW_EXIF_RATIONAL
# Pair of black and white reference values
138 'DateTime' => MW_EXIF_ASCII
, # File change date and time
139 'ImageDescription' => MW_EXIF_ASCII
, # Image title
140 'Make' => MW_EXIF_ASCII
, # Image input equipment manufacturer
141 'Model' => MW_EXIF_ASCII
, # Image input equipment model
142 'Software' => MW_EXIF_ASCII
, # Software used
143 'Artist' => MW_EXIF_ASCII
, # Person who created the image
144 'Copyright' => MW_EXIF_ASCII
, # Copyright holder
148 # Exif IFD Attribute Information (p30-31)
150 # Tags relating to version
152 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
153 # to the EXIF 2.1 AND 2.2 standards
154 'ExifVersion' => MW_EXIF_UNDEFINED
, # Exif version
155 'FlashpixVersion' => MW_EXIF_UNDEFINED
, # Supported Flashpix version #p32
158 # Tags relating to Image Data Characteristics
159 'characteristics' => array(
160 'ColorSpace' => MW_EXIF_SHORT
, # Color space information #p32
163 # Tags relating to image configuration
164 'configuration' => array(
165 'ComponentsConfiguration' => MW_EXIF_UNDEFINED
, # Meaning of each component #p33
166 'CompressedBitsPerPixel' => MW_EXIF_RATIONAL
, # Image compression mode
167 'PixelYDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valid image width
168 'PixelXDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valind image height
171 # Tags relating to related user information
173 'MakerNote' => MW_EXIF_UNDEFINED
, # Manufacturer notes
174 'UserComment' => MW_EXIF_UNDEFINED
, # User comments #p34
177 # Tags relating to related file information
179 'RelatedSoundFile' => MW_EXIF_ASCII
, # Related audio file
182 # Tags relating to date and time
183 'dateandtime' => array(
184 'DateTimeOriginal' => MW_EXIF_ASCII
, # Date and time of original data generation #p36
185 'DateTimeDigitized' => MW_EXIF_ASCII
, # Date and time of original data generation
186 'SubSecTime' => MW_EXIF_ASCII
, # DateTime subseconds
187 'SubSecTimeOriginal' => MW_EXIF_ASCII
, # DateTimeOriginal subseconds
188 'SubSecTimeDigitized' => MW_EXIF_ASCII
, # DateTimeDigitized subseconds
191 # Tags relating to picture-taking conditions (p31)
192 'conditions' => array(
193 'ExposureTime' => MW_EXIF_RATIONAL
, # Exposure time
194 'FNumber' => MW_EXIF_RATIONAL
, # F Number
195 'ExposureProgram' => MW_EXIF_SHORT
, # Exposure Program #p38
196 'SpectralSensitivity' => MW_EXIF_ASCII
, # Spectral sensitivity
197 'ISOSpeedRatings' => MW_EXIF_SHORT
, # ISO speed rating
198 'OECF' => MW_EXIF_UNDEFINED
, # Optoelectronic conversion factor
199 'ShutterSpeedValue' => MW_EXIF_SRATIONAL
, # Shutter speed
200 'ApertureValue' => MW_EXIF_RATIONAL
, # Aperture
201 'BrightnessValue' => MW_EXIF_SRATIONAL
, # Brightness
202 'ExposureBiasValue' => MW_EXIF_SRATIONAL
, # Exposure bias
203 'MaxApertureValue' => MW_EXIF_RATIONAL
, # Maximum land aperture
204 'SubjectDistance' => MW_EXIF_RATIONAL
, # Subject distance
205 'MeteringMode' => MW_EXIF_SHORT
, # Metering mode #p40
206 'LightSource' => MW_EXIF_SHORT
, # Light source #p40-41
207 'Flash' => MW_EXIF_SHORT
, # Flash #p41-42
208 'FocalLength' => MW_EXIF_RATIONAL
, # Lens focal length
209 'SubjectArea' => MW_EXIF_SHORT
, # Subject area
210 'FlashEnergy' => MW_EXIF_RATIONAL
, # Flash energy
211 'SpatialFrequencyResponse' => MW_EXIF_UNDEFINED
, # Spatial frequency response
212 'FocalPlaneXResolution' => MW_EXIF_RATIONAL
, # Focal plane X resolution
213 'FocalPlaneYResolution' => MW_EXIF_RATIONAL
, # Focal plane Y resolution
214 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT
, # Focal plane resolution unit #p46
215 'SubjectLocation' => MW_EXIF_SHORT
, # Subject location
216 'ExposureIndex' => MW_EXIF_RATIONAL
, # Exposure index
217 'SensingMethod' => MW_EXIF_SHORT
, # Sensing method #p46
218 'FileSource' => MW_EXIF_UNDEFINED
, # File source #p47
219 'SceneType' => MW_EXIF_UNDEFINED
, # Scene type #p47
220 'CFAPattern' => MW_EXIF_UNDEFINED
, # CFA pattern
221 'CustomRendered' => MW_EXIF_SHORT
, # Custom image processing #p48
222 'ExposureMode' => MW_EXIF_SHORT
, # Exposure mode #p48
223 'WhiteBalance' => MW_EXIF_SHORT
, # White Balance #p49
224 'DigitalZoomRatio' => MW_EXIF_RATIONAL
, # Digital zoom ration
225 'FocalLengthIn35mmFilm' => MW_EXIF_SHORT
, # Focal length in 35 mm film
226 'SceneCaptureType' => MW_EXIF_SHORT
, # Scene capture type #p49
227 'GainControl' => MW_EXIF_RATIONAL
, # Scene control #p49-50
228 'Contrast' => MW_EXIF_SHORT
, # Contrast #p50
229 'Saturation' => MW_EXIF_SHORT
, # Saturation #p50
230 'Sharpness' => MW_EXIF_SHORT
, # Sharpness #p50
231 'DeviceSettingDescription' => MW_EXIF_UNDEFINED
, # Desice settings description
232 'SubjectDistanceRange' => MW_EXIF_SHORT
, # Subject distance range #p51
236 'ImageUniqueID' => MW_EXIF_ASCII
, # Unique image ID
240 # GPS Attribute Information (p52)
242 'GPSVersionID' => MW_EXIF_BYTE
, # GPS tag version
243 'GPSLatitudeRef' => MW_EXIF_ASCII
, # North or South Latitude #p52-53
244 'GPSLatitude' => MW_EXIF_RATIONAL
, # Latitude
245 'GPSLongitudeRef' => MW_EXIF_ASCII
, # East or West Longitude #p53
246 'GPSLongitude' => MW_EXIF_RATIONAL
, # Longitude
247 'GPSAltitudeRef' => MW_EXIF_BYTE
, # Altitude reference
248 'GPSAltitude' => MW_EXIF_RATIONAL
, # Altitude
249 'GPSTimeStamp' => MW_EXIF_RATIONAL
, # GPS time (atomic clock)
250 'GPSSatellites' => MW_EXIF_ASCII
, # Satellites used for measurement
251 'GPSStatus' => MW_EXIF_ASCII
, # Receiver status #p54
252 'GPSMeasureMode' => MW_EXIF_ASCII
, # Measurement mode #p54-55
253 'GPSDOP' => MW_EXIF_RATIONAL
, # Measurement precision
254 'GPSSpeedRef' => MW_EXIF_ASCII
, # Speed unit #p55
255 'GPSSpeed' => MW_EXIF_RATIONAL
, # Speed of GPS receiver
256 'GPSTrackRef' => MW_EXIF_ASCII
, # Reference for direction of movement #p55
257 'GPSTrack' => MW_EXIF_RATIONAL
, # Direction of movement
258 'GPSImgDirectionRef' => MW_EXIF_ASCII
, # Reference for direction of image #p56
259 'GPSImgDirection' => MW_EXIF_RATIONAL
, # Direction of image
260 'GPSMapDatum' => MW_EXIF_ASCII
, # Geodetic survey data used
261 'GPSDestLatitudeRef' => MW_EXIF_ASCII
, # Reference for latitude of destination #p56
262 'GPSDestLatitude' => MW_EXIF_RATIONAL
, # Latitude destination
263 'GPSDestLongitudeRef' => MW_EXIF_ASCII
, # Reference for longitude of destination #p57
264 'GPSDestLongitude' => MW_EXIF_RATIONAL
, # Longitude of destination
265 'GPSDestBearingRef' => MW_EXIF_ASCII
, # Reference for bearing of destination #p57
266 'GPSDestBearing' => MW_EXIF_RATIONAL
, # Bearing of destination
267 'GPSDestDistanceRef' => MW_EXIF_ASCII
, # Reference for distance to destination #p57-58
268 'GPSDestDistance' => MW_EXIF_RATIONAL
, # Distance to destination
269 'GPSProcessingMethod' => MW_EXIF_UNDEFINED
, # Name of GPS processing method
270 'GPSAreaInformation' => MW_EXIF_UNDEFINED
, # Name of GPS area
271 'GPSDateStamp' => MW_EXIF_ASCII
, # GPS date
272 'GPSDifferential' => MW_EXIF_SHORT
, # GPS differential correction
276 $this->makeFlatExifTags();
277 wfSuppressWarnings();
278 $this->mRawExifData
= exif_read_data( $file );
280 $this->makeFilteredData();
281 $this->makeFormattedData();
288 * Generate a flat list of the exif tags
290 function makeFlatExifTags() {
291 $this->extractTags( $this->mExifTags
);
295 * A recursing extractor function used by makeFlatExifTags()
297 * Note: This used to use an array_walk function, but it made PHP5
298 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
300 function extractTags( &$tagset ) {
301 foreach( $tagset as $key => $val ) {
302 if( is_array( $val ) ) {
303 $this->extractTags( $val );
305 $this->mFlatExifTags
[$key] = $val;
311 * Make $this->mFilteredExifData
313 function makeFilteredData() {
314 $this->mFilteredExifData
= $this->mRawExifData
;
316 foreach( $this->mFilteredExifData
as $k => $v ) {
317 if ( !in_array( $k, array_keys( $this->mFlatExifTags
) ) ) {
318 $this->debug( $v, __FUNCTION__
, "'$k' is not a valid Exif tag" );
319 unset( $this->mFilteredExifData
[$k] );
323 foreach( $this->mFilteredExifData
as $k => $v ) {
324 if ( !$this->validate($k, $v) ) {
325 $this->debug( $v, __FUNCTION__
, "'$k' contained invalid data" );
326 unset( $this->mFilteredExifData
[$k] );
331 function makeFormattedData( $data = null ) {
332 $format = new FormatExif( $this->getFilteredData() );
333 $this->mFormattedExifData
= $format->getFormattedData();
341 * Get $this->mRawExifData
344 return $this->mRawExifData
;
348 * Get $this->mFilteredExifData
350 function getFilteredData() {
351 return $this->mFilteredExifData
;
355 * Get $this->mFormattedExifData
357 function getFormattedData() {
358 return $this->mFormattedExifData
;
363 * The version of the output format
365 * Before the actual metadata information is saved in the database we
366 * strip some of it since we don't want to save things like thumbnails
367 * which usually accompany Exif data. This value gets saved in the
368 * database along with the actual Exif data, and if the version in the
369 * database doesn't equal the value returned by this function the Exif
370 * data is regenerated.
375 return 1; // We don't need no bloddy constants!
379 * Validates if a tag value is of the type it should be according to the Exif spec
383 * @param mixed $in The input value to check
386 function isByte( $in ) {
387 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
388 $this->debug( $in, __FUNCTION__
, true );
391 $this->debug( $in, __FUNCTION__
, false );
396 function isASCII( $in ) {
397 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
398 $this->debug( $in, __FUNCTION__
, 'found a character not in our whitelist' );
402 if ( preg_match( "/^\s*$/", $in ) ) {
403 $this->debug( $in, __FUNCTION__
, 'input consisted solely of whitespace' );
410 function isShort( $in ) {
411 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
412 $this->debug( $in, __FUNCTION__
, true );
415 $this->debug( $in, __FUNCTION__
, false );
420 function isLong( $in ) {
421 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
422 $this->debug( $in, __FUNCTION__
, true );
425 $this->debug( $in, __FUNCTION__
, false );
430 function isRational( $in ) {
431 if ( @preg_match
( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
432 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
434 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
439 function isUndefined( $in ) {
440 if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
441 $this->debug( $in, __FUNCTION__
, true );
444 $this->debug( $in, __FUNCTION__
, false );
449 function isSlong( $in ) {
450 if ( $this->isLong( abs( $in ) ) ) {
451 $this->debug( $in, __FUNCTION__
, true );
454 $this->debug( $in, __FUNCTION__
, false );
459 function isSrational( $in ) {
460 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
461 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
463 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
470 * Validates if a tag has a legal value according to the Exif spec
474 * @param string $tag The tag to check
475 * @param mixed $val The value of the tag
478 function validate( $tag, $val ) {
479 $debug = "tag is '$tag'";
480 // Fucks up if not typecast
481 switch( (string)$this->mFlatExifTags
[$tag] ) {
482 case (string)MW_EXIF_BYTE
:
483 $this->debug( $val, __FUNCTION__
, $debug );
484 return $this->isByte( $val );
485 case (string)MW_EXIF_ASCII
:
486 $this->debug( $val, __FUNCTION__
, $debug );
487 return $this->isASCII( $val );
488 case (string)MW_EXIF_SHORT
:
489 $this->debug( $val, __FUNCTION__
, $debug );
490 return $this->isShort( $val );
491 case (string)MW_EXIF_LONG
:
492 $this->debug( $val, __FUNCTION__
, $debug );
493 return $this->isLong( $val );
494 case (string)MW_EXIF_RATIONAL
:
495 $this->debug( $val, __FUNCTION__
, $debug );
496 return $this->isRational( $val );
497 case (string)MW_EXIF_UNDEFINED
:
498 $this->debug( $val, __FUNCTION__
, $debug );
499 return $this->isUndefined( $val );
500 case (string)MW_EXIF_SLONG
:
501 $this->debug( $val, __FUNCTION__
, $debug );
502 return $this->isSlong( $val );
503 case (string)MW_EXIF_SRATIONAL
:
504 $this->debug( $val, __FUNCTION__
, $debug );
505 return $this->isSrational( $val );
506 case (string)MW_EXIF_SHORT
.','.MW_EXIF_LONG
:
507 $this->debug( $val, __FUNCTION__
, $debug );
508 return $this->isShort( $val ) ||
$this->isLong( $val );
510 $this->debug( $val, __FUNCTION__
, "The tag '$tag' is unknown" );
516 * Conviniance function for debugging output
521 * @param string $fname
522 * @param mixed $action
524 function debug( $in, $fname, $action = null ) {
525 $type = gettype( $in );
526 $class = ucfirst( __CLASS__
);
527 if ( $type === 'array' )
528 $in = print_r( $in, true );
530 if ( $action === true )
531 wfDebug( "$class::$fname: accepted: '$in' (type: $type)\n");
532 elseif ( $action === false )
533 wfDebug( "$class::$fname: rejected: '$in' (type: $type)\n");
534 elseif ( $action === null )
535 wfDebug( "$class::$fname: input was: '$in' (type: $type)\n");
537 wfDebug( "$class::$fname: $action (type: $type; content: '$in')\n");
544 * @subpackage Metadata
548 * The Exif data to format
558 * @param array $exif The Exif data to format ( as returned by
559 * Exif::getFilteredData() )
561 function FormatExif( $exif ) {
562 $this->mExif
= $exif;
566 * Numbers given by Exif user agents are often magical, that is they
567 * should be replaced by a detailed explanation depending on their
568 * value which most of the time are plain integers. This function
569 * formats Exif values into human readable form.
573 function getFormattedData() {
576 $tags =& $this->mExif
;
578 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
579 unset( $tags['ResolutionUnit'] );
581 foreach( $tags as $tag => $val ) {
586 $tags[$tag] = $this->msg( $tag, $val );
594 case 'PhotometricInterpretation':
597 $tags[$tag] = $this->msg( $tag, $val );
607 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
608 $tags[$tag] = $this->msg( $tag, $val );
616 case 'PlanarConfiguration':
619 $tags[$tag] = $this->msg( $tag, $val );
627 // TODO: YCbCrSubSampling
628 // TODO: YCbCrPositioning
632 switch( $resolutionunit ) {
634 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
637 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
645 // TODO: YCbCrCoefficients #p27 (see annex E)
646 case 'ExifVersion': case 'FlashpixVersion':
647 $tags[$tag] = "$val"/100;
652 case 1: case 'FFFF.H':
653 $tags[$tag] = $this->msg( $tag, $val );
661 case 'ComponentsConfiguration':
663 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
664 $tags[$tag] = $this->msg( $tag, $val );
673 case 'DateTimeOriginal':
674 case 'DateTimeDigitized':
675 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW
, $val) );
678 case 'ExposureProgram':
680 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
681 $tags[$tag] = $this->msg( $tag, $val );
689 case 'SubjectDistance':
690 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
695 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
696 $tags[$tag] = $this->msg( $tag, $val );
706 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
707 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
708 case 21: case 22: case 23: case 24: case 255:
709 $tags[$tag] = $this->msg( $tag, $val );
718 case 'FocalPlaneResolutionUnit':
721 $tags[$tag] = $this->msg( $tag, $val );
729 case 'SensingMethod':
731 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
732 $tags[$tag] = $this->msg( $tag, $val );
743 $tags[$tag] = $this->msg( $tag, $val );
754 $tags[$tag] = $this->msg( $tag, $val );
762 case 'CustomRendered':
765 $tags[$tag] = $this->msg( $tag, $val );
775 case 0: case 1: case 2:
776 $tags[$tag] = $this->msg( $tag, $val );
787 $tags[$tag] = $this->msg( $tag, $val );
795 case 'SceneCaptureType':
797 case 0: case 1: case 2: case 3:
798 $tags[$tag] = $this->msg( $tag, $val );
808 case 0: case 1: case 2: case 3: case 4:
809 $tags[$tag] = $this->msg( $tag, $val );
819 case 0: case 1: case 2:
820 $tags[$tag] = $this->msg( $tag, $val );
830 case 0: case 1: case 2:
831 $tags[$tag] = $this->msg( $tag, $val );
841 case 0: case 1: case 2:
842 $tags[$tag] = $this->msg( $tag, $val );
850 case 'SubjectDistanceRange':
852 case 0: case 1: case 2: case 3:
853 $tags[$tag] = $this->msg( $tag, $val );
861 case 'GPSLatitudeRef':
862 case 'GPSDestLatitudeRef':
865 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
873 case 'GPSLongitudeRef':
874 case 'GPSDestLongitudeRef':
877 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
888 $tags[$tag] = $this->msg( $tag, $val );
896 case 'GPSMeasureMode':
899 $tags[$tag] = $this->msg( $tag, $val );
908 case 'GPSDestDistanceRef':
910 case 'K': case 'M': case 'N':
911 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
920 case 'GPSImgDirectionRef':
921 case 'GPSDestBearingRef':
924 $tags[$tag] = $this->msg( 'GPSDirection', $val );
933 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
936 // This is not in the Exif standard, just a special
937 // case for our purposes which enables wikis to wikify
938 // the make, model and software name to link to their articles.
942 $tags[$tag] = $this->msg( $tag, '', $val );
945 $tags[$tag] = $this->formatNum( $val );
954 * Conviniance function for getFormattedData()
958 * @param string $tag The tag name to pass on
959 * @param string $val The value of the tag
960 * @param string $arg An argument to pass ($1)
961 * @return string A wfMsg of "exif-$tag-$val" in lower case
963 function msg( $tag, $val, $arg = null ) {
966 return wfMsg( strtolower( "exif-$tag-$val" ), $arg );
970 * Format a number, convert numbers from fractions into floating point
975 * @param mixed $num The value to format
976 * @return mixed A floating point number or whatever we were fed
978 function formatNum( $num ) {
979 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
980 return $m[2] != 0 ?
$m[1] / $m[2] : $num;