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