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;
91 * The file being processed
96 * The basename of the file being processed
101 * The private log to log to
110 * @param string $file
112 function Exif( $file ) {
114 * Page numbers here refer to pages in the EXIF 2.2 standard
116 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
118 $this->mExifTags
= array(
119 # TIFF Rev. 6.0 Attribute Information (p22)
121 # Tags relating to image structure
122 'structure' => array(
123 'ImageWidth' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image width
124 'ImageLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image height
125 'BitsPerSample' => MW_EXIF_SHORT
, # Number of bits per component
126 # "When a primary image is JPEG compressed, this designation is not"
127 # "necessary and is omitted." (p23)
128 'Compression' => MW_EXIF_SHORT
, # Compression scheme #p23
129 'PhotometricInterpretation' => MW_EXIF_SHORT
, # Pixel composition #p23
130 'Orientation' => MW_EXIF_SHORT
, # Orientation of image #p24
131 'SamplesPerPixel' => MW_EXIF_SHORT
, # Number of components
132 'PlanarConfiguration' => MW_EXIF_SHORT
, # Image data arrangement #p24
133 'YCbCrSubSampling' => MW_EXIF_SHORT
, # Subsampling ratio of Y to C #p24
134 'YCbCrPositioning' => MW_EXIF_SHORT
, # Y and C positioning #p24-25
135 'XResolution' => MW_EXIF_RATIONAL
, # Image resolution in width direction
136 'YResolution' => MW_EXIF_RATIONAL
, # Image resolution in height direction
137 'ResolutionUnit' => MW_EXIF_SHORT
, # Unit of X and Y resolution #(p26)
140 # Tags relating to recording offset
142 'StripOffsets' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image data location
143 'RowsPerStrip' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Number of rows per strip
144 'StripByteCounts' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes per compressed strip
145 'JPEGInterchangeFormat' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Offset to JPEG SOI
146 'JPEGInterchangeFormatLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes of JPEG data
149 # Tags relating to image data characteristics
150 'characteristics' => array(
151 'TransferFunction' => MW_EXIF_SHORT
, # Transfer function
152 'WhitePoint' => MW_EXIF_RATIONAL
, # White point chromaticity
153 'PrimaryChromaticities' => MW_EXIF_RATIONAL
, # Chromaticities of primarities
154 'YCbCrCoefficients' => MW_EXIF_RATIONAL
, # Color space transformation matrix coefficients #p27
155 'ReferenceBlackWhite' => MW_EXIF_RATIONAL
# Pair of black and white reference values
160 'DateTime' => MW_EXIF_ASCII
, # File change date and time
161 'ImageDescription' => MW_EXIF_ASCII
, # Image title
162 'Make' => MW_EXIF_ASCII
, # Image input equipment manufacturer
163 'Model' => MW_EXIF_ASCII
, # Image input equipment model
164 'Software' => MW_EXIF_ASCII
, # Software used
165 'Artist' => MW_EXIF_ASCII
, # Person who created the image
166 'Copyright' => MW_EXIF_ASCII
, # Copyright holder
170 # Exif IFD Attribute Information (p30-31)
172 # Tags relating to version
174 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
175 # to the EXIF 2.1 AND 2.2 standards
176 'ExifVersion' => MW_EXIF_UNDEFINED
, # Exif version
177 'FlashpixVersion' => MW_EXIF_UNDEFINED
, # Supported Flashpix version #p32
180 # Tags relating to Image Data Characteristics
181 'characteristics' => array(
182 'ColorSpace' => MW_EXIF_SHORT
, # Color space information #p32
185 # Tags relating to image configuration
186 'configuration' => array(
187 'ComponentsConfiguration' => MW_EXIF_UNDEFINED
, # Meaning of each component #p33
188 'CompressedBitsPerPixel' => MW_EXIF_RATIONAL
, # Image compression mode
189 'PixelYDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valid image width
190 'PixelXDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valind image height
193 # Tags relating to related user information
195 'MakerNote' => MW_EXIF_UNDEFINED
, # Manufacturer notes
196 'UserComment' => MW_EXIF_UNDEFINED
, # User comments #p34
199 # Tags relating to related file information
201 'RelatedSoundFile' => MW_EXIF_ASCII
, # Related audio file
204 # Tags relating to date and time
205 'dateandtime' => array(
206 'DateTimeOriginal' => MW_EXIF_ASCII
, # Date and time of original data generation #p36
207 'DateTimeDigitized' => MW_EXIF_ASCII
, # Date and time of original data generation
208 'SubSecTime' => MW_EXIF_ASCII
, # DateTime subseconds
209 'SubSecTimeOriginal' => MW_EXIF_ASCII
, # DateTimeOriginal subseconds
210 'SubSecTimeDigitized' => MW_EXIF_ASCII
, # DateTimeDigitized subseconds
213 # Tags relating to picture-taking conditions (p31)
214 'conditions' => array(
215 'ExposureTime' => MW_EXIF_RATIONAL
, # Exposure time
216 'FNumber' => MW_EXIF_RATIONAL
, # F Number
217 'ExposureProgram' => MW_EXIF_SHORT
, # Exposure Program #p38
218 'SpectralSensitivity' => MW_EXIF_ASCII
, # Spectral sensitivity
219 'ISOSpeedRatings' => MW_EXIF_SHORT
, # ISO speed rating
220 'OECF' => MW_EXIF_UNDEFINED
, # Optoelectronic conversion factor
221 'ShutterSpeedValue' => MW_EXIF_SRATIONAL
, # Shutter speed
222 'ApertureValue' => MW_EXIF_RATIONAL
, # Aperture
223 'BrightnessValue' => MW_EXIF_SRATIONAL
, # Brightness
224 'ExposureBiasValue' => MW_EXIF_SRATIONAL
, # Exposure bias
225 'MaxApertureValue' => MW_EXIF_RATIONAL
, # Maximum land aperture
226 'SubjectDistance' => MW_EXIF_RATIONAL
, # Subject distance
227 'MeteringMode' => MW_EXIF_SHORT
, # Metering mode #p40
228 'LightSource' => MW_EXIF_SHORT
, # Light source #p40-41
229 'Flash' => MW_EXIF_SHORT
, # Flash #p41-42
230 'FocalLength' => MW_EXIF_RATIONAL
, # Lens focal length
231 'SubjectArea' => MW_EXIF_SHORT
, # Subject area
232 'FlashEnergy' => MW_EXIF_RATIONAL
, # Flash energy
233 'SpatialFrequencyResponse' => MW_EXIF_UNDEFINED
, # Spatial frequency response
234 'FocalPlaneXResolution' => MW_EXIF_RATIONAL
, # Focal plane X resolution
235 'FocalPlaneYResolution' => MW_EXIF_RATIONAL
, # Focal plane Y resolution
236 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT
, # Focal plane resolution unit #p46
237 'SubjectLocation' => MW_EXIF_SHORT
, # Subject location
238 'ExposureIndex' => MW_EXIF_RATIONAL
, # Exposure index
239 'SensingMethod' => MW_EXIF_SHORT
, # Sensing method #p46
240 'FileSource' => MW_EXIF_UNDEFINED
, # File source #p47
241 'SceneType' => MW_EXIF_UNDEFINED
, # Scene type #p47
242 'CFAPattern' => MW_EXIF_UNDEFINED
, # CFA pattern
243 'CustomRendered' => MW_EXIF_SHORT
, # Custom image processing #p48
244 'ExposureMode' => MW_EXIF_SHORT
, # Exposure mode #p48
245 'WhiteBalance' => MW_EXIF_SHORT
, # White Balance #p49
246 'DigitalZoomRatio' => MW_EXIF_RATIONAL
, # Digital zoom ration
247 'FocalLengthIn35mmFilm' => MW_EXIF_SHORT
, # Focal length in 35 mm film
248 'SceneCaptureType' => MW_EXIF_SHORT
, # Scene capture type #p49
249 'GainControl' => MW_EXIF_RATIONAL
, # Scene control #p49-50
250 'Contrast' => MW_EXIF_SHORT
, # Contrast #p50
251 'Saturation' => MW_EXIF_SHORT
, # Saturation #p50
252 'Sharpness' => MW_EXIF_SHORT
, # Sharpness #p50
253 'DeviceSettingDescription' => MW_EXIF_UNDEFINED
, # Desice settings description
254 'SubjectDistanceRange' => MW_EXIF_SHORT
, # Subject distance range #p51
258 'ImageUniqueID' => MW_EXIF_ASCII
, # Unique image ID
262 # GPS Attribute Information (p52)
264 'GPSVersionID' => MW_EXIF_BYTE
, # GPS tag version
265 'GPSLatitudeRef' => MW_EXIF_ASCII
, # North or South Latitude #p52-53
266 'GPSLatitude' => MW_EXIF_RATIONAL
, # Latitude
267 'GPSLongitudeRef' => MW_EXIF_ASCII
, # East or West Longitude #p53
268 'GPSLongitude' => MW_EXIF_RATIONAL
, # Longitude
269 'GPSAltitudeRef' => MW_EXIF_BYTE
, # Altitude reference
270 'GPSAltitude' => MW_EXIF_RATIONAL
, # Altitude
271 'GPSTimeStamp' => MW_EXIF_RATIONAL
, # GPS time (atomic clock)
272 'GPSSatellites' => MW_EXIF_ASCII
, # Satellites used for measurement
273 'GPSStatus' => MW_EXIF_ASCII
, # Receiver status #p54
274 'GPSMeasureMode' => MW_EXIF_ASCII
, # Measurement mode #p54-55
275 'GPSDOP' => MW_EXIF_RATIONAL
, # Measurement precision
276 'GPSSpeedRef' => MW_EXIF_ASCII
, # Speed unit #p55
277 'GPSSpeed' => MW_EXIF_RATIONAL
, # Speed of GPS receiver
278 'GPSTrackRef' => MW_EXIF_ASCII
, # Reference for direction of movement #p55
279 'GPSTrack' => MW_EXIF_RATIONAL
, # Direction of movement
280 'GPSImgDirectionRef' => MW_EXIF_ASCII
, # Reference for direction of image #p56
281 'GPSImgDirection' => MW_EXIF_RATIONAL
, # Direction of image
282 'GPSMapDatum' => MW_EXIF_ASCII
, # Geodetic survey data used
283 'GPSDestLatitudeRef' => MW_EXIF_ASCII
, # Reference for latitude of destination #p56
284 'GPSDestLatitude' => MW_EXIF_RATIONAL
, # Latitude destination
285 'GPSDestLongitudeRef' => MW_EXIF_ASCII
, # Reference for longitude of destination #p57
286 'GPSDestLongitude' => MW_EXIF_RATIONAL
, # Longitude of destination
287 'GPSDestBearingRef' => MW_EXIF_ASCII
, # Reference for bearing of destination #p57
288 'GPSDestBearing' => MW_EXIF_RATIONAL
, # Bearing of destination
289 'GPSDestDistanceRef' => MW_EXIF_ASCII
, # Reference for distance to destination #p57-58
290 'GPSDestDistance' => MW_EXIF_RATIONAL
, # Distance to destination
291 'GPSProcessingMethod' => MW_EXIF_UNDEFINED
, # Name of GPS processing method
292 'GPSAreaInformation' => MW_EXIF_UNDEFINED
, # Name of GPS area
293 'GPSDateStamp' => MW_EXIF_ASCII
, # GPS date
294 'GPSDifferential' => MW_EXIF_SHORT
, # GPS differential correction
299 $this->basename
= basename( $this->file
);
301 $this->makeFlatExifTags();
303 $this->debugFile( $this->basename
, __FUNCTION__
, true );
304 wfSuppressWarnings();
305 $data = exif_read_data( $this->file
);
308 * exif_read_data() will return false on invalid input, such as
309 * when somebody uploads a file called something.jpeg
310 * containing random gibberish.
312 $this->mRawExifData
= $data ?
$data : array();
314 $this->makeFilteredData();
315 $this->makeFormattedData();
317 $this->debugFile( __FUNCTION__
, false );
324 * Generate a flat list of the exif tags
326 function makeFlatExifTags() {
327 $this->extractTags( $this->mExifTags
);
331 * A recursing extractor function used by makeFlatExifTags()
333 * Note: This used to use an array_walk function, but it made PHP5
334 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
336 function extractTags( &$tagset ) {
337 foreach( $tagset as $key => $val ) {
338 if( is_array( $val ) ) {
339 $this->extractTags( $val );
341 $this->mFlatExifTags
[$key] = $val;
347 * Make $this->mFilteredExifData
349 function makeFilteredData() {
350 $this->mFilteredExifData
= $this->mRawExifData
;
352 foreach( $this->mFilteredExifData
as $k => $v ) {
353 if ( !in_array( $k, array_keys( $this->mFlatExifTags
) ) ) {
354 $this->debug( $v, __FUNCTION__
, "'$k' is not a valid Exif tag" );
355 unset( $this->mFilteredExifData
[$k] );
359 foreach( $this->mFilteredExifData
as $k => $v ) {
360 if ( !$this->validate($k, $v) ) {
361 $this->debug( $v, __FUNCTION__
, "'$k' contained invalid data" );
362 unset( $this->mFilteredExifData
[$k] );
367 function makeFormattedData( $data = null ) {
368 $format = new FormatExif( $this->getFilteredData() );
369 $this->mFormattedExifData
= $format->getFormattedData();
377 * Get $this->mRawExifData
380 return $this->mRawExifData
;
384 * Get $this->mFilteredExifData
386 function getFilteredData() {
387 return $this->mFilteredExifData
;
391 * Get $this->mFormattedExifData
393 function getFormattedData() {
394 return $this->mFormattedExifData
;
399 * The version of the output format
401 * Before the actual metadata information is saved in the database we
402 * strip some of it since we don't want to save things like thumbnails
403 * which usually accompany Exif data. This value gets saved in the
404 * database along with the actual Exif data, and if the version in the
405 * database doesn't equal the value returned by this function the Exif
406 * data is regenerated.
411 return 1; // We don't need no bloddy constants!
415 * Validates if a tag value is of the type it should be according to the Exif spec
419 * @param mixed $in The input value to check
422 function isByte( $in ) {
423 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
424 $this->debug( $in, __FUNCTION__
, true );
427 $this->debug( $in, __FUNCTION__
, false );
432 function isASCII( $in ) {
433 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
434 $this->debug( $in, __FUNCTION__
, 'found a character not in our whitelist' );
438 if ( preg_match( "/^\s*$/", $in ) ) {
439 $this->debug( $in, __FUNCTION__
, 'input consisted solely of whitespace' );
446 function isShort( $in ) {
447 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
448 $this->debug( $in, __FUNCTION__
, true );
451 $this->debug( $in, __FUNCTION__
, false );
456 function isLong( $in ) {
457 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
458 $this->debug( $in, __FUNCTION__
, true );
461 $this->debug( $in, __FUNCTION__
, false );
466 function isRational( $in ) {
467 if ( @preg_match
( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
468 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
470 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
475 function isUndefined( $in ) {
476 if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
477 $this->debug( $in, __FUNCTION__
, true );
480 $this->debug( $in, __FUNCTION__
, false );
485 function isSlong( $in ) {
486 if ( $this->isLong( abs( $in ) ) ) {
487 $this->debug( $in, __FUNCTION__
, true );
490 $this->debug( $in, __FUNCTION__
, false );
495 function isSrational( $in ) {
496 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
497 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
499 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
506 * Validates if a tag has a legal value according to the Exif spec
510 * @param string $tag The tag to check
511 * @param mixed $val The value of the tag
514 function validate( $tag, $val ) {
515 $debug = "tag is '$tag'";
516 // Fucks up if not typecast
517 switch( (string)$this->mFlatExifTags
[$tag] ) {
518 case (string)MW_EXIF_BYTE
:
519 $this->debug( $val, __FUNCTION__
, $debug );
520 return $this->isByte( $val );
521 case (string)MW_EXIF_ASCII
:
522 $this->debug( $val, __FUNCTION__
, $debug );
523 return $this->isASCII( $val );
524 case (string)MW_EXIF_SHORT
:
525 $this->debug( $val, __FUNCTION__
, $debug );
526 return $this->isShort( $val );
527 case (string)MW_EXIF_LONG
:
528 $this->debug( $val, __FUNCTION__
, $debug );
529 return $this->isLong( $val );
530 case (string)MW_EXIF_RATIONAL
:
531 $this->debug( $val, __FUNCTION__
, $debug );
532 return $this->isRational( $val );
533 case (string)MW_EXIF_UNDEFINED
:
534 $this->debug( $val, __FUNCTION__
, $debug );
535 return $this->isUndefined( $val );
536 case (string)MW_EXIF_SLONG
:
537 $this->debug( $val, __FUNCTION__
, $debug );
538 return $this->isSlong( $val );
539 case (string)MW_EXIF_SRATIONAL
:
540 $this->debug( $val, __FUNCTION__
, $debug );
541 return $this->isSrational( $val );
542 case (string)MW_EXIF_SHORT
.','.MW_EXIF_LONG
:
543 $this->debug( $val, __FUNCTION__
, $debug );
544 return $this->isShort( $val ) ||
$this->isLong( $val );
546 $this->debug( $val, __FUNCTION__
, "The tag '$tag' is unknown" );
552 * Conviniance function for debugging output
557 * @param string $fname
558 * @param mixed $action
560 function debug( $in, $fname, $action = null ) {
561 $type = gettype( $in );
562 $class = ucfirst( __CLASS__
);
563 if ( $type === 'array' )
564 $in = print_r( $in, true );
566 if ( $action === true )
567 wfDebugLog( $this->log
, "$class::$fname: accepted: '$in' (type: $type)\n");
568 elseif ( $action === false )
569 wfDebugLog( $this->log
, "$class::$fname: rejected: '$in' (type: $type)\n");
570 elseif ( $action === null )
571 wfDebugLog( $this->log
, "$class::$fname: input was: '$in' (type: $type)\n");
573 wfDebugLog( $this->log
, "$class::$fname: $action (type: $type; content: '$in')\n");
577 * Conviniance function for debugging output
581 * @param string $basename The name of the file being processed
582 * @paran string $fname The name of the function calling this function
583 * @param bool $bool $io Specify whether we're beginning or ending
585 function debugFile( $fname, $io ) {
586 $class = ucfirst( __CLASS__
);
588 wfDebugLog( $this->log
, "$class::$fname: begin processing: '{$this->basename}'\n" );
590 wfDebugLog( $this->log
, "$class::$fname: end processing: '{$this->basename}'\n" );
597 * @subpackage Metadata
601 * The Exif data to format
611 * @param array $exif The Exif data to format ( as returned by
612 * Exif::getFilteredData() )
614 function FormatExif( $exif ) {
615 $this->mExif
= $exif;
619 * Numbers given by Exif user agents are often magical, that is they
620 * should be replaced by a detailed explanation depending on their
621 * value which most of the time are plain integers. This function
622 * formats Exif values into human readable form.
626 function getFormattedData() {
629 $tags =& $this->mExif
;
631 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
632 unset( $tags['ResolutionUnit'] );
634 foreach( $tags as $tag => $val ) {
639 $tags[$tag] = $this->msg( $tag, $val );
647 case 'PhotometricInterpretation':
650 $tags[$tag] = $this->msg( $tag, $val );
660 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
661 $tags[$tag] = $this->msg( $tag, $val );
669 case 'PlanarConfiguration':
672 $tags[$tag] = $this->msg( $tag, $val );
680 // TODO: YCbCrSubSampling
681 // TODO: YCbCrPositioning
685 switch( $resolutionunit ) {
687 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
690 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
698 // TODO: YCbCrCoefficients #p27 (see annex E)
699 case 'ExifVersion': case 'FlashpixVersion':
700 $tags[$tag] = "$val"/100;
705 case 1: case 'FFFF.H':
706 $tags[$tag] = $this->msg( $tag, $val );
714 case 'ComponentsConfiguration':
716 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
717 $tags[$tag] = $this->msg( $tag, $val );
726 case 'DateTimeOriginal':
727 case 'DateTimeDigitized':
728 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW
, $val) );
731 case 'ExposureProgram':
733 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
734 $tags[$tag] = $this->msg( $tag, $val );
742 case 'SubjectDistance':
743 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
748 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
749 $tags[$tag] = $this->msg( $tag, $val );
759 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
760 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
761 case 21: case 22: case 23: case 24: case 255:
762 $tags[$tag] = $this->msg( $tag, $val );
771 case 'FocalPlaneResolutionUnit':
774 $tags[$tag] = $this->msg( $tag, $val );
782 case 'SensingMethod':
784 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
785 $tags[$tag] = $this->msg( $tag, $val );
796 $tags[$tag] = $this->msg( $tag, $val );
807 $tags[$tag] = $this->msg( $tag, $val );
815 case 'CustomRendered':
818 $tags[$tag] = $this->msg( $tag, $val );
828 case 0: case 1: case 2:
829 $tags[$tag] = $this->msg( $tag, $val );
840 $tags[$tag] = $this->msg( $tag, $val );
848 case 'SceneCaptureType':
850 case 0: case 1: case 2: case 3:
851 $tags[$tag] = $this->msg( $tag, $val );
861 case 0: case 1: case 2: case 3: case 4:
862 $tags[$tag] = $this->msg( $tag, $val );
872 case 0: case 1: case 2:
873 $tags[$tag] = $this->msg( $tag, $val );
883 case 0: case 1: case 2:
884 $tags[$tag] = $this->msg( $tag, $val );
894 case 0: case 1: case 2:
895 $tags[$tag] = $this->msg( $tag, $val );
903 case 'SubjectDistanceRange':
905 case 0: case 1: case 2: case 3:
906 $tags[$tag] = $this->msg( $tag, $val );
914 case 'GPSLatitudeRef':
915 case 'GPSDestLatitudeRef':
918 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
926 case 'GPSLongitudeRef':
927 case 'GPSDestLongitudeRef':
930 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
941 $tags[$tag] = $this->msg( $tag, $val );
949 case 'GPSMeasureMode':
952 $tags[$tag] = $this->msg( $tag, $val );
961 case 'GPSDestDistanceRef':
963 case 'K': case 'M': case 'N':
964 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
973 case 'GPSImgDirectionRef':
974 case 'GPSDestBearingRef':
977 $tags[$tag] = $this->msg( 'GPSDirection', $val );
986 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
989 // This is not in the Exif standard, just a special
990 // case for our purposes which enables wikis to wikify
991 // the make, model and software name to link to their articles.
995 $tags[$tag] = $this->msg( $tag, '', $val );
999 // Show the pretty fraction as well as decimal version
1000 $tags[$tag] = wfMsg( 'exif-exposuretime-format',
1001 $this->formatFraction( $val ), $this->formatNum( $val ) );
1005 $tags[$tag] = wfMsg( 'exif-fnumber-format',
1006 $this->formatNum( $val ) );
1010 $tags[$tag] = wfMsg( 'exif-focallength-format',
1011 $this->formatNum( $val ) );
1015 $tags[$tag] = $this->formatNum( $val );
1024 * Conviniance function for getFormattedData()
1028 * @param string $tag The tag name to pass on
1029 * @param string $val The value of the tag
1030 * @param string $arg An argument to pass ($1)
1031 * @return string A wfMsg of "exif-$tag-$val" in lower case
1033 function msg( $tag, $val, $arg = null ) {
1038 return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg );
1042 * Format a number, convert numbers from fractions into floating point
1047 * @param mixed $num The value to format
1048 * @return mixed A floating point number or whatever we were fed
1050 function formatNum( $num ) {
1051 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
1052 return $m[2] != 0 ?
$m[1] / $m[2] : $num;
1058 * Format a rational number, reducing fractions
1062 * @param mixed $num The value to format
1063 * @return mixed A floating point number or whatever we were fed
1065 function formatFraction( $num ) {
1066 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
1067 $numerator = intval( $m[1] );
1068 $denominator = intval( $m[2] );
1069 $gcd = $this->gcd( $numerator, $denominator );
1071 // 0 shouldn't happen! ;)
1072 return $numerator / $gcd . '/' . $denominator / $gcd;
1075 return $this->formatNum( $num );
1079 * Calculate the greatest common divisor of two integers.
1086 function gcd( $a, $b ) {
1088 // http://en.wikipedia.org/wiki/Euclidean_algorithm
1089 // Recursive form would be:
1093 return gcd( $b, $a % $b );
1096 $remainder = $a %
$b;
1098 // tail recursion...