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 (1-byte) 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;
86 * The private log to log to
98 function Exif( $file ) {
100 * Page numbers here refer to pages in the EXIF 2.2 standard
102 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
104 $this->mExifTags
= array(
105 # TIFF Rev. 6.0 Attribute Information (p22)
107 # Tags relating to image structure
108 'structure' => array(
109 'ImageWidth' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image width
110 'ImageLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image height
111 'BitsPerSample' => MW_EXIF_SHORT
, # Number of bits per component
112 # "When a primary image is JPEG compressed, this designation is not"
113 # "necessary and is omitted." (p23)
114 'Compression' => MW_EXIF_SHORT
, # Compression scheme #p23
115 'PhotometricInterpretation' => MW_EXIF_SHORT
, # Pixel composition #p23
116 'Orientation' => MW_EXIF_SHORT
, # Orientation of image #p24
117 'SamplesPerPixel' => MW_EXIF_SHORT
, # Number of components
118 'PlanarConfiguration' => MW_EXIF_SHORT
, # Image data arrangement #p24
119 'YCbCrSubSampling' => MW_EXIF_SHORT
, # Subsampling ratio of Y to C #p24
120 'YCbCrPositioning' => MW_EXIF_SHORT
, # Y and C positioning #p24-25
121 'XResolution' => MW_EXIF_RATIONAL
, # Image resolution in width direction
122 'YResolution' => MW_EXIF_RATIONAL
, # Image resolution in height direction
123 'ResolutionUnit' => MW_EXIF_SHORT
, # Unit of X and Y resolution #(p26)
126 # Tags relating to recording offset
128 'StripOffsets' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image data location
129 'RowsPerStrip' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Number of rows per strip
130 'StripByteCounts' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes per compressed strip
131 'JPEGInterchangeFormat' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Offset to JPEG SOI
132 'JPEGInterchangeFormatLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes of JPEG data
135 # Tags relating to image data characteristics
136 'characteristics' => array(
137 'TransferFunction' => MW_EXIF_SHORT
, # Transfer function
138 'WhitePoint' => MW_EXIF_RATIONAL
, # White point chromaticity
139 'PrimaryChromaticities' => MW_EXIF_RATIONAL
, # Chromaticities of primarities
140 'YCbCrCoefficients' => MW_EXIF_RATIONAL
, # Color space transformation matrix coefficients #p27
141 'ReferenceBlackWhite' => MW_EXIF_RATIONAL
# Pair of black and white reference values
146 'DateTime' => MW_EXIF_ASCII
, # File change date and time
147 'ImageDescription' => MW_EXIF_ASCII
, # Image title
148 'Make' => MW_EXIF_ASCII
, # Image input equipment manufacturer
149 'Model' => MW_EXIF_ASCII
, # Image input equipment model
150 'Software' => MW_EXIF_ASCII
, # Software used
151 'Artist' => MW_EXIF_ASCII
, # Person who created the image
152 'Copyright' => MW_EXIF_ASCII
, # Copyright holder
156 # Exif IFD Attribute Information (p30-31)
158 # Tags relating to version
160 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
161 # to the EXIF 2.1 AND 2.2 standards
162 'ExifVersion' => MW_EXIF_UNDEFINED
, # Exif version
163 'FlashpixVersion' => MW_EXIF_UNDEFINED
, # Supported Flashpix version #p32
166 # Tags relating to Image Data Characteristics
167 'characteristics' => array(
168 'ColorSpace' => MW_EXIF_SHORT
, # Color space information #p32
171 # Tags relating to image configuration
172 'configuration' => array(
173 'ComponentsConfiguration' => MW_EXIF_UNDEFINED
, # Meaning of each component #p33
174 'CompressedBitsPerPixel' => MW_EXIF_RATIONAL
, # Image compression mode
175 'PixelYDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valid image width
176 'PixelXDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valind image height
179 # Tags relating to related user information
181 'MakerNote' => MW_EXIF_UNDEFINED
, # Manufacturer notes
182 'UserComment' => MW_EXIF_UNDEFINED
, # User comments #p34
185 # Tags relating to related file information
187 'RelatedSoundFile' => MW_EXIF_ASCII
, # Related audio file
190 # Tags relating to date and time
191 'dateandtime' => array(
192 'DateTimeOriginal' => MW_EXIF_ASCII
, # Date and time of original data generation #p36
193 'DateTimeDigitized' => MW_EXIF_ASCII
, # Date and time of original data generation
194 'SubSecTime' => MW_EXIF_ASCII
, # DateTime subseconds
195 'SubSecTimeOriginal' => MW_EXIF_ASCII
, # DateTimeOriginal subseconds
196 'SubSecTimeDigitized' => MW_EXIF_ASCII
, # DateTimeDigitized subseconds
199 # Tags relating to picture-taking conditions (p31)
200 'conditions' => array(
201 'ExposureTime' => MW_EXIF_RATIONAL
, # Exposure time
202 'FNumber' => MW_EXIF_RATIONAL
, # F Number
203 'ExposureProgram' => MW_EXIF_SHORT
, # Exposure Program #p38
204 'SpectralSensitivity' => MW_EXIF_ASCII
, # Spectral sensitivity
205 'ISOSpeedRatings' => MW_EXIF_SHORT
, # ISO speed rating
206 'OECF' => MW_EXIF_UNDEFINED
, # Optoelectronic conversion factor
207 'ShutterSpeedValue' => MW_EXIF_SRATIONAL
, # Shutter speed
208 'ApertureValue' => MW_EXIF_RATIONAL
, # Aperture
209 'BrightnessValue' => MW_EXIF_SRATIONAL
, # Brightness
210 'ExposureBiasValue' => MW_EXIF_SRATIONAL
, # Exposure bias
211 'MaxApertureValue' => MW_EXIF_RATIONAL
, # Maximum land aperture
212 'SubjectDistance' => MW_EXIF_RATIONAL
, # Subject distance
213 'MeteringMode' => MW_EXIF_SHORT
, # Metering mode #p40
214 'LightSource' => MW_EXIF_SHORT
, # Light source #p40-41
215 'Flash' => MW_EXIF_SHORT
, # Flash #p41-42
216 'FocalLength' => MW_EXIF_RATIONAL
, # Lens focal length
217 'SubjectArea' => MW_EXIF_SHORT
, # Subject area
218 'FlashEnergy' => MW_EXIF_RATIONAL
, # Flash energy
219 'SpatialFrequencyResponse' => MW_EXIF_UNDEFINED
, # Spatial frequency response
220 'FocalPlaneXResolution' => MW_EXIF_RATIONAL
, # Focal plane X resolution
221 'FocalPlaneYResolution' => MW_EXIF_RATIONAL
, # Focal plane Y resolution
222 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT
, # Focal plane resolution unit #p46
223 'SubjectLocation' => MW_EXIF_SHORT
, # Subject location
224 'ExposureIndex' => MW_EXIF_RATIONAL
, # Exposure index
225 'SensingMethod' => MW_EXIF_SHORT
, # Sensing method #p46
226 'FileSource' => MW_EXIF_UNDEFINED
, # File source #p47
227 'SceneType' => MW_EXIF_UNDEFINED
, # Scene type #p47
228 'CFAPattern' => MW_EXIF_UNDEFINED
, # CFA pattern
229 'CustomRendered' => MW_EXIF_SHORT
, # Custom image processing #p48
230 'ExposureMode' => MW_EXIF_SHORT
, # Exposure mode #p48
231 'WhiteBalance' => MW_EXIF_SHORT
, # White Balance #p49
232 'DigitalZoomRatio' => MW_EXIF_RATIONAL
, # Digital zoom ration
233 'FocalLengthIn35mmFilm' => MW_EXIF_SHORT
, # Focal length in 35 mm film
234 'SceneCaptureType' => MW_EXIF_SHORT
, # Scene capture type #p49
235 'GainControl' => MW_EXIF_RATIONAL
, # Scene control #p49-50
236 'Contrast' => MW_EXIF_SHORT
, # Contrast #p50
237 'Saturation' => MW_EXIF_SHORT
, # Saturation #p50
238 'Sharpness' => MW_EXIF_SHORT
, # Sharpness #p50
239 'DeviceSettingDescription' => MW_EXIF_UNDEFINED
, # Desice settings description
240 'SubjectDistanceRange' => MW_EXIF_SHORT
, # Subject distance range #p51
244 'ImageUniqueID' => MW_EXIF_ASCII
, # Unique image ID
248 # GPS Attribute Information (p52)
250 'GPSVersionID' => MW_EXIF_BYTE
, # GPS tag version
251 'GPSLatitudeRef' => MW_EXIF_ASCII
, # North or South Latitude #p52-53
252 'GPSLatitude' => MW_EXIF_RATIONAL
, # Latitude
253 'GPSLongitudeRef' => MW_EXIF_ASCII
, # East or West Longitude #p53
254 'GPSLongitude' => MW_EXIF_RATIONAL
, # Longitude
255 'GPSAltitudeRef' => MW_EXIF_BYTE
, # Altitude reference
256 'GPSAltitude' => MW_EXIF_RATIONAL
, # Altitude
257 'GPSTimeStamp' => MW_EXIF_RATIONAL
, # GPS time (atomic clock)
258 'GPSSatellites' => MW_EXIF_ASCII
, # Satellites used for measurement
259 'GPSStatus' => MW_EXIF_ASCII
, # Receiver status #p54
260 'GPSMeasureMode' => MW_EXIF_ASCII
, # Measurement mode #p54-55
261 'GPSDOP' => MW_EXIF_RATIONAL
, # Measurement precision
262 'GPSSpeedRef' => MW_EXIF_ASCII
, # Speed unit #p55
263 'GPSSpeed' => MW_EXIF_RATIONAL
, # Speed of GPS receiver
264 'GPSTrackRef' => MW_EXIF_ASCII
, # Reference for direction of movement #p55
265 'GPSTrack' => MW_EXIF_RATIONAL
, # Direction of movement
266 'GPSImgDirectionRef' => MW_EXIF_ASCII
, # Reference for direction of image #p56
267 'GPSImgDirection' => MW_EXIF_RATIONAL
, # Direction of image
268 'GPSMapDatum' => MW_EXIF_ASCII
, # Geodetic survey data used
269 'GPSDestLatitudeRef' => MW_EXIF_ASCII
, # Reference for latitude of destination #p56
270 'GPSDestLatitude' => MW_EXIF_RATIONAL
, # Latitude destination
271 'GPSDestLongitudeRef' => MW_EXIF_ASCII
, # Reference for longitude of destination #p57
272 'GPSDestLongitude' => MW_EXIF_RATIONAL
, # Longitude of destination
273 'GPSDestBearingRef' => MW_EXIF_ASCII
, # Reference for bearing of destination #p57
274 'GPSDestBearing' => MW_EXIF_RATIONAL
, # Bearing of destination
275 'GPSDestDistanceRef' => MW_EXIF_ASCII
, # Reference for distance to destination #p57-58
276 'GPSDestDistance' => MW_EXIF_RATIONAL
, # Distance to destination
277 'GPSProcessingMethod' => MW_EXIF_UNDEFINED
, # Name of GPS processing method
278 'GPSAreaInformation' => MW_EXIF_UNDEFINED
, # Name of GPS area
279 'GPSDateStamp' => MW_EXIF_ASCII
, # GPS date
280 'GPSDifferential' => MW_EXIF_SHORT
, # GPS differential correction
284 $basename = basename( $file );
286 $this->makeFlatExifTags();
288 $this->debugFile( $basename, __FUNCTION__
, true );
289 wfSuppressWarnings();
290 $data = exif_read_data( $file );
293 * exif_read_data() will return false on invalid input, such as
294 * when somebody uploads a file called something.jpeg
295 * containing random gibberish.
297 $this->mRawExifData
= $data ?
$data : array();
299 $this->makeFilteredData();
300 $this->makeFormattedData();
302 $this->debugFile( $basename, __FUNCTION__
, false );
309 * Generate a flat list of the exif tags
311 function makeFlatExifTags() {
312 $this->extractTags( $this->mExifTags
);
316 * A recursing extractor function used by makeFlatExifTags()
318 * Note: This used to use an array_walk function, but it made PHP5
319 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
321 function extractTags( &$tagset ) {
322 foreach( $tagset as $key => $val ) {
323 if( is_array( $val ) ) {
324 $this->extractTags( $val );
326 $this->mFlatExifTags
[$key] = $val;
332 * Make $this->mFilteredExifData
334 function makeFilteredData() {
335 $this->mFilteredExifData
= $this->mRawExifData
;
337 foreach( $this->mFilteredExifData
as $k => $v ) {
338 if ( !in_array( $k, array_keys( $this->mFlatExifTags
) ) ) {
339 $this->debug( $v, __FUNCTION__
, "'$k' is not a valid Exif tag" );
340 unset( $this->mFilteredExifData
[$k] );
344 foreach( $this->mFilteredExifData
as $k => $v ) {
345 if ( !$this->validate($k, $v) ) {
346 $this->debug( $v, __FUNCTION__
, "'$k' contained invalid data" );
347 unset( $this->mFilteredExifData
[$k] );
352 function makeFormattedData( $data = null ) {
353 $format = new FormatExif( $this->getFilteredData() );
354 $this->mFormattedExifData
= $format->getFormattedData();
362 * Get $this->mRawExifData
365 return $this->mRawExifData
;
369 * Get $this->mFilteredExifData
371 function getFilteredData() {
372 return $this->mFilteredExifData
;
376 * Get $this->mFormattedExifData
378 function getFormattedData() {
379 return $this->mFormattedExifData
;
384 * The version of the output format
386 * Before the actual metadata information is saved in the database we
387 * strip some of it since we don't want to save things like thumbnails
388 * which usually accompany Exif data. This value gets saved in the
389 * database along with the actual Exif data, and if the version in the
390 * database doesn't equal the value returned by this function the Exif
391 * data is regenerated.
396 return 1; // We don't need no bloddy constants!
400 * Validates if a tag value is of the type it should be according to the Exif spec
404 * @param mixed $in The input value to check
407 function isByte( $in ) {
408 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
409 $this->debug( $in, __FUNCTION__
, true );
412 $this->debug( $in, __FUNCTION__
, false );
417 function isASCII( $in ) {
418 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
419 $this->debug( $in, __FUNCTION__
, 'found a character not in our whitelist' );
423 if ( preg_match( "/^\s*$/", $in ) ) {
424 $this->debug( $in, __FUNCTION__
, 'input consisted solely of whitespace' );
431 function isShort( $in ) {
432 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
433 $this->debug( $in, __FUNCTION__
, true );
436 $this->debug( $in, __FUNCTION__
, false );
441 function isLong( $in ) {
442 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
443 $this->debug( $in, __FUNCTION__
, true );
446 $this->debug( $in, __FUNCTION__
, false );
451 function isRational( $in ) {
452 if ( @preg_match
( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
453 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
455 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
460 function isUndefined( $in ) {
461 if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
462 $this->debug( $in, __FUNCTION__
, true );
465 $this->debug( $in, __FUNCTION__
, false );
470 function isSlong( $in ) {
471 if ( $this->isLong( abs( $in ) ) ) {
472 $this->debug( $in, __FUNCTION__
, true );
475 $this->debug( $in, __FUNCTION__
, false );
480 function isSrational( $in ) {
481 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
482 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
484 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
491 * Validates if a tag has a legal value according to the Exif spec
495 * @param string $tag The tag to check
496 * @param mixed $val The value of the tag
499 function validate( $tag, $val ) {
500 $debug = "tag is '$tag'";
501 // Fucks up if not typecast
502 switch( (string)$this->mFlatExifTags
[$tag] ) {
503 case (string)MW_EXIF_BYTE
:
504 $this->debug( $val, __FUNCTION__
, $debug );
505 return $this->isByte( $val );
506 case (string)MW_EXIF_ASCII
:
507 $this->debug( $val, __FUNCTION__
, $debug );
508 return $this->isASCII( $val );
509 case (string)MW_EXIF_SHORT
:
510 $this->debug( $val, __FUNCTION__
, $debug );
511 return $this->isShort( $val );
512 case (string)MW_EXIF_LONG
:
513 $this->debug( $val, __FUNCTION__
, $debug );
514 return $this->isLong( $val );
515 case (string)MW_EXIF_RATIONAL
:
516 $this->debug( $val, __FUNCTION__
, $debug );
517 return $this->isRational( $val );
518 case (string)MW_EXIF_UNDEFINED
:
519 $this->debug( $val, __FUNCTION__
, $debug );
520 return $this->isUndefined( $val );
521 case (string)MW_EXIF_SLONG
:
522 $this->debug( $val, __FUNCTION__
, $debug );
523 return $this->isSlong( $val );
524 case (string)MW_EXIF_SRATIONAL
:
525 $this->debug( $val, __FUNCTION__
, $debug );
526 return $this->isSrational( $val );
527 case (string)MW_EXIF_SHORT
.','.MW_EXIF_LONG
:
528 $this->debug( $val, __FUNCTION__
, $debug );
529 return $this->isShort( $val ) ||
$this->isLong( $val );
531 $this->debug( $val, __FUNCTION__
, "The tag '$tag' is unknown" );
537 * Conviniance function for debugging output
542 * @param string $fname
543 * @param mixed $action
545 function debug( $in, $fname, $action = null ) {
546 $type = gettype( $in );
547 $class = ucfirst( __CLASS__
);
548 if ( $type === 'array' )
549 $in = print_r( $in, true );
551 if ( $action === true )
552 wfDebugLog( $this->log
, "$class::$fname: accepted: '$in' (type: $type)\n");
553 elseif ( $action === false )
554 wfDebugLog( $this->log
, "$class::$fname: rejected: '$in' (type: $type)\n");
555 elseif ( $action === null )
556 wfDebugLog( $this->log
, "$class::$fname: input was: '$in' (type: $type)\n");
558 wfDebugLog( $this->log
, "$class::$fname: $action (type: $type; content: '$in')\n");
562 * Conviniance function for debugging output
566 * @param string $basename The name of the file being processed
567 * @paran string $fname The name of the function calling this function
568 * @param bool $bool $io Specify whether we're beginning or ending
570 function debugFile( $basename, $fname, $io ) {
571 $class = ucfirst( __CLASS__
);
573 wfDebugLog( $this->log
, "$class::$fname: begin processing: '$basename'\n" );
575 wfDebugLog( $this->log
, "$class::$fname: end processing: '$basename'\n" );
582 * @subpackage Metadata
586 * The Exif data to format
596 * @param array $exif The Exif data to format ( as returned by
597 * Exif::getFilteredData() )
599 function FormatExif( $exif ) {
600 $this->mExif
= $exif;
604 * Numbers given by Exif user agents are often magical, that is they
605 * should be replaced by a detailed explanation depending on their
606 * value which most of the time are plain integers. This function
607 * formats Exif values into human readable form.
611 function getFormattedData() {
614 $tags =& $this->mExif
;
616 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
617 unset( $tags['ResolutionUnit'] );
619 foreach( $tags as $tag => $val ) {
624 $tags[$tag] = $this->msg( $tag, $val );
632 case 'PhotometricInterpretation':
635 $tags[$tag] = $this->msg( $tag, $val );
645 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
646 $tags[$tag] = $this->msg( $tag, $val );
654 case 'PlanarConfiguration':
657 $tags[$tag] = $this->msg( $tag, $val );
665 // TODO: YCbCrSubSampling
666 // TODO: YCbCrPositioning
670 switch( $resolutionunit ) {
672 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
675 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
683 // TODO: YCbCrCoefficients #p27 (see annex E)
684 case 'ExifVersion': case 'FlashpixVersion':
685 $tags[$tag] = "$val"/100;
690 case 1: case 'FFFF.H':
691 $tags[$tag] = $this->msg( $tag, $val );
699 case 'ComponentsConfiguration':
701 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
702 $tags[$tag] = $this->msg( $tag, $val );
711 case 'DateTimeOriginal':
712 case 'DateTimeDigitized':
713 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW
, $val) );
716 case 'ExposureProgram':
718 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
719 $tags[$tag] = $this->msg( $tag, $val );
727 case 'SubjectDistance':
728 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
733 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
734 $tags[$tag] = $this->msg( $tag, $val );
744 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
745 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
746 case 21: case 22: case 23: case 24: case 255:
747 $tags[$tag] = $this->msg( $tag, $val );
756 case 'FocalPlaneResolutionUnit':
759 $tags[$tag] = $this->msg( $tag, $val );
767 case 'SensingMethod':
769 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
770 $tags[$tag] = $this->msg( $tag, $val );
781 $tags[$tag] = $this->msg( $tag, $val );
792 $tags[$tag] = $this->msg( $tag, $val );
800 case 'CustomRendered':
803 $tags[$tag] = $this->msg( $tag, $val );
813 case 0: case 1: case 2:
814 $tags[$tag] = $this->msg( $tag, $val );
825 $tags[$tag] = $this->msg( $tag, $val );
833 case 'SceneCaptureType':
835 case 0: case 1: case 2: case 3:
836 $tags[$tag] = $this->msg( $tag, $val );
846 case 0: case 1: case 2: case 3: case 4:
847 $tags[$tag] = $this->msg( $tag, $val );
857 case 0: case 1: case 2:
858 $tags[$tag] = $this->msg( $tag, $val );
868 case 0: case 1: case 2:
869 $tags[$tag] = $this->msg( $tag, $val );
879 case 0: case 1: case 2:
880 $tags[$tag] = $this->msg( $tag, $val );
888 case 'SubjectDistanceRange':
890 case 0: case 1: case 2: case 3:
891 $tags[$tag] = $this->msg( $tag, $val );
899 case 'GPSLatitudeRef':
900 case 'GPSDestLatitudeRef':
903 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
911 case 'GPSLongitudeRef':
912 case 'GPSDestLongitudeRef':
915 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
926 $tags[$tag] = $this->msg( $tag, $val );
934 case 'GPSMeasureMode':
937 $tags[$tag] = $this->msg( $tag, $val );
946 case 'GPSDestDistanceRef':
948 case 'K': case 'M': case 'N':
949 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
958 case 'GPSImgDirectionRef':
959 case 'GPSDestBearingRef':
962 $tags[$tag] = $this->msg( 'GPSDirection', $val );
971 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
974 // This is not in the Exif standard, just a special
975 // case for our purposes which enables wikis to wikify
976 // the make, model and software name to link to their articles.
980 $tags[$tag] = $this->msg( $tag, '', $val );
983 $tags[$tag] = $this->formatNum( $val );
992 * Conviniance function for getFormattedData()
996 * @param string $tag The tag name to pass on
997 * @param string $val The value of the tag
998 * @param string $arg An argument to pass ($1)
999 * @return string A wfMsg of "exif-$tag-$val" in lower case
1001 function msg( $tag, $val, $arg = null ) {
1004 return wfMsg( strtolower( "exif-$tag-$val" ), $arg );
1008 * Format a number, convert numbers from fractions into floating point
1013 * @param mixed $num The value to format
1014 * @return mixed A floating point number or whatever we were fed
1016 function formatNum( $num ) {
1017 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
1018 return $m[2] != 0 ?
$m[1] / $m[2] : $num;