ca35606d3c44d15ff4403e4feb19e14bb78c07ad
[lhc/web/wiklou.git] / includes / Exif.php
1 <?php
2 if ( !defined( 'MEDIAWIKI' ) ) die();
3 /**
4 * @package MediaWiki
5 * @subpackage Metadata
6 *
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
10 *
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.
15 *
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.
20 *
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
25 *
26 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
27 * @bug 1555, 1947
28 */
29
30 /**#@+
31 * Exif tag type definition
32 */
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.
41 /**#@-*/
42
43
44 /**
45 * @package MediaWiki
46 * @subpackage Metadata
47 */
48 class Exif {
49 /**#@+
50 * @var array
51 * @access private
52 */
53
54 /**
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.
58 */
59 var $mExifTags;
60
61 /**
62 * A one dimentional array of all Exif tags
63 */
64 var $mFlatExifTags;
65
66 /**
67 * The raw Exif data returned by exif_read_data()
68 */
69 var $mRawExifData;
70
71 /**
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
75 */
76 var $mFilteredExifData;
77
78 /**
79 * Filtered and formatted Exif data, see FormatExif::getFormattedData()
80 */
81 var $mFormattedExifData;
82
83 /**#@-*/
84
85 /**
86 * Constructor
87 */
88 function Exif( $file ) {
89 /**
90 * Page numbers here refer to pages in the EXIF 2.2 standard
91 *
92 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
93 */
94 $this->mExifTags = array(
95 # TIFF Rev. 6.0 Attribute Information (p22)
96 'tiff' => array(
97 # Tags relating to image structure
98 'structure' => array(
99 'ImageWidth' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Image width
100 'ImageLength' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Image height
101 'BitsPerSample' => MW_EXIF_SHORT, # Number of bits per component
102 # "When a primary image is JPEG compressed, this designation is not"
103 # "necessary and is omitted." (p23)
104 'Compression' => MW_EXIF_SHORT, # Compression scheme #p23
105 'PhotometricInterpretation' => MW_EXIF_SHORT, # Pixel composition #p23
106 'Orientation' => MW_EXIF_SHORT, # Orientation of image #p24
107 'SamplesPerPixel' => MW_EXIF_SHORT, # Number of components
108 'PlanarConfiguration' => MW_EXIF_SHORT, # Image data arrangement #p24
109 'YCbCrSubSampling' => MW_EXIF_SHORT, # Subsampling ratio of Y to C #p24
110 'YCbCrPositioning' => MW_EXIF_SHORT, # Y and C positioning #p24-25
111 'XResolution' => MW_EXIF_RATIONAL, # Image resolution in width direction
112 'YResolution' => MW_EXIF_RATIONAL, # Image resolution in height direction
113 'ResolutionUnit' => MW_EXIF_SHORT, # Unit of X and Y resolution #(p26)
114 ),
115
116 # Tags relating to recording offset
117 'offset' => array(
118 'StripOffsets' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Image data location
119 'RowsPerStrip' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Number of rows per strip
120 'StripByteCounts' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Bytes per compressed strip
121 'JPEGInterchangeFormat' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Offset to JPEG SOI
122 'JPEGInterchangeFormatLength' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Bytes of JPEG data
123 ),
124
125 # Tags relating to image data characteristics
126 'characteristics' => array(
127 'TransferFunction' => MW_EXIF_SHORT, # Transfer function
128 'WhitePoint' => MW_EXIF_RATIONAL, # White point chromaticity
129 'PrimaryChromaticities' => MW_EXIF_RATIONAL, # Chromaticities of primarities
130 'YCbCrCoefficients' => MW_EXIF_RATIONAL, # Color space transformation matrix coefficients #p27
131 'ReferenceBlackWhite' => MW_EXIF_RATIONAL # Pair of black and white reference values
132 ),
133
134 # Other tags
135 'other' => array(
136 'DateTime' => MW_EXIF_ASCII, # File change date and time
137 'ImageDescription' => MW_EXIF_ASCII, # Image title
138 'Make' => MW_EXIF_ASCII, # Image input equipment manufacturer
139 'Model' => MW_EXIF_ASCII, # Image input equipment model
140 'Software' => MW_EXIF_ASCII, # Software used
141 'Artist' => MW_EXIF_ASCII, # Person who created the image
142 'Copyright' => MW_EXIF_ASCII, # Copyright holder
143 ),
144 ),
145
146 # Exif IFD Attribute Information (p30-31)
147 'exif' => array(
148 # Tags relating to version
149 'version' => array(
150 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
151 # to the EXIF 2.1 AND 2.2 standards
152 'ExifVersion' => MW_EXIF_UNDEFINED, # Exif version
153 'FlashpixVersion' => MW_EXIF_UNDEFINED, # Supported Flashpix version #p32
154 ),
155
156 # Tags relating to Image Data Characteristics
157 'characteristics' => array(
158 'ColorSpace' => MW_EXIF_SHORT, # Color space information #p32
159 ),
160
161 # Tags relating to image configuration
162 'configuration' => array(
163 'ComponentsConfiguration' => MW_EXIF_UNDEFINED, # Meaning of each component #p33
164 'CompressedBitsPerPixel' => MW_EXIF_RATIONAL, # Image compression mode
165 'PixelYDimension' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Valid image width
166 'PixelXDimension' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Valind image height
167 ),
168
169 # Tags relating to related user information
170 'user' => array(
171 'MakerNote' => MW_EXIF_UNDEFINED, # Manufacturer notes
172 'UserComment' => MW_EXIF_UNDEFINED, # User comments #p34
173 ),
174
175 # Tags relating to related file information
176 'related' => array(
177 'RelatedSoundFile' => MW_EXIF_ASCII, # Related audio file
178 ),
179
180 # Tags relating to date and time
181 'dateandtime' => array(
182 'DateTimeOriginal' => MW_EXIF_ASCII, # Date and time of original data generation #p36
183 'DateTimeDigitized' => MW_EXIF_ASCII, # Date and time of original data generation
184 'SubSecTime' => MW_EXIF_ASCII, # DateTime subseconds
185 'SubSecTimeOriginal' => MW_EXIF_ASCII, # DateTimeOriginal subseconds
186 'SubSecTimeDigitized' => MW_EXIF_ASCII, # DateTimeDigitized subseconds
187 ),
188
189 # Tags relating to picture-taking conditions (p31)
190 'conditions' => array(
191 'ExposureTime' => MW_EXIF_RATIONAL, # Exposure time
192 'FNumber' => MW_EXIF_RATIONAL, # F Number
193 'ExposureProgram' => MW_EXIF_SHORT, # Exposure Program #p38
194 'SpectralSensitivity' => MW_EXIF_ASCII, # Spectral sensitivity
195 'ISOSpeedRatings' => MW_EXIF_SHORT, # ISO speed rating
196 'OECF' => MW_EXIF_UNDEFINED, # Optoelectronic conversion factor
197 'ShutterSpeedValue' => MW_EXIF_SRATIONAL, # Shutter speed
198 'ApertureValue' => MW_EXIF_RATIONAL, # Aperture
199 'BrightnessValue' => MW_EXIF_SRATIONAL, # Brightness
200 'ExposureBiasValue' => MW_EXIF_SRATIONAL, # Exposure bias
201 'MaxApertureValue' => MW_EXIF_RATIONAL, # Maximum land aperture
202 'SubjectDistance' => MW_EXIF_RATIONAL, # Subject distance
203 'MeteringMode' => MW_EXIF_SHORT, # Metering mode #p40
204 'LightSource' => MW_EXIF_SHORT, # Light source #p40-41
205 'Flash' => MW_EXIF_SHORT, # Flash #p41-42
206 'FocalLength' => MW_EXIF_RATIONAL, # Lens focal length
207 'SubjectArea' => MW_EXIF_SHORT, # Subject area
208 'FlashEnergy' => MW_EXIF_RATIONAL, # Flash energy
209 'SpatialFrequencyResponse' => MW_EXIF_UNDEFINED, # Spatial frequency response
210 'FocalPlaneXResolution' => MW_EXIF_RATIONAL, # Focal plane X resolution
211 'FocalPlaneYResolution' => MW_EXIF_RATIONAL, # Focal plane Y resolution
212 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT, # Focal plane resolution unit
213 'SubjectLocation' => MW_EXIF_SHORT, # Subject location
214 'ExposureIndex' => MW_EXIF_RATIONAL, # Exposure index
215 'SensingMethod' => MW_EXIF_SHORT, # Sensing method #p46
216 'FileSource' => MW_EXIF_UNDEFINED, # File source #p47
217 'SceneType' => MW_EXIF_UNDEFINED, # Scene type #p47
218 'CFAPattern' => MW_EXIF_UNDEFINED, # CFA pattern
219 'CustomRendered' => MW_EXIF_SHORT, # Custom image processing #p48
220 'ExposureMode' => MW_EXIF_SHORT, # Exposure mode #p48
221 'WhiteBalance' => MW_EXIF_SHORT, # White Balance #p49
222 'DigitalZoomRatio' => MW_EXIF_RATIONAL, # Digital zoom ration
223 'FocalLengthIn35mmFilm' => MW_EXIF_SHORT, # Focal length in 35 mm film
224 'SceneCaptureType' => MW_EXIF_SHORT, # Scene capture type #p49
225 'GainControl' => MW_EXIF_RATIONAL, # Scene control #p49-50
226 'Contrast' => MW_EXIF_SHORT, # Contrast #p50
227 'Saturation' => MW_EXIF_SHORT, # Saturation #p50
228 'Sharpness' => MW_EXIF_SHORT, # Sharpness #p50
229 'DeviceSettingDescription' => MW_EXIF_UNDEFINED, # Desice settings description
230 'SubjectDistanceRange' => MW_EXIF_SHORT, # Subject distance range #p51
231 ),
232
233 'other' => array(
234 'ImageUniqueID' => MW_EXIF_ASCII, # Unique image ID
235 ),
236 ),
237
238 # GPS Attribute Information (p52)
239 'gps' => array(
240 'GPSVersionID' => MW_EXIF_BYTE, # GPS tag version
241 'GPSLatitudeRef' => MW_EXIF_ASCII, # North or South Latitude #p52-53
242 'GPSLatitude' => MW_EXIF_RATIONAL, # Latitude
243 'GPSLongitudeRef' => MW_EXIF_ASCII, # East or West Longitude #p53
244 'GPSLongitude' => MW_EXIF_RATIONAL, # Longitude
245 'GPSAltitudeRef' => MW_EXIF_BYTE, # Altitude reference
246 'GPSAltitude' => MW_EXIF_RATIONAL, # Altitude
247 'GPSTimeStamp' => MW_EXIF_RATIONAL, # GPS time (atomic clock)
248 'GPSSatellites' => MW_EXIF_ASCII, # Satellites used for measurement
249 'GPSStatus' => MW_EXIF_ASCII, # Receiver status #p54
250 'GPSMeasureMode' => MW_EXIF_ASCII, # Measurement mode #p54-55
251 'GPSDOP' => MW_EXIF_RATIONAL, # Measurement precision
252 'GPSSpeedRef' => MW_EXIF_ASCII, # Speed unit #p55
253 'GPSSpeed' => MW_EXIF_RATIONAL, # Speed of GPS receiver
254 'GPSTrackRef' => MW_EXIF_ASCII, # Reference for direction of movement #p55
255 'GPSTrack' => MW_EXIF_RATIONAL, # Direction of movement
256 'GPSImgDirectionRef' => MW_EXIF_ASCII, # Reference for direction of image #p56
257 'GPSImgDirection' => MW_EXIF_RATIONAL, # Direction of image
258 'GPSMapDatum' => MW_EXIF_ASCII, # Geodetic survey data used
259 'GPSDestLatitudeRef' => MW_EXIF_ASCII, # Reference for latitude of destination #p56
260 'GPSDestLatitude' => MW_EXIF_RATIONAL, # Latitude destination
261 'GPSDestLongitudeRef' => MW_EXIF_ASCII, # Reference for longitude of destination #p57
262 'GPSDestLongitude' => MW_EXIF_RATIONAL, # Longitude of destination
263 'GPSDestBearingRef' => MW_EXIF_ASCII, # Reference for bearing of destination #p57
264 'GPSDestBearing' => MW_EXIF_RATIONAL, # Bearing of destination
265 'GPSDestDistanceRef' => MW_EXIF_ASCII, # Reference for distance to destination #p57-58
266 'GPSDestDistance' => MW_EXIF_RATIONAL, # Distance to destination
267 'GPSProcessingMethod' => MW_EXIF_UNDEFINED, # Name of GPS processing method
268 'GPSAreaInformation' => MW_EXIF_UNDEFINED, # Name of GPS area
269 'GPSDateStamp' => MW_EXIF_ASCII, # GPS date
270 'GPSDifferential' => MW_EXIF_SHORT, # GPS differential correction
271 ),
272 );
273
274 $this->makeFlatExifTags();
275 wfSuppressWarnings();
276 $this->mRawExifData = exif_read_data( $file );
277 wfRestoreWarnings();
278 $this->makeFilteredData();
279 $this->makeFormattedData();
280 }
281
282 /**#@+
283 * @access private
284 */
285 /**
286 * Generate a flat list of the exif tags
287 */
288 function makeFlatExifTags() {
289 $this->extractTags( $this->mExifTags );
290 }
291
292 /**
293 * A recursing extractor function used by makeFlatExifTags()
294 *
295 * Note: This used to use an array_walk function, but it made PHP5
296 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
297 */
298 function extractTags( &$tagset ) {
299 foreach( $tagset as $key => $val ) {
300 if( is_array( $val ) ) {
301 $this->extractTags( $val );
302 } else {
303 $this->mFlatExifTags[$key] = $val;
304 }
305 }
306 }
307
308 /**#@-*/
309
310 /**
311 * Make $this->mFilteredExifData
312 */
313 function makeFilteredData() {
314 $this->mFilteredExifData = $this->mRawExifData;
315
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] );
320 }
321 }
322
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] );
327 }
328 }
329 }
330
331 function makeFormattedData( $data = null ) {
332 $format = new FormatExif( $this->getFilteredData() );
333 $this->mFormattedExifData = $format->getFormattedData();
334 }
335 /**#@-*/
336
337 /**#@+
338 * @return array
339 */
340 /**
341 * Get $this->mRawExifData
342 */
343 function getData() {
344 return $this->mRawExifData;
345 }
346
347 /**
348 * Get $this->mFilteredExifData
349 */
350 function getFilteredData() {
351 return $this->mFilteredExifData;
352 }
353
354 /**
355 * Get $this->mFormattedExifData
356 */
357 function getFormattedData() {
358 return $this->mFormattedExifData;
359 }
360 /**#@-*/
361
362 /**
363 * The version of the output format
364 *
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.
371 *
372 * @return int
373 */
374 function version() {
375 return 1; // We don't need no bloddy constants!
376 }
377
378 /**#@+
379 * Validates if a tag value is of the type it should be according to the Exif spec
380 *
381 * @param mixed $in The input value to check
382 * @return bool
383 */
384 function isByte( $in ) {
385 if ( sprintf('%d', $in) === $in && $in >= 0 && $in <= 255 ) {
386 $this->debug( $in, __FUNCTION__, true );
387 return true;
388 } else {
389 $this->debug( $in, __FUNCTION__, false );
390 return false;
391 }
392 }
393
394 function isASCII( $in ) {
395 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
396 $this->debug( $in, __FUNCTION__, 'found a character not in our whitelist' );
397 return false;
398 }
399
400 if ( preg_match( "/^\s*$/", $in ) ) {
401 $this->debug( $in, __FUNCTION__, 'input consisted solely of whitespace' );
402 return false;
403 }
404
405 if ( strlen($in) > 1024 ) { // TODO: This might not be according to the spec
406 $this->debug( $in, __FUNCTION__, 'input was too long' );
407 return false;
408 }
409
410 return true;
411 }
412
413 function isShort( $in ) {
414 if ( sprintf('%d', $in) === $in && $in >= 0 && $in <= 65536 ) {
415 $this->debug( $in, __FUNCTION__, true );
416 return true;
417 } else {
418 $this->debug( $in, __FUNCTION__, true );
419 return false;
420 }
421 }
422
423 function isLong( $in ) {
424 if ( sprintf('%d', $in) === $in && $in >= 0 && $in <= 4294967296 ) {
425 $this->debug( $in, __FUNCTION__, true );
426 return true;
427 } else {
428 $this->debug( $in, __FUNCTION__, false );
429 return false;
430 }
431 }
432
433 function isRational( $in ) {
434 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
435 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
436 } else {
437 $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
438 return false;
439 }
440 }
441
442 function isUndefined( $in ) {
443 $this->debug( $in, __FUNCTION__ );
444 if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
445 return true;
446 } else {
447 return false;
448 }
449 }
450
451 function isSlong( $in ) {
452 if ( $this->isLong( abs( $in ) ) ) {
453 $this->debug( $in, __FUNCTION__, true );
454 return true;
455 } else {
456 $this->debug( $in, __FUNCTION__, false );
457 return false;
458 }
459 }
460
461 function isSrational( $in ) {
462 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
463 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
464 } else {
465 $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
466 return false;
467 }
468 }
469 /**#@-*/
470
471 /**
472 * Validates if a tag has a legal value according to the Exif spec
473 *
474 * @param string $tag The tag to check
475 * @param mixed $val The value of the tag
476 * @return bool
477 */
478 function validate( $tag, $val ) {
479 // Fucks up if not typecast
480 switch( (string)$this->mFlatExifTags[$tag] ) {
481 case (string)MW_EXIF_BYTE:
482 return $this->isByte( $val );
483 case (string)MW_EXIF_ASCII:
484 return $this->isASCII( $val );
485 case (string)MW_EXIF_SHORT:
486 return $this->isShort( $val );
487 case (string)MW_EXIF_LONG:
488 return $this->isLong( $val );
489 case (string)MW_EXIF_RATIONAL:
490 return $this->isRational( $val );
491 case (string)MW_EXIF_UNDEFINED:
492 return $this->isUndefined( $val );
493 case (string)MW_EXIF_SLONG:
494 return $this->isSlong( $val );
495 case (string)MW_EXIF_SRATIONAL:
496 return $this->isSrational( $val );
497 case (string)MW_EXIF_SHORT.','.MW_EXIF_LONG:
498 return $this->isShort( $val ) || $this->isLong( $val );
499 default:
500 wfDebug( ucfirst( __CLASS__ ) . '::' . __FUNCTION__ .
501 ": The tag '$tag' in unknown (type: " . gettype( $val ) . "; content: '$val')\n" );
502 return false;
503 }
504 }
505
506 /**
507 * Conviniance function for debugging output
508 *
509 * @param mixed $in
510 * @param string $fname
511 * @param mixed $action
512 */
513 function debug( $in, $fname, $action = null ) {
514 $type = gettype( $in );
515 $class = ucfirst( __CLASS__ );
516 if ( $type === 'array' )
517 $in = print_r( $in, true );
518
519 if ( $action === true )
520 wfDebug( "$class::$fname: accepted: '$in' (type: $type)\n");
521 elseif ( $action === false )
522 wfDebug( "$class::$fname: rejected: '$in' (type: $type)\n");
523 elseif ( $action === null )
524 wfDebug( "$class::$fname: input was: '$in' (type: $type)\n");
525 else
526 wfDebug( "$class::$fname: $action (type: $type; content: '$in')\n");
527 }
528
529 }
530
531 /**
532 * @package MediaWiki
533 * @subpackage Metadata
534 */
535 class FormatExif {
536 /**
537 * The Exif data to format
538 *
539 * @var array
540 * @access private
541 */
542 var $mExif;
543
544 /**
545 * Constructor
546 *
547 * @param array $exif The Exif data to format ( as returned by
548 * Exif::getFilteredData() )
549 */
550 function FormatExif( $exif ) {
551 $this->mExif = $exif;
552 }
553
554 /**
555 * Numbers given by Exif user agents are often magical, that is they
556 * should be replaced by a detailed explanation depending on their
557 * value which most of the time are plain integers. This function
558 * formats Exif values into human readable form.
559 *
560 * @return array
561 */
562 function getFormattedData() {
563 global $wgLang;
564
565 $tags =& $this->mExif;
566
567 foreach( $tags as $tag => $val ) {
568 switch( $tag ) {
569 case 'Compression':
570 switch( $val ) {
571 case 1: case 6:
572 $tags[$tag] = $this->msg( $tag, $val );
573 break;
574 default:
575 $tags[$tag] = $val;
576 break;
577 }
578
579 case 'PhotometricInterpretation':
580 switch( $val ) {
581 case 2: case 6:
582 $tags[$tag] = $this->msg( $tag, $val );
583 break;
584 default:
585 $tags[$tag] = $val;
586 break;
587 }
588
589 case 'Orientation':
590 switch( $val ) {
591 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
592 $tags[$tag] = $this->msg( $tag, $val );
593 break;
594 default:
595 $tags[$tag] = $val;
596 break;
597 }
598
599 case 'PlanarConfiguration':
600 switch( $val ) {
601 case 1: case 2:
602 $tags[$tag] = $this->msg( $tag, $val );
603 break;
604 default:
605 $tags[$tag] = $val;
606 break;
607 }
608
609 // TODO: YCbCrSubSampling
610 // TODO: YCbCrPositioning
611 // TODO: If this field does not exists use 2
612 case 'ResolutionUnit': #p26
613 switch( $val ) {
614 case 2: case 3:
615 $tags[$tag] = $this->msg( $tag, $val );
616 break;
617 default:
618 $tags[$tag] = $val;
619 break;
620 }
621
622 // TODO: YCbCrCoefficients #p27 (see annex E)
623 case 'ExifVersion': case 'FlashpixVersion':
624 $tags[$tag] = "$val"/100;
625 break;
626
627 case 'ColorSpace':
628 switch( $val ) {
629 case 1: case 'FFFF.H':
630 $tags[$tag] = $this->msg( $tag, $val );
631 break;
632 default:
633 $tags[$tag] = $val;
634 break;
635 }
636
637 case 'ComponentsConfiguration':
638 switch( $val ) {
639 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
640 $tags[$tag] = $this->msg( $tag, $val );
641 break;
642 default:
643 $tags[$tag] = $val;
644 break;
645 }
646
647 case 'DateTime':
648 case 'DateTimeOriginal':
649 case 'DateTimeDigitized':
650 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW, $val) );
651 break;
652
653 case 'ExposureProgram':
654 switch( $val ) {
655 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
656 $tags[$tag] = $this->msg( $tag, $val );
657 break;
658 default:
659 $tags[$tag] = $val;
660 break;
661 }
662
663 case 'MeteringMode':
664 switch( $val ) {
665 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
666 $tags[$tag] = $this->msg( $tag, $val );
667 break;
668 default:
669 $tags[$tag] = $val;
670 break;
671 }
672
673 case 'LightSource':
674 switch( $val ) {
675 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
676 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
677 case 21: case 22: case 23: case 24: case 255:
678 $tags[$tag] = $this->msg( $tag, $val );
679 break;
680 default:
681 $tags[$tag] = $val;
682 break;
683 }
684
685 // TODO: Flash
686 case 'SensingMethod':
687 switch( $val ) {
688 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
689 $tags[$tag] = $this->msg( $tag, $val );
690 break;
691 default:
692 $tags[$tag] = $val;
693 break;
694 }
695
696 case 'FileSource':
697 switch( $val ) {
698 case 3:
699 $tags[$tag] = $this->msg( $tag, $val );
700 break;
701 default:
702 $tags[$tag] = $val;
703 break;
704 }
705
706 case 'SceneType':
707 switch( $val ) {
708 case 1:
709 $tags[$tag] = $this->msg( $tag, $val );
710 break;
711 default:
712 $tags[$tag] = $val;
713 break;
714 }
715
716 case 'CustomRendered':
717 switch( $val ) {
718 case 0: case 1:
719 $tags[$tag] = $this->msg( $tag, $val );
720 break;
721 default:
722 $tags[$tag] = $val;
723 break;
724 }
725
726 case 'ExposureMode':
727 switch( $val ) {
728 case 0: case 1: case 2:
729 $tags[$tag] = $this->msg( $tag, $val );
730 break;
731 default:
732 $tags[$tag] = $val;
733 break;
734 }
735
736 case 'WhiteBalance':
737 switch( $val ) {
738 case 0: case 1:
739 $tags[$tag] = $this->msg( $tag, $val );
740 break;
741 default:
742 $tags[$tag] = $val;
743 break;
744 }
745
746 case 'SceneCaptureType':
747 switch( $val ) {
748 case 0: case 1: case 2: case 3:
749 $tags[$tag] = $this->msg( $tag, $val );
750 break;
751 default:
752 $tags[$tag] = $val;
753 break;
754 }
755
756 case 'GainControl':
757 switch( $val ) {
758 case 0: case 1: case 2: case 3: case 4:
759 $tags[$tag] = $this->msg( $tag, $val );
760 break;
761 default:
762 $tags[$tag] = $val;
763 break;
764 }
765
766 case 'Contrast':
767 switch( $val ) {
768 case 0: case 1: case 2:
769 $tags[$tag] = $this->msg( $tag, $val );
770 break;
771 default:
772 $tags[$tag] = $val;
773 break;
774 }
775
776 case 'Saturation':
777 switch( $val ) {
778 case 0: case 1: case 2:
779 $tags[$tag] = $this->msg( $tag, $val );
780 break;
781 default:
782 $tags[$tag] = $val;
783 break;
784 }
785
786 case 'Sharpness':
787 switch( $val ) {
788 case 0: case 1: case 2:
789 $tags[$tag] = $this->msg( $tag, $val );
790 break;
791 default:
792 $tags[$tag] = $val;
793 break;
794 }
795
796 case 'SubjectDistanceRange':
797 switch( $val ) {
798 case 0: case 1: case 2: case 3:
799 $tags[$tag] = $this->msg( $tag, $val );
800 break;
801 default:
802 $tags[$tag] = $val;
803 break;
804 }
805
806 case 'GPSLatitudeRef':
807 case 'GPSDestLatitudeRef':
808 switch( $val ) {
809 case 'N': case 'S':
810 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
811 break;
812 default:
813 $tags[$tag] = $val;
814 break;
815 }
816
817 case 'GPSLongitudeRef':
818 case 'GPSDestLongitudeRef':
819 switch( $val ) {
820 case 'E': case 'W':
821 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
822 break;
823 default:
824 $tags[$tag] = $val;
825 break;
826 }
827
828 case 'GPSStatus':
829 switch( $val ) {
830 case 'A': case 'V':
831 $tags[$tag] = $this->msg( $tag, $val );
832 break;
833 default:
834 $tags[$tag] = $val;
835 break;
836 }
837
838 case 'GPSMeasureMode':
839 switch( $val ) {
840 case 2: case 3:
841 $tags[$tag] = $this->msg( $tag, $val );
842 break;
843 default:
844 $tags[$tag] = $val;
845 break;
846 }
847
848 case 'GPSSpeedRef':
849 case 'GPSDestDistanceRef':
850 switch( $val ) {
851 case 'K': case 'M': case 'N':
852 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
853 break;
854 default:
855 $tags[$tag] = $val;
856 break;
857 }
858
859 case 'GPSTrackRef':
860 case 'GPSImgDirectionRef':
861 case 'GPSDestBearingRef':
862 switch( $val ) {
863 case 'T': case 'M':
864 $tags[$tag] = $this->msg( 'GPSDirection', $val );
865 break;
866 default:
867 $tags[$tag] = $val;
868 break;
869 }
870
871 case 'GPSDateStamp':
872 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
873 break;
874
875 // This is not in the Exif standard, just a special
876 // case for our purposes which enables wikis to wikify
877 // the make, model and software name to link to their articles.
878 case 'Make':
879 case 'Model':
880 case 'Software':
881 $tags[$tag] = wfMsg( strtolower( "exif-$tag-value" ), $val );
882 break;
883 default:
884 if ( preg_match( '/^(\d+)\/(\d+)$/', $val, $m ) ) {
885 $tags[$tag] = $m[2] != 0 ? $m[1]/$m[2] : $val;
886 break;
887 }
888 $tags[$tag] = $val;
889 break;
890 }
891 }
892
893 return $tags;
894 }
895
896 /**
897 * Conviniance function for format()
898 *
899 * @param string $tag The tag name to pass on
900 * @param string $val The value of the tag
901 * @return string A wfMsg of "exif-$tag-$val" in lower case
902 */
903 function msg( $tag, $val ) {
904 return wfMsg( strtolower("exif-$tag-$val") );
905 }
906 }