MediaWiki REL1_28
Exif.php
Go to the documentation of this file.
1<?php
32class Exif {
34 const BYTE = 1;
35
39 const ASCII = 2;
40
42 const SHORT = 3;
43
45 const LONG = 4;
46
50 const RATIONAL = 5;
51
53 const SHORT_OR_LONG = 6;
54
56 const UNDEFINED = 7;
57
59 const SLONG = 9;
60
64 const SRATIONAL = 10;
65
67 const IGNORE = -1;
68
73 private $mExifTags;
74
77
83
85 private $file;
86
88 private $basename;
89
91 private $log = false;
92
96 private $byteOrder;
97
110 function __construct( $file, $byteOrder = '' ) {
119 $this->mExifTags = [
120 # TIFF Rev. 6.0 Attribute Information (p22)
121 'IFD0' => [
122 # Tags relating to image structure
123 'ImageWidth' => Exif::SHORT_OR_LONG, # Image width
124 'ImageLength' => Exif::SHORT_OR_LONG, # Image height
125 'BitsPerSample' => [ Exif::SHORT, 3 ], # 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' => Exif::SHORT, # Compression scheme #p23
129 'PhotometricInterpretation' => Exif::SHORT, # Pixel composition #p23
130 'Orientation' => Exif::SHORT, # Orientation of image #p24
131 'SamplesPerPixel' => Exif::SHORT, # Number of components
132 'PlanarConfiguration' => Exif::SHORT, # Image data arrangement #p24
133 'YCbCrSubSampling' => [ Exif::SHORT, 2 ], # Subsampling ratio of Y to C #p24
134 'YCbCrPositioning' => Exif::SHORT, # Y and C positioning #p24-25
135 'XResolution' => Exif::RATIONAL, # Image resolution in width direction
136 'YResolution' => Exif::RATIONAL, # Image resolution in height direction
137 'ResolutionUnit' => Exif::SHORT, # Unit of X and Y resolution #(p26)
138
139 # Tags relating to recording offset
140 'StripOffsets' => Exif::SHORT_OR_LONG, # Image data location
141 'RowsPerStrip' => Exif::SHORT_OR_LONG, # Number of rows per strip
142 'StripByteCounts' => Exif::SHORT_OR_LONG, # Bytes per compressed strip
143 'JPEGInterchangeFormat' => Exif::SHORT_OR_LONG, # Offset to JPEG SOI
144 'JPEGInterchangeFormatLength' => Exif::SHORT_OR_LONG, # Bytes of JPEG data
145
146 # Tags relating to image data characteristics
147 'TransferFunction' => Exif::IGNORE, # Transfer function
148 'WhitePoint' => [ Exif::RATIONAL, 2 ], # White point chromaticity
149 'PrimaryChromaticities' => [ Exif::RATIONAL, 6 ], # Chromaticities of primarities
150 # Color space transformation matrix coefficients #p27
151 'YCbCrCoefficients' => [ Exif::RATIONAL, 3 ],
152 'ReferenceBlackWhite' => [ Exif::RATIONAL, 6 ], # Pair of black and white reference values
153
154 # Other tags
155 'DateTime' => Exif::ASCII, # File change date and time
156 'ImageDescription' => Exif::ASCII, # Image title
157 'Make' => Exif::ASCII, # Image input equipment manufacturer
158 'Model' => Exif::ASCII, # Image input equipment model
159 'Software' => Exif::ASCII, # Software used
160 'Artist' => Exif::ASCII, # Person who created the image
161 'Copyright' => Exif::ASCII, # Copyright holder
162 ],
163
164 # Exif IFD Attribute Information (p30-31)
165 'EXIF' => [
166 # @todo NOTE: Nonexistence of this field is taken to mean nonconformance
167 # to the Exif 2.1 AND 2.2 standards
168 'ExifVersion' => Exif::UNDEFINED, # Exif version
169 'FlashPixVersion' => Exif::UNDEFINED, # Supported Flashpix version #p32
170
171 # Tags relating to Image Data Characteristics
172 'ColorSpace' => Exif::SHORT, # Color space information #p32
173
174 # Tags relating to image configuration
175 'ComponentsConfiguration' => Exif::UNDEFINED, # Meaning of each component #p33
176 'CompressedBitsPerPixel' => Exif::RATIONAL, # Image compression mode
177 'PixelYDimension' => Exif::SHORT_OR_LONG, # Valid image height
178 'PixelXDimension' => Exif::SHORT_OR_LONG, # Valid image width
179
180 # Tags relating to related user information
181 'MakerNote' => Exif::IGNORE, # Manufacturer notes
182 'UserComment' => Exif::UNDEFINED, # User comments #p34
183
184 # Tags relating to related file information
185 'RelatedSoundFile' => Exif::ASCII, # Related audio file
186
187 # Tags relating to date and time
188 'DateTimeOriginal' => Exif::ASCII, # Date and time of original data generation #p36
189 'DateTimeDigitized' => Exif::ASCII, # Date and time of original data generation
190 'SubSecTime' => Exif::ASCII, # DateTime subseconds
191 'SubSecTimeOriginal' => Exif::ASCII, # DateTimeOriginal subseconds
192 'SubSecTimeDigitized' => Exif::ASCII, # DateTimeDigitized subseconds
193
194 # Tags relating to picture-taking conditions (p31)
195 'ExposureTime' => Exif::RATIONAL, # Exposure time
196 'FNumber' => Exif::RATIONAL, # F Number
197 'ExposureProgram' => Exif::SHORT, # Exposure Program #p38
198 'SpectralSensitivity' => Exif::ASCII, # Spectral sensitivity
199 'ISOSpeedRatings' => Exif::SHORT, # ISO speed rating
200 'OECF' => Exif::IGNORE,
201 # Optoelectronic conversion factor. Note: We don't have support for this atm.
202 'ShutterSpeedValue' => Exif::SRATIONAL, # Shutter speed
203 'ApertureValue' => Exif::RATIONAL, # Aperture
204 'BrightnessValue' => Exif::SRATIONAL, # Brightness
205 'ExposureBiasValue' => Exif::SRATIONAL, # Exposure bias
206 'MaxApertureValue' => Exif::RATIONAL, # Maximum land aperture
207 'SubjectDistance' => Exif::RATIONAL, # Subject distance
208 'MeteringMode' => Exif::SHORT, # Metering mode #p40
209 'LightSource' => Exif::SHORT, # Light source #p40-41
210 'Flash' => Exif::SHORT, # Flash #p41-42
211 'FocalLength' => Exif::RATIONAL, # Lens focal length
212 'SubjectArea' => [ Exif::SHORT, 4 ], # Subject area
213 'FlashEnergy' => Exif::RATIONAL, # Flash energy
214 'SpatialFrequencyResponse' => Exif::IGNORE, # Spatial frequency response. Not supported atm.
215 'FocalPlaneXResolution' => Exif::RATIONAL, # Focal plane X resolution
216 'FocalPlaneYResolution' => Exif::RATIONAL, # Focal plane Y resolution
217 'FocalPlaneResolutionUnit' => Exif::SHORT, # Focal plane resolution unit #p46
218 'SubjectLocation' => [ Exif::SHORT, 2 ], # Subject location
219 'ExposureIndex' => Exif::RATIONAL, # Exposure index
220 'SensingMethod' => Exif::SHORT, # Sensing method #p46
221 'FileSource' => Exif::UNDEFINED, # File source #p47
222 'SceneType' => Exif::UNDEFINED, # Scene type #p47
223 'CFAPattern' => Exif::IGNORE, # CFA pattern. not supported atm.
224 'CustomRendered' => Exif::SHORT, # Custom image processing #p48
225 'ExposureMode' => Exif::SHORT, # Exposure mode #p48
226 'WhiteBalance' => Exif::SHORT, # White Balance #p49
227 'DigitalZoomRatio' => Exif::RATIONAL, # Digital zoom ration
228 'FocalLengthIn35mmFilm' => Exif::SHORT, # Focal length in 35 mm film
229 'SceneCaptureType' => Exif::SHORT, # Scene capture type #p49
230 'GainControl' => Exif::SHORT, # Scene control #p49-50
231 'Contrast' => Exif::SHORT, # Contrast #p50
232 'Saturation' => Exif::SHORT, # Saturation #p50
233 'Sharpness' => Exif::SHORT, # Sharpness #p50
234 'DeviceSettingDescription' => Exif::IGNORE,
235 # Device settings description. This could maybe be supported. Need to find an
236 # example file that uses this to see if it has stuff of interest in it.
237 'SubjectDistanceRange' => Exif::SHORT, # Subject distance range #p51
238
239 'ImageUniqueID' => Exif::ASCII, # Unique image ID
240 ],
241
242 # GPS Attribute Information (p52)
243 'GPS' => [
244 'GPSVersion' => Exif::UNDEFINED,
245 # Should be an array of 4 Exif::BYTE's. However php treats it as an undefined
246 # Note exif standard calls this GPSVersionID, but php doesn't like the id suffix
247 'GPSLatitudeRef' => Exif::ASCII, # North or South Latitude #p52-53
248 'GPSLatitude' => [ Exif::RATIONAL, 3 ], # Latitude
249 'GPSLongitudeRef' => Exif::ASCII, # East or West Longitude #p53
250 'GPSLongitude' => [ Exif::RATIONAL, 3 ], # Longitude
251 'GPSAltitudeRef' => Exif::UNDEFINED,
252 # Altitude reference. Note, the exif standard says this should be an EXIF::Byte,
253 # but php seems to disagree.
254 'GPSAltitude' => Exif::RATIONAL, # Altitude
255 'GPSTimeStamp' => [ Exif::RATIONAL, 3 ], # GPS time (atomic clock)
256 'GPSSatellites' => Exif::ASCII, # Satellites used for measurement
257 'GPSStatus' => Exif::ASCII, # Receiver status #p54
258 'GPSMeasureMode' => Exif::ASCII, # Measurement mode #p54-55
259 'GPSDOP' => Exif::RATIONAL, # Measurement precision
260 'GPSSpeedRef' => Exif::ASCII, # Speed unit #p55
261 'GPSSpeed' => Exif::RATIONAL, # Speed of GPS receiver
262 'GPSTrackRef' => Exif::ASCII, # Reference for direction of movement #p55
263 'GPSTrack' => Exif::RATIONAL, # Direction of movement
264 'GPSImgDirectionRef' => Exif::ASCII, # Reference for direction of image #p56
265 'GPSImgDirection' => Exif::RATIONAL, # Direction of image
266 'GPSMapDatum' => Exif::ASCII, # Geodetic survey data used
267 'GPSDestLatitudeRef' => Exif::ASCII, # Reference for latitude of destination #p56
268 'GPSDestLatitude' => [ Exif::RATIONAL, 3 ], # Latitude destination
269 'GPSDestLongitudeRef' => Exif::ASCII, # Reference for longitude of destination #p57
270 'GPSDestLongitude' => [ Exif::RATIONAL, 3 ], # Longitude of destination
271 'GPSDestBearingRef' => Exif::ASCII, # Reference for bearing of destination #p57
272 'GPSDestBearing' => Exif::RATIONAL, # Bearing of destination
273 'GPSDestDistanceRef' => Exif::ASCII, # Reference for distance to destination #p57-58
274 'GPSDestDistance' => Exif::RATIONAL, # Distance to destination
275 'GPSProcessingMethod' => Exif::UNDEFINED, # Name of GPS processing method
276 'GPSAreaInformation' => Exif::UNDEFINED, # Name of GPS area
277 'GPSDateStamp' => Exif::ASCII, # GPS date
278 'GPSDifferential' => Exif::SHORT, # GPS differential correction
279 ],
280 ];
281
282 $this->file = $file;
283 $this->basename = wfBaseName( $this->file );
284 if ( $byteOrder === 'BE' || $byteOrder === 'LE' ) {
285 $this->byteOrder = $byteOrder;
286 } else {
287 // Only give a warning for b/c, since originally we didn't
288 // require this. The number of things affected by this is
289 // rather small.
290 wfWarn( 'Exif class did not have byte order specified. ' .
291 'Some properties may be decoded incorrectly.' );
292 $this->byteOrder = 'BE'; // BE seems about twice as popular as LE in jpg's.
293 }
294
295 $this->debugFile( $this->basename, __FUNCTION__, true );
296 if ( function_exists( 'exif_read_data' ) ) {
297 MediaWiki\suppressWarnings();
298 $data = exif_read_data( $this->file, 0, true );
299 MediaWiki\restoreWarnings();
300 } else {
301 throw new MWException( "Internal error: exif_read_data not present. " .
302 "\$wgShowEXIF may be incorrectly set or not checked by an extension." );
303 }
309 $this->mRawExifData = $data ?: [];
310 $this->makeFilteredData();
311 $this->collapseData();
312 $this->debugFile( __FUNCTION__, false );
313 }
314
318 function makeFilteredData() {
319 $this->mFilteredExifData = [];
320
321 foreach ( array_keys( $this->mRawExifData ) as $section ) {
322 if ( !array_key_exists( $section, $this->mExifTags ) ) {
323 $this->debug( $section, __FUNCTION__, "'$section' is not a valid Exif section" );
324 continue;
325 }
326
327 foreach ( array_keys( $this->mRawExifData[$section] ) as $tag ) {
328 if ( !array_key_exists( $tag, $this->mExifTags[$section] ) ) {
329 $this->debug( $tag, __FUNCTION__, "'$tag' is not a valid tag in '$section'" );
330 continue;
331 }
332
333 $this->mFilteredExifData[$tag] = $this->mRawExifData[$section][$tag];
334 // This is ok, as the tags in the different sections do not conflict.
335 // except in computed and thumbnail section, which we don't use.
336
337 $value = $this->mRawExifData[$section][$tag];
338 if ( !$this->validate( $section, $tag, $value ) ) {
339 $this->debug( $value, __FUNCTION__, "'$tag' contained invalid data" );
340 unset( $this->mFilteredExifData[$tag] );
341 }
342 }
343 }
344 }
345
364 function collapseData() {
365
366 $this->exifGPStoNumber( 'GPSLatitude' );
367 $this->exifGPStoNumber( 'GPSDestLatitude' );
368 $this->exifGPStoNumber( 'GPSLongitude' );
369 $this->exifGPStoNumber( 'GPSDestLongitude' );
370
371 if ( isset( $this->mFilteredExifData['GPSAltitude'] )
372 && isset( $this->mFilteredExifData['GPSAltitudeRef'] )
373 ) {
374 // We know altitude data is a <num>/<denom> from the validation
375 // functions ran earlier. But multiplying such a string by -1
376 // doesn't work well, so convert.
377 list( $num, $denom ) = explode( '/', $this->mFilteredExifData['GPSAltitude'] );
378 $this->mFilteredExifData['GPSAltitude'] = $num / $denom;
379
380 if ( $this->mFilteredExifData['GPSAltitudeRef'] === "\1" ) {
381 $this->mFilteredExifData['GPSAltitude'] *= -1;
382 }
383 unset( $this->mFilteredExifData['GPSAltitudeRef'] );
384 }
385
386 $this->exifPropToOrd( 'FileSource' );
387 $this->exifPropToOrd( 'SceneType' );
388
389 $this->charCodeString( 'UserComment' );
390 $this->charCodeString( 'GPSProcessingMethod' );
391 $this->charCodeString( 'GPSAreaInformation' );
392
393 // ComponentsConfiguration should really be an array instead of a string...
394 // This turns a string of binary numbers into an array of numbers.
395
396 if ( isset( $this->mFilteredExifData['ComponentsConfiguration'] ) ) {
397 $val = $this->mFilteredExifData['ComponentsConfiguration'];
398 $ccVals = [];
399
400 $strLen = strlen( $val );
401 for ( $i = 0; $i < $strLen; $i++ ) {
402 $ccVals[$i] = ord( substr( $val, $i, 1 ) );
403 }
404 $ccVals['_type'] = 'ol'; // this is for formatting later.
405 $this->mFilteredExifData['ComponentsConfiguration'] = $ccVals;
406 }
407
408 // GPSVersion(ID) is treated as the wrong type by php exif support.
409 // Go through each byte turning it into a version string.
410 // For example: "\x02\x02\x00\x00" -> "2.2.0.0"
411
412 // Also change exif tag name from GPSVersion (what php exif thinks it is)
413 // to GPSVersionID (what the exif standard thinks it is).
414
415 if ( isset( $this->mFilteredExifData['GPSVersion'] ) ) {
416 $val = $this->mFilteredExifData['GPSVersion'];
417 $newVal = '';
418
419 $strLen = strlen( $val );
420 for ( $i = 0; $i < $strLen; $i++ ) {
421 if ( $i !== 0 ) {
422 $newVal .= '.';
423 }
424 $newVal .= ord( substr( $val, $i, 1 ) );
425 }
426
427 if ( $this->byteOrder === 'LE' ) {
428 // Need to reverse the string
429 $newVal2 = '';
430 for ( $i = strlen( $newVal ) - 1; $i >= 0; $i-- ) {
431 $newVal2 .= substr( $newVal, $i, 1 );
432 }
433 $this->mFilteredExifData['GPSVersionID'] = $newVal2;
434 } else {
435 $this->mFilteredExifData['GPSVersionID'] = $newVal;
436 }
437 unset( $this->mFilteredExifData['GPSVersion'] );
438 }
439 }
440
447 private function charCodeString( $prop ) {
448 if ( isset( $this->mFilteredExifData[$prop] ) ) {
449
450 if ( strlen( $this->mFilteredExifData[$prop] ) <= 8 ) {
451 // invalid. Must be at least 9 bytes long.
452
453 $this->debug( $this->mFilteredExifData[$prop], __FUNCTION__, false );
454 unset( $this->mFilteredExifData[$prop] );
455
456 return;
457 }
458 $charCode = substr( $this->mFilteredExifData[$prop], 0, 8 );
459 $val = substr( $this->mFilteredExifData[$prop], 8 );
460
461 switch ( $charCode ) {
462 case "\x4A\x49\x53\x00\x00\x00\x00\x00":
463 // JIS
464 $charset = "Shift-JIS";
465 break;
466 case "UNICODE\x00":
467 $charset = "UTF-16" . $this->byteOrder;
468 break;
469 default: // ascii or undefined.
470 $charset = "";
471 break;
472 }
473 if ( $charset ) {
474 MediaWiki\suppressWarnings();
475 $val = iconv( $charset, 'UTF-8//IGNORE', $val );
476 MediaWiki\restoreWarnings();
477 } else {
478 // if valid utf-8, assume that, otherwise assume windows-1252
479 $valCopy = $val;
480 UtfNormal\Validator::quickIsNFCVerify( $valCopy ); // validates $valCopy.
481 if ( $valCopy !== $val ) {
482 MediaWiki\suppressWarnings();
483 $val = iconv( 'Windows-1252', 'UTF-8//IGNORE', $val );
484 MediaWiki\restoreWarnings();
485 }
486 }
487
488 // trim and check to make sure not only whitespace.
489 $val = trim( $val );
490 if ( strlen( $val ) === 0 ) {
491 // only whitespace.
492 $this->debug( $this->mFilteredExifData[$prop], __FUNCTION__, "$prop: Is only whitespace" );
493 unset( $this->mFilteredExifData[$prop] );
494
495 return;
496 }
497
498 // all's good.
499 $this->mFilteredExifData[$prop] = $val;
500 }
501 }
502
509 private function exifPropToOrd( $prop ) {
510 if ( isset( $this->mFilteredExifData[$prop] ) ) {
511 $this->mFilteredExifData[$prop] = ord( $this->mFilteredExifData[$prop] );
512 }
513 }
514
520 private function exifGPStoNumber( $prop ) {
521 $loc =& $this->mFilteredExifData[$prop];
522 $dir =& $this->mFilteredExifData[$prop . 'Ref'];
523 $res = false;
524
525 if ( isset( $loc ) && isset( $dir )
526 && ( $dir === 'N' || $dir === 'S' || $dir === 'E' || $dir === 'W' )
527 ) {
528 list( $num, $denom ) = explode( '/', $loc[0] );
529 $res = $num / $denom;
530 list( $num, $denom ) = explode( '/', $loc[1] );
531 $res += ( $num / $denom ) * ( 1 / 60 );
532 list( $num, $denom ) = explode( '/', $loc[2] );
533 $res += ( $num / $denom ) * ( 1 / 3600 );
534
535 if ( $dir === 'S' || $dir === 'W' ) {
536 $res *= -1; // make negative
537 }
538 }
539
540 // update the exif records.
541
542 if ( $res !== false ) { // using !== as $res could potentially be 0
543 $this->mFilteredExifData[$prop] = $res;
544 unset( $this->mFilteredExifData[$prop . 'Ref'] );
545 } else { // if invalid
546 unset( $this->mFilteredExifData[$prop] );
547 unset( $this->mFilteredExifData[$prop . 'Ref'] );
548 }
549 }
550
560 function getData() {
561 return $this->mRawExifData;
562 }
563
568 function getFilteredData() {
570 }
571
586 public static function version() {
587 return 2; // We don't need no bloddy constants!
588 }
589
596 private function isByte( $in ) {
597 if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 255 ) {
598 $this->debug( $in, __FUNCTION__, true );
599
600 return true;
601 } else {
602 $this->debug( $in, __FUNCTION__, false );
603
604 return false;
605 }
606 }
607
612 private function isASCII( $in ) {
613 if ( is_array( $in ) ) {
614 return false;
615 }
616
617 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
618 $this->debug( $in, __FUNCTION__, 'found a character not in our whitelist' );
619
620 return false;
621 }
622
623 if ( preg_match( '/^\s*$/', $in ) ) {
624 $this->debug( $in, __FUNCTION__, 'input consisted solely of whitespace' );
625
626 return false;
627 }
628
629 return true;
630 }
631
636 private function isShort( $in ) {
637 if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 65536 ) {
638 $this->debug( $in, __FUNCTION__, true );
639
640 return true;
641 } else {
642 $this->debug( $in, __FUNCTION__, false );
643
644 return false;
645 }
646 }
647
652 private function isLong( $in ) {
653 if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 4294967296 ) {
654 $this->debug( $in, __FUNCTION__, true );
655
656 return true;
657 } else {
658 $this->debug( $in, __FUNCTION__, false );
659
660 return false;
661 }
662 }
663
668 private function isRational( $in ) {
669 $m = [];
670
671 # Avoid division by zero
672 if ( !is_array( $in )
673 && preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m )
674 ) {
675 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
676 } else {
677 $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
678
679 return false;
680 }
681 }
682
687 private function isUndefined( $in ) {
688 $this->debug( $in, __FUNCTION__, true );
689
690 return true;
691 }
692
697 private function isSlong( $in ) {
698 if ( $this->isLong( abs( $in ) ) ) {
699 $this->debug( $in, __FUNCTION__, true );
700
701 return true;
702 } else {
703 $this->debug( $in, __FUNCTION__, false );
704
705 return false;
706 }
707 }
708
713 private function isSrational( $in ) {
714 $m = [];
715
716 # Avoid division by zero
717 if ( !is_array( $in ) &&
718 preg_match( '/^(-?\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m )
719 ) {
720 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
721 } else {
722 $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
723
724 return false;
725 }
726 }
727
739 private function validate( $section, $tag, $val, $recursive = false ) {
740 $debug = "tag is '$tag'";
741 $etype = $this->mExifTags[$section][$tag];
742 $ecount = 1;
743 if ( is_array( $etype ) ) {
744 list( $etype, $ecount ) = $etype;
745 if ( $recursive ) {
746 $ecount = 1; // checking individual elements
747 }
748 }
749 $count = count( $val );
750 if ( $ecount != $count ) {
751 $this->debug( $val, __FUNCTION__, "Expected $ecount elements for $tag but got $count" );
752
753 return false;
754 }
755 if ( $count > 1 ) {
756 foreach ( $val as $v ) {
757 if ( !$this->validate( $section, $tag, $v, true ) ) {
758 return false;
759 }
760 }
761
762 return true;
763 }
764 // Does not work if not typecast
765 switch ( (string)$etype ) {
766 case (string)Exif::BYTE:
767 $this->debug( $val, __FUNCTION__, $debug );
768
769 return $this->isByte( $val );
770 case (string)Exif::ASCII:
771 $this->debug( $val, __FUNCTION__, $debug );
772
773 return $this->isASCII( $val );
774 case (string)Exif::SHORT:
775 $this->debug( $val, __FUNCTION__, $debug );
776
777 return $this->isShort( $val );
778 case (string)Exif::LONG:
779 $this->debug( $val, __FUNCTION__, $debug );
780
781 return $this->isLong( $val );
782 case (string)Exif::RATIONAL:
783 $this->debug( $val, __FUNCTION__, $debug );
784
785 return $this->isRational( $val );
786 case (string)Exif::SHORT_OR_LONG:
787 $this->debug( $val, __FUNCTION__, $debug );
788
789 return $this->isShort( $val ) || $this->isLong( $val );
790 case (string)Exif::UNDEFINED:
791 $this->debug( $val, __FUNCTION__, $debug );
792
793 return $this->isUndefined( $val );
794 case (string)Exif::SLONG:
795 $this->debug( $val, __FUNCTION__, $debug );
796
797 return $this->isSlong( $val );
798 case (string)Exif::SRATIONAL:
799 $this->debug( $val, __FUNCTION__, $debug );
800
801 return $this->isSrational( $val );
802 case (string)Exif::IGNORE:
803 $this->debug( $val, __FUNCTION__, $debug );
804
805 return false;
806 default:
807 $this->debug( $val, __FUNCTION__, "The tag '$tag' is unknown" );
808
809 return false;
810 }
811 }
812
820 private function debug( $in, $fname, $action = null ) {
821 if ( !$this->log ) {
822 return;
823 }
824 $type = gettype( $in );
825 $class = ucfirst( __CLASS__ );
826 if ( is_array( $in ) ) {
827 $in = print_r( $in, true );
828 }
829
830 if ( $action === true ) {
831 wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)" );
832 } elseif ( $action === false ) {
833 wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)" );
834 } elseif ( $action === null ) {
835 wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)" );
836 } else {
837 wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')" );
838 }
839 }
840
847 private function debugFile( $fname, $io ) {
848 if ( !$this->log ) {
849 return;
850 }
851 $class = ucfirst( __CLASS__ );
852 if ( $io ) {
853 wfDebugLog( $this->log, "$class::$fname: begin processing: '{$this->basename}'" );
854 } else {
855 wfDebugLog( $this->log, "$class::$fname: end processing: '{$this->basename}'" );
856 }
857 }
858}
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition Setup.php:36
Class to extract and validate Exif data from jpeg (and possibly tiff) files.
Definition Exif.php:32
const SRATIONAL
Two SLONGs.
Definition Exif.php:64
validate( $section, $tag, $val, $recursive=false)
#-
Definition Exif.php:739
isRational( $in)
Definition Exif.php:668
const BYTE
An 8-bit (1-byte) unsigned integer.
Definition Exif.php:34
exifPropToOrd( $prop)
Convert an Exif::UNDEFINED from a raw binary string to its value.
Definition Exif.php:509
getData()
#-
Definition Exif.php:560
const SHORT_OR_LONG
A 16-bit (2-byte) or 32-bit (4-byte) unsigned integer.
Definition Exif.php:53
string $file
The file being processed.
Definition Exif.php:85
const RATIONAL
Two LONGs.
Definition Exif.php:50
array $mFilteredExifData
A Filtered version of $mRawExifData that has been pruned of invalid tags and tags that contain conten...
Definition Exif.php:82
const UNDEFINED
An 8-bit byte that can take any value depending on the field definition.
Definition Exif.php:56
isUndefined( $in)
Definition Exif.php:687
string $byteOrder
The byte order of the file.
Definition Exif.php:96
static version()
#-
Definition Exif.php:586
const ASCII
An 8-bit byte containing one 7-bit ASCII code.
Definition Exif.php:39
isSrational( $in)
Definition Exif.php:713
getFilteredData()
Get $this->mFilteredExifData.
Definition Exif.php:568
debug( $in, $fname, $action=null)
Convenience function for debugging output.
Definition Exif.php:820
const SHORT
A 16-bit (2-byte) unsigned integer.
Definition Exif.php:42
charCodeString( $prop)
Do userComment tags and similar.
Definition Exif.php:447
const LONG
A 32-bit (4-byte) unsigned integer.
Definition Exif.php:45
array $mExifTags
Exif tags grouped by category, the tagname itself is the key and the type is the value,...
Definition Exif.php:73
array $mRawExifData
The raw Exif data returned by exif_read_data()
Definition Exif.php:76
__construct( $file, $byteOrder='')
Constructor.
Definition Exif.php:110
makeFilteredData()
Make $this->mFilteredExifData.
Definition Exif.php:318
isLong( $in)
Definition Exif.php:652
string $log
The private log to log to, e.g.
Definition Exif.php:91
string $basename
The basename of the file being processed.
Definition Exif.php:88
isSlong( $in)
Definition Exif.php:697
isASCII( $in)
Definition Exif.php:612
collapseData()
Collapse some fields together.
Definition Exif.php:364
isShort( $in)
Definition Exif.php:636
const IGNORE
A fake value for things we don't want or don't support.
Definition Exif.php:67
debugFile( $fname, $io)
Convenience function for debugging output.
Definition Exif.php:847
exifGPStoNumber( $prop)
Convert gps in exif form to a single floating point number for example 10 degress 2040` S -> -10....
Definition Exif.php:520
isByte( $in)
Validates if a tag value is of the type it should be according to the Exif spec.
Definition Exif.php:596
const SLONG
A 32-bit (4-byte) signed integer (2's complement notation),.
Definition Exif.php:59
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:50
MediaWiki exception.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
$res
Definition database.txt:21
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could change
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
database rows
Definition globals.txt:10
the array() calling protocol came about after MediaWiki 1.4rc1.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after processing
Definition hooks.txt:1958
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
Definition hooks.txt:181
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition hooks.txt:2568
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify prev or next refreshes the diff cache allow viewing deleted revs difference engine object to be used for diff source
Definition hooks.txt:1609
null for the local wiki Added in
Definition hooks.txt:1558
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive false for true for descending in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. 'CustomEditor' $rcid is used in generating this variable which contains information about the new such as the revision s whether the revision was marked as a minor edit or not
Definition hooks.txt:1207
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books $tag
Definition hooks.txt:1033
you don t have to do a grep find to see where the $wgReverseTitle variable is used
Definition hooks.txt:117
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition hooks.txt:108
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition hooks.txt:2901
if(count( $args)==0) $dir
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the Software
Definition LICENSE.txt:12
Copyright(c) 2011-2015 MediaWiki Widgets Team and others under the terms of The MIT License(MIT)
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$debug
Definition mcc.php:31
title
width
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN boolean columns are always mapped to as the code does not always treat the column as a and VARBINARY columns should simply be TEXT The only exception is when VARBINARY is used to store true binary data
Definition postgres.txt:43
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:36