* Improved the debug output of the type checking functions
[lhc/web/wiklou.git] / includes / Exif.php
1 <?php
2 if (defined('MEDIAWIKI')) {
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 */
52
53 /**
54 * Exif tags grouped by category, the tagname itself is the key and the type
55 * is the value, in the case of more than one possible value type they are
56 * seperated by commas.
57 *
58 * @access private
59 */
60 var $mExif;
61
62 /**
63 * A one dimentional array of all Exif tags
64 */
65 var $mFlatExif;
66
67 /**
68 * A one dimentional array of all Exif tags that we'd want to save in
69 * the database or present on a page.
70 */
71 var $mValidExif;
72
73 /**#@-*/
74
75 /**
76 * Constructor
77 */
78 function Exif() {
79 /**
80 * Page numbers here refer to pages in the EXIF 2.2 standard
81 *
82 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
83 */
84 $this->mExif = array(
85 # TIFF Rev. 6.0 Attribute Information (p22)
86 'tiff' => array(
87 # Tags relating to image structure
88 'structure' => array(
89 'ImageWidth' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Image width
90 'ImageLength' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Image height
91 'BitsPerSample' => MW_EXIF_SHORT, # Number of bits per component
92 # "When a primary image is JPEG compressed, this designation is not"
93 # "necessary and is omitted." (p23)
94 'Compression' => MW_EXIF_SHORT, # Compression scheme #p23
95 'PhotometricInterpretation' => MW_EXIF_SHORT, # Pixel composition #p23
96 'Orientation' => MW_EXIF_SHORT, # Orientation of image #p24
97 'SamplesPerPixel' => MW_EXIF_SHORT, # Number of components
98 'PlanarConfiguration' => MW_EXIF_SHORT, # Image data arrangement #p24
99 'YCbCrSubSampling' => MW_EXIF_SHORT, # Subsampling ratio of Y to C #p24
100 'YCbCrPositioning' => MW_EXIF_SHORT, # Y and C positioning #p24-25
101 'XResolution' => MW_EXIF_RATIONAL, # Image resolution in width direction
102 'YResolution' => MW_EXIF_RATIONAL, # Image resolution in height direction
103 'ResolutionUnit' => MW_EXIF_SHORT, # Unit of X and Y resolution #(p26)
104 ),
105
106 # Tags relating to recording offset
107 'offset' => array(
108 'StripOffsets' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Image data location
109 'RowsPerStrip' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Number of rows per strip
110 'StripByteCounts' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Bytes per compressed strip
111 'JPEGInterchangeFormat' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Offset to JPEG SOI
112 'JPEGInterchangeFormatLength' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Bytes of JPEG data
113 ),
114
115 # Tags relating to image data characteristics
116 'characteristics' => array(
117 'TransferFunction' => MW_EXIF_SHORT, # Transfer function
118 'WhitePoint' => MW_EXIF_RATIONAL, # White point chromaticity
119 'PrimaryChromaticities' => MW_EXIF_RATIONAL, # Chromaticities of primarities
120 'YCbCrCoefficients' => MW_EXIF_RATIONAL, # Color space transformation matrix coefficients #p27
121 'ReferenceBlackWhite' => MW_EXIF_RATIONAL # Pair of black and white reference values
122 ),
123
124 # Other tags
125 'other' => array(
126 'DateTime' => MW_EXIF_ASCII, # File change date and time
127 'ImageDescription' => MW_EXIF_ASCII, # Image title
128 'Make' => MW_EXIF_ASCII, # Image input equipment manufacturer
129 'Model' => MW_EXIF_ASCII, # Image input equipment model
130 'Software' => MW_EXIF_ASCII, # Software used
131 'Artist' => MW_EXIF_ASCII, # Person who created the image
132 'Copyright' => MW_EXIF_ASCII, # Copyright holder
133 ),
134 ),
135
136 # Exif IFD Attribute Information (p30-31)
137 'exif' => array(
138 # Tags relating to version
139 'version' => array(
140 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
141 # to the EXIF 2.1 AND 2.2 standards
142 'ExifVersion' => MW_EXIF_UNDEFINED, # Exif version
143 'FlashpixVersion' => MW_EXIF_UNDEFINED, # Supported Flashpix version #p32
144 ),
145
146 # Tags relating to Image Data Characteristics
147 'characteristics' => array(
148 'ColorSpace' => MW_EXIF_SHORT, # Color space information #p32
149 ),
150
151 # Tags relating to image configuration
152 'configuration' => array(
153 'ComponentsConfiguration' => MW_EXIF_UNDEFINED, # Meaning of each component #p33
154 'CompressedBitsPerPixel' => MW_EXIF_RATIONAL, # Image compression mode
155 'PixelYDimension' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Valid image width
156 'PixelXDimension' => MW_EXIF_SHORT.','.MW_EXIF_LONG, # Valind image height
157 ),
158
159 # Tags relating to related user information
160 'user' => array(
161 'MakerNote' => MW_EXIF_UNDEFINED, # Manufacturer notes
162 'UserComment' => MW_EXIF_UNDEFINED, # User comments #p34
163 ),
164
165 # Tags relating to related file information
166 'related' => array(
167 'RelatedSoundFile' => MW_EXIF_ASCII, # Related audio file
168 ),
169
170 # Tags relating to date and time
171 'dateandtime' => array(
172 'DateTimeOriginal' => MW_EXIF_ASCII, # Date and time of original data generation #p36
173 'DateTimeDigitized' => MW_EXIF_ASCII, # Date and time of original data generation
174 'SubSecTime' => MW_EXIF_ASCII, # DateTime subseconds
175 'SubSecTimeOriginal' => MW_EXIF_ASCII, # DateTimeOriginal subseconds
176 'SubSecTimeDigitized' => MW_EXIF_ASCII, # DateTimeDigitized subseconds
177 ),
178
179 # Tags relating to picture-taking conditions (p31)
180 'conditions' => array(
181 'ExposureTime' => MW_EXIF_RATIONAL, # Exposure time
182 'FNumber' => MW_EXIF_RATIONAL, # F Number
183 'ExposureProgram' => MW_EXIF_SHORT, # Exposure Program #p38
184 'SpectralSensitivity' => MW_EXIF_ASCII, # Spectral sensitivity
185 'ISOSpeedRatings' => MW_EXIF_SHORT, # ISO speed rating
186 'OECF' => MW_EXIF_UNDEFINED, # Optoelectronic conversion factor
187 'ShutterSpeedValue' => MW_EXIF_SRATIONAL, # Shutter speed
188 'ApertureValue' => MW_EXIF_RATIONAL, # Aperture
189 'BrightnessValue' => MW_EXIF_SRATIONAL, # Brightness
190 'ExposureBiasValue' => MW_EXIF_SRATIONAL, # Exposure bias
191 'MaxApertureValue' => MW_EXIF_RATIONAL, # Maximum land aperture
192 'SubjectDistance' => MW_EXIF_RATIONAL, # Subject distance
193 'MeteringMode' => MW_EXIF_SHORT, # Metering mode #p40
194 'LightSource' => MW_EXIF_SHORT, # Light source #p40-41
195 'Flash' => MW_EXIF_SHORT, # Flash #p41-42
196 'FocalLength' => MW_EXIF_RATIONAL, # Lens focal length
197 'SubjectArea' => MW_EXIF_SHORT, # Subject area
198 'FlashEnergy' => MW_EXIF_RATIONAL, # Flash energy
199 'SpatialFrequencyResponse' => MW_EXIF_UNDEFINED, # Spatial frequency response
200 'FocalPlaneXResolution' => MW_EXIF_RATIONAL, # Focal plane X resolution
201 'FocalPlaneYResolution' => MW_EXIF_RATIONAL, # Focal plane Y resolution
202 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT, # Focal plane resolution unit
203 'SubjectLocation' => MW_EXIF_SHORT, # Subject location
204 'ExposureIndex' => MW_EXIF_RATIONAL, # Exposure index
205 'SensingMethod' => MW_EXIF_SHORT, # Sensing method #p46
206 'FileSource' => MW_EXIF_UNDEFINED, # File source #p47
207 'SceneType' => MW_EXIF_UNDEFINED, # Scene type #p47
208 'CFAPattern' => MW_EXIF_UNDEFINED, # CFA pattern
209 'CustomRendered' => MW_EXIF_SHORT, # Custom image processing #p48
210 'ExposureMode' => MW_EXIF_SHORT, # Exposure mode #p48
211 'WhiteBalance' => MW_EXIF_SHORT, # White Balance #p49
212 'DigitalZoomRatio' => MW_EXIF_RATIONAL, # Digital zoom ration
213 'FocalLengthIn35mmFilm' => MW_EXIF_SHORT, # Focal length in 35 mm film
214 'SceneCaptureType' => MW_EXIF_SHORT, # Scene capture type #p49
215 'GainControl' => MW_EXIF_RATIONAL, # Scene control #p49-50
216 'Contrast' => MW_EXIF_SHORT, # Contrast #p50
217 'Saturation' => MW_EXIF_SHORT, # Saturation #p50
218 'Sharpness' => MW_EXIF_SHORT, # Sharpness #p50
219 'DeviceSettingDescription' => MW_EXIF_UNDEFINED, # Desice settings description
220 'SubjectDistanceRange' => MW_EXIF_SHORT, # Subject distance range #p51
221 ),
222
223 'other' => array(
224 'ImageUniqueID' => MW_EXIF_ASCII, # Unique image ID
225 ),
226 ),
227
228 # GPS Attribute Information (p52)
229 'gps' => array(
230 'GPSVersionID' => MW_EXIF_BYTE, # GPS tag version
231 'GPSLatitudeRef' => MW_EXIF_ASCII, # North or South Latitude #p52-53
232 'GPSLatitude' => MW_EXIF_RATIONAL, # Latitude
233 'GPSLongitudeRef' => MW_EXIF_ASCII, # East or West Longitude #p53
234 'GPSLongitude' => MW_EXIF_RATIONAL, # Longitude
235 'GPSAltitudeRef' => MW_EXIF_BYTE, # Altitude reference
236 'GPSAltitude' => MW_EXIF_RATIONAL, # Altitude
237 'GPSTimeStamp' => MW_EXIF_RATIONAL, # GPS time (atomic clock)
238 'GPSSatellites' => MW_EXIF_ASCII, # Satellites used for measurement
239 'GPSStatus' => MW_EXIF_ASCII, # Receiver status #p54
240 'GPSMeasureMode' => MW_EXIF_ASCII, # Measurement mode #p54-55
241 'GPSDOP' => MW_EXIF_RATIONAL, # Measurement precision
242 'GPSSpeedRef' => MW_EXIF_ASCII, # Speed unit #p55
243 'GPSSpeed' => MW_EXIF_RATIONAL, # Speed of GPS receiver
244 'GPSTrackRef' => MW_EXIF_ASCII, # Reference for direction of movement #p55
245 'GPSTrack' => MW_EXIF_RATIONAL, # Direction of movement
246 'GPSImgDirectionRef' => MW_EXIF_ASCII, # Reference for direction of image #p56
247 'GPSImgDirection' => MW_EXIF_RATIONAL, # Direction of image
248 'GPSMapDatum' => MW_EXIF_ASCII, # Geodetic survey data used
249 'GPSDestLatitudeRef' => MW_EXIF_ASCII, # Reference for latitude of destination #p56
250 'GPSDestLatitude' => MW_EXIF_RATIONAL, # Latitude destination
251 'GPSDestLongitudeRef' => MW_EXIF_ASCII, # Reference for longitude of destination #p57
252 'GPSDestLongitude' => MW_EXIF_RATIONAL, # Longitude of destination
253 'GPSDestBearingRef' => MW_EXIF_ASCII, # Reference for bearing of destination #p57
254 'GPSDestBearing' => MW_EXIF_RATIONAL, # Bearing of destination
255 'GPSDestDistanceRef' => MW_EXIF_ASCII, # Reference for distance to destination #p57-58
256 'GPSDestDistance' => MW_EXIF_RATIONAL, # Distance to destination
257 'GPSProcessingMethod' => MW_EXIF_UNDEFINED, # Name of GPS processing method
258 'GPSAreaInformation' => MW_EXIF_UNDEFINED, # Name of GPS area
259 'GPSDateStamp' => MW_EXIF_ASCII, # GPS date
260 'GPSDifferential' => MW_EXIF_SHORT, # GPS differential correction
261 ),
262 );
263
264 $this->makeFlatExifTags();
265 $this->makeValidExifTags();
266 }
267
268 /**
269 * Get the raw list of exiftags
270 *
271 * @access private
272 * @return array
273 */
274 function getExif() {
275 return $this->mExif;
276 }
277
278 /**
279 * Generate a flat list of the exif tags
280 */
281 function makeFlatExifTags() {
282 $exif = $this->getExif();
283 $this->extractTags( $exif );
284 }
285
286 /**
287 * A recursing extractor function used by makeFlatExifTags()
288 *
289 * Note: This used to use an array_walk function, but it made PHP5
290 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
291 */
292 function extractTags( $tagset ) {
293 foreach( $tagset as $key => $val ) {
294 if( is_array( $val ) ) {
295 $this->extractTags( $val );
296 } else {
297 $this->mFlatExif[$key] = $val;
298 }
299 }
300 }
301
302 /**
303 * Produce a list of all Exif tags appropriate for user output
304 *
305 * Produce a list of all tags that we want to show in output, in order not to
306 * output binary gibberish such as raw thumbnails we strip all tags
307 * with the datatype of UNDEFINED.
308 *
309 * @todo We might actually want to display some of the UNDEFINED
310 * stuff, but we strip it for now.
311 */
312 function makeValidExifTags() {
313 foreach( $this->mFlatExif as $key => $val ) {
314 if( strpos( $val, (string)MW_EXIF_UNDEFINED ) !== false ) {
315 continue;
316 }
317 $this->mValidExif[] = $key;
318 }
319 }
320
321 /**
322 * The version of the output format
323 *
324 * Before the actual metadata information is saved in the database we
325 * strip some of it since we don't want to save things like thumbnails
326 * which usually accompany Exif data. This value gets saved in the
327 * database along with the actual Exif data, and if the version in the
328 * database doesn't equal the value returned by this function the Exif
329 * data is regenerated.
330 *
331 * @return int
332 */
333 function version() {
334 return 1; // We don't need no bloddy constants!
335 }
336
337 /**#@+
338 * Validates if a tag value is of the type it should be according to the Exif spec
339 *
340 * @param mixed $in The input value to check
341 * @return bool
342 */
343 function isByte( $in ) {
344 $fname = 'isByte';
345 if ( is_numeric( $in ) && $in >= 0 && $in <= 255 ) {
346 wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n");
347 return true;
348 } else {
349 wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n");
350 return false;
351 }
352 }
353
354 function isASCII( $in ) {
355 wfDebug("Exif::isASCII: input was '$in'\n");
356 return true; // TODO: FIXME
357 }
358
359 function isShort( $in ) {
360 $fname = 'isShort';
361 if ( is_numeric( $in ) && $in >= 0 && $in <= 65536 ) {
362 wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n");
363 return true;
364 } else {
365 wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n");
366 return false;
367 }
368 }
369
370 function isLong( $in ) {
371 $fname = 'isLong';
372 if ( is_numeric( $in ) && $in >= 0 && $in <= 4294967296 ) {
373 wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n");
374 return true;
375 } else {
376 wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n");
377 return false;
378 }
379 }
380
381 function isRational( $in ) {
382 $fname = 'isRational';
383 $a = explode( '/', $in, 2 );
384 if ( $this->isLong( $a[0] ) && $this->isLong( $a[1] ) ) {
385 wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n");
386 return true;
387 } else {
388 wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n");
389 return false;
390 }
391 }
392
393 function isUndefined( $in ) {
394 $fname = 'isUndefined';
395 wfDebug("Exif::$fname: input was '$in'\n");
396 return true;
397 }
398
399 function isSlong( $in ) {
400 $fname = 'isSlong';
401 if ( $this->isLong( abs( $in ) ) ) {
402 wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n");
403 return true;
404 } else {
405 wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n");
406 return false;
407 }
408 }
409
410 function isSrational( $in ) {
411 $fname = 'isSrational';
412 $a = explode( '/', $in, 2 );
413 if ( $this->isSlong( $a[0] ) && $this->isSlong( $a[1] ) ) {
414 wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n");
415 return true;
416 } else {
417 wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n");
418 return false;
419 }
420 }
421 /**#@-*/
422
423 /**
424 * Validates if a tag has a legal value according to the Exif spec, presumes
425 * that the given tag is valid ( has been checked in advance with
426 * $this->mValidExif )
427 *
428 * @param string $tag The tag to check
429 * @param mixed $val The value of the tag
430 * @return bool
431 */
432 function validate( $tag, $val ) {
433 // Fucks up if not typecast
434 switch( (string)$this->mFlatExif[$tag] ) {
435 case (string)MW_EXIF_BYTE:
436 return $this->isByte( $val );
437 case (string)MW_EXIF_ASCII:
438 return $this->isASCII( $val );
439 case (string)MW_EXIF_SHORT:
440 return $this->isShort( $val );
441 case (string)MW_EXIF_LONG:
442 return $this->isLong( $val );
443 case (string)MW_EXIF_RATIONAL:
444 return $this->isRational( $val );
445 case (string)MW_EXIF_UNDEFINED:
446 return $this->isUndefined( $val );
447 case (string)MW_EXIF_SLONG:
448 return $this->isSlong( $val );
449 case (string)MW_EXIF_SRATIONAL:
450 return $this->isSrational( $val );
451 case (string)MW_EXIF_SHORT.','.MW_EXIF_LONG:
452 return $this->isShort( $val ) || $this->isLong( $val );
453 default:
454 wfDebug( "Exif::validate: The tag \"$tag\" had an invalid value: \"$val\"\n" );
455 return false;
456 }
457 }
458
459 /**
460 * Numbers given by Exif user agents are often magical, that is they
461 * should be replaced by a detailed explanation depending on their
462 * value which most of the time are plain integers. This function
463 * formats Exif values into human readable form.
464 *
465 * @param string $tag The tag to be formatted
466 * @param mixed $val The value of the tag
467 * @return string
468 */
469 function format( $tag, $val ) {
470 global $wgLang;
471
472 switch( $tag ) {
473 case 'Compression':
474 switch( $val ) {
475 case 1: case 6:
476 return $this->msg( $tag, $val );
477 }
478 break;
479
480 case 'PhotometricInterpretation':
481 switch( $val ) {
482 case 2: case 6:
483 return $this->msg( $tag, $val );
484 }
485 break;
486
487 case 'Orientation':
488 switch( $val ) {
489 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
490 return $this->msg( $tag, $val );
491 }
492 break;
493
494 case 'PlanarConfiguration':
495 switch( $val ) {
496 case 1: case 2:
497 return $this->msg( $tag, $val );
498 }
499 break;
500
501 // TODO: YCbCrSubSampling
502 // TODO: YCbCrPositioning
503 // TODO: If this field does not exists use 2
504 case 'ResolutionUnit': #p26
505 switch( $val ) {
506 case 2: case 3:
507 return $this->msg( $tag, $val );
508 }
509 break;
510
511 // TODO: YCbCrCoefficients #p27 (see annex E)
512 case 'ExifVersion': case 'FlashpixVersion':
513 return "$val"/100;
514
515 case 'ColorSpace':
516 switch( $val ) {
517 case 1: case 'FFFF.H':
518 return $this->msg( $tag, $val );
519 }
520 break;
521
522 case 'ComponentsConfiguration':
523 switch( $val ) {
524 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
525 return $this->msg( $tag, $val );
526 }
527 break;
528
529 case 'DateTime':
530 case 'DateTimeOriginal':
531 case 'DateTimeDigitized':
532 return $wgLang->timeanddate( wfTimestamp(TS_MW, $val) );
533
534 case 'ExposureProgram':
535 switch( $val ) {
536 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
537 return $this->msg( $tag, $val );
538 }
539 break;
540
541 case 'MeteringMode':
542 switch( $val ) {
543 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
544 return $this->msg( $tag, $val );
545 }
546 break;
547
548 case 'LightSource':
549 switch( $val ) {
550 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
551 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
552 case 21: case 22: case 23: case 24: case 255:
553 return $this->msg( $tag, $val );
554 }
555 break;
556
557 // TODO: Flash
558 case 'SensingMethod':
559 switch( $val ) {
560 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
561 return $this->msg( $tag, $val );
562 }
563 break;
564
565 case 'FileSource':
566 switch( $val ) {
567 case 3:
568 return $this->msg( $tag, $val );
569 }
570 break;
571
572 case 'SceneType':
573 switch( $val ) {
574 case 1:
575 return $this->msg( $tag, $val );
576 }
577 break;
578
579 case 'CustomRendered':
580 switch( $val ) {
581 case 0: case 1:
582 return $this->msg( $tag, $val );
583 }
584 break;
585
586 case 'ExposureMode':
587 switch( $val ) {
588 case 0: case 1: case 2:
589 return $this->msg( $tag, $val );
590 }
591 break;
592
593 case 'WhiteBalance':
594 switch( $val ) {
595 case 0: case 1:
596 return $this->msg( $tag, $val );
597 }
598 break;
599
600 case 'SceneCaptureType':
601 switch( $val ) {
602 case 0: case 1: case 2: case 3:
603 return $this->msg( $tag, $val );
604 }
605 break;
606
607 case 'GainControl':
608 switch( $val ) {
609 case 0: case 1: case 2: case 3: case 4:
610 return $this->msg( $tag, $val );
611 }
612 break;
613
614 case 'Contrast':
615 switch( $val ) {
616 case 0: case 1: case 2:
617 return $this->msg( $tag, $val );
618 }
619 break;
620
621 case 'Saturation':
622 switch( $val ) {
623 case 0: case 1: case 2:
624 return $this->msg( $tag, $val );
625 }
626 break;
627
628 case 'Sharpness':
629 switch( $val ) {
630 case 0: case 1: case 2:
631 return $this->msg( $tag, $val );
632 }
633 break;
634
635 case 'SubjectDistanceRange':
636 switch( $val ) {
637 case 0: case 1: case 2: case 3:
638 return $this->msg( $tag, $val );
639 }
640 break;
641
642 case 'GPSLatitudeRef':
643 switch( $val ) {
644 case 'N': case 'S':
645 return $this->msg( $tag, $val );
646 }
647 break;
648
649 case 'GPSLongitudeRef':
650 switch( $val ) {
651 case 'E': case 'W':
652 return $this->msg( $tag, $val );
653 }
654 break;
655
656 case 'GPSStatus':
657 switch( $val ) {
658 case 'A': case 'V':
659 return $this->msg( $tag, $val );
660 }
661 break;
662
663 case 'GPSMeasureMode':
664 switch( $val ) {
665 case 2: case 3:
666 return $this->msg( $tag, $val );
667 }
668 break;
669
670 case 'GPSSpeedRef':
671 switch( $val ) {
672 case 'K': case 'M': case 'N':
673 return $this->msg( $tag, $val );
674 }
675 break;
676
677 case 'GPSTrackRef':
678 switch( $val ) {
679 case 'T': case 'M':
680 return $this->msg( $tag, $val );
681 }
682 break;
683
684 case 'GPSImgDirectionRef':
685 switch( $val ) {
686 case 'T': case 'M':
687 return $this->msg( $tag, $val );
688 }
689 break;
690
691 case 'GPSDestLatitudeRef':
692 switch( $val ) {
693 case 'N': case 'S':
694 return $this->msg( $tag, $val );
695 }
696 break;
697
698 case 'GPSDestLongitudeRef':
699 switch( $val ) {
700 case 'E': case 'W':
701 return $this->msg( $tag, $val );
702 }
703 break;
704
705 case 'GPSDestBearingRef':
706 switch( $val ) {
707 case 'T': case 'M':
708 return $this->msg( $tag, $val );
709 }
710 break;
711 case 'GPSDateStamp':
712 return $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
713
714 // This is not in the Exif standard, just a special
715 // case for our purposes which enables wikis to wikify
716 // the make, model and software name to link to their articles.
717 case 'Make':
718 case 'Model':
719 case 'Software':
720 return wfMsg( strtolower( "exif-$tag-value" ), $val );
721 default:
722 return $val;
723 }
724 }
725
726 /**
727 * Conviniance function for format()
728 *
729 * @param string $tag The tag name to pass on
730 * @param string $val The value of the tag
731 * @return string A wfMsg of "exif-$tag-$val" in lower case
732 */
733 function msg( $tag, $val ) {
734 return wfMsg( strtolower("exif-$tag-$val") );
735 }
736 }
737
738 } // MEDIAWIKI