MediaWiki  1.23.8
Exif.php
Go to the documentation of this file.
1 <?php
32 class 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 
76  private $mRawExifData;
77 
82  private $mFilteredExifData;
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 = array(
120  # TIFF Rev. 6.0 Attribute Information (p22)
121  'IFD0' => array(
122  # Tags relating to image structure
123  'ImageWidth' => Exif::SHORT_OR_LONG, # Image width
124  'ImageLength' => Exif::SHORT_OR_LONG, # Image height
125  'BitsPerSample' => array( 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' => array( 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' => array( Exif::RATIONAL, 2 ), # White point chromaticity
149  'PrimaryChromaticities' => array( Exif::RATIONAL, 6 ), # Chromaticities of primarities
150  # Color space transformation matrix coefficients #p27
151  'YCbCrCoefficients' => array( Exif::RATIONAL, 3 ),
152  'ReferenceBlackWhite' => array( 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' => array(
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 width
178  'PixelXDimension' => Exif::SHORT_OR_LONG, # Valid image height
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' => array( 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' => array( 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' => array(
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' => array( Exif::RATIONAL, 3 ), # Latitude
249  'GPSLongitudeRef' => Exif::ASCII, # East or West Longitude #p53
250  'GPSLongitude' => array( 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' => array( 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' => array( Exif::RATIONAL, 3 ), # Latitude destination
269  'GPSDestLongitudeRef' => Exif::ASCII, # Reference for longitude of destination #p57
270  'GPSDestLongitude' => array( 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' ) ) {
298  $data = exif_read_data( $this->file, 0, true );
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 ?: array();
310  $this->makeFilteredData();
311  $this->collapseData();
312  $this->debugFile( __FUNCTION__, false );
313  }
314 
318  function makeFilteredData() {
319  $this->mFilteredExifData = array();
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 = array();
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  // This could possibly check to see if iconv is really installed
474  // or if we're using the compatibility wrapper in globalFunctions.php
475  if ( $charset ) {
477  $val = iconv( $charset, 'UTF-8//IGNORE', $val );
479  } else {
480  // if valid utf-8, assume that, otherwise assume windows-1252
481  $valCopy = $val;
482  UtfNormal::quickIsNFCVerify( $valCopy ); //validates $valCopy.
483  if ( $valCopy !== $val ) {
485  $val = iconv( 'Windows-1252', 'UTF-8//IGNORE', $val );
487  }
488  }
489 
490  //trim and check to make sure not only whitespace.
491  $val = trim( $val );
492  if ( strlen( $val ) === 0 ) {
493  //only whitespace.
494  $this->debug( $this->mFilteredExifData[$prop], __FUNCTION__, "$prop: Is only whitespace" );
495  unset( $this->mFilteredExifData[$prop] );
496 
497  return;
498  }
499 
500  //all's good.
501  $this->mFilteredExifData[$prop] = $val;
502  }
503  }
504 
511  private function exifPropToOrd( $prop ) {
512  if ( isset( $this->mFilteredExifData[$prop] ) ) {
513  $this->mFilteredExifData[$prop] = ord( $this->mFilteredExifData[$prop] );
514  }
515  }
516 
522  private function exifGPStoNumber( $prop ) {
523  $loc =& $this->mFilteredExifData[$prop];
524  $dir =& $this->mFilteredExifData[$prop . 'Ref'];
525  $res = false;
526 
527  if ( isset( $loc ) && isset( $dir )
528  && ( $dir === 'N' || $dir === 'S' || $dir === 'E' || $dir === 'W' )
529  ) {
530  list( $num, $denom ) = explode( '/', $loc[0] );
531  $res = $num / $denom;
532  list( $num, $denom ) = explode( '/', $loc[1] );
533  $res += ( $num / $denom ) * ( 1 / 60 );
534  list( $num, $denom ) = explode( '/', $loc[2] );
535  $res += ( $num / $denom ) * ( 1 / 3600 );
536 
537  if ( $dir === 'S' || $dir === 'W' ) {
538  $res *= -1; // make negative
539  }
540  }
541 
542  // update the exif records.
543 
544  if ( $res !== false ) { // using !== as $res could potentially be 0
545  $this->mFilteredExifData[$prop] = $res;
546  unset( $this->mFilteredExifData[$prop . 'Ref'] );
547  } else { // if invalid
548  unset( $this->mFilteredExifData[$prop] );
549  unset( $this->mFilteredExifData[$prop . 'Ref'] );
550  }
551  }
552 
562  function getData() {
563  return $this->mRawExifData;
564  }
565 
569  function getFilteredData() {
570  return $this->mFilteredExifData;
571  }
572 
587  public static function version() {
588  return 2; // We don't need no bloddy constants!
589  }
590 
597  private function isByte( $in ) {
598  if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 255 ) {
599  $this->debug( $in, __FUNCTION__, true );
600 
601  return true;
602  } else {
603  $this->debug( $in, __FUNCTION__, false );
604 
605  return false;
606  }
607  }
608 
613  private function isASCII( $in ) {
614  if ( is_array( $in ) ) {
615  return false;
616  }
617 
618  if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
619  $this->debug( $in, __FUNCTION__, 'found a character not in our whitelist' );
620 
621  return false;
622  }
623 
624  if ( preg_match( '/^\s*$/', $in ) ) {
625  $this->debug( $in, __FUNCTION__, 'input consisted solely of whitespace' );
626 
627  return false;
628  }
629 
630  return true;
631  }
632 
637  private function isShort( $in ) {
638  if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 65536 ) {
639  $this->debug( $in, __FUNCTION__, true );
640 
641  return true;
642  } else {
643  $this->debug( $in, __FUNCTION__, false );
644 
645  return false;
646  }
647  }
648 
653  private function isLong( $in ) {
654  if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 4294967296 ) {
655  $this->debug( $in, __FUNCTION__, true );
656 
657  return true;
658  } else {
659  $this->debug( $in, __FUNCTION__, false );
660 
661  return false;
662  }
663  }
664 
669  private function isRational( $in ) {
670  $m = array();
671 
672  # Avoid division by zero
673  if ( !is_array( $in )
674  && preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m )
675  ) {
676  return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
677  } else {
678  $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
679 
680  return false;
681  }
682  }
683 
688  private function isUndefined( $in ) {
689  $this->debug( $in, __FUNCTION__, true );
690 
691  return true;
692  }
693 
698  private function isSlong( $in ) {
699  if ( $this->isLong( abs( $in ) ) ) {
700  $this->debug( $in, __FUNCTION__, true );
701 
702  return true;
703  } else {
704  $this->debug( $in, __FUNCTION__, false );
705 
706  return false;
707  }
708  }
709 
714  private function isSrational( $in ) {
715  $m = array();
716 
717  # Avoid division by zero
718  if ( !is_array( $in ) &&
719  preg_match( '/^(-?\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m )
720  ) {
721  return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
722  } else {
723  $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
724 
725  return false;
726  }
727  }
728 
740  private function validate( $section, $tag, $val, $recursive = false ) {
741  $debug = "tag is '$tag'";
742  $etype = $this->mExifTags[$section][$tag];
743  $ecount = 1;
744  if ( is_array( $etype ) ) {
745  list( $etype, $ecount ) = $etype;
746  if ( $recursive ) {
747  $ecount = 1; // checking individual elements
748  }
749  }
750  $count = count( $val );
751  if ( $ecount != $count ) {
752  $this->debug( $val, __FUNCTION__, "Expected $ecount elements for $tag but got $count" );
753 
754  return false;
755  }
756  if ( $count > 1 ) {
757  foreach ( $val as $v ) {
758  if ( !$this->validate( $section, $tag, $v, true ) ) {
759  return false;
760  }
761  }
762 
763  return true;
764  }
765  // Does not work if not typecast
766  switch ( (string)$etype ) {
767  case (string)Exif::BYTE:
768  $this->debug( $val, __FUNCTION__, $debug );
769 
770  return $this->isByte( $val );
771  case (string)Exif::ASCII:
772  $this->debug( $val, __FUNCTION__, $debug );
773 
774  return $this->isASCII( $val );
775  case (string)Exif::SHORT:
776  $this->debug( $val, __FUNCTION__, $debug );
777 
778  return $this->isShort( $val );
779  case (string)Exif::LONG:
780  $this->debug( $val, __FUNCTION__, $debug );
781 
782  return $this->isLong( $val );
783  case (string)Exif::RATIONAL:
784  $this->debug( $val, __FUNCTION__, $debug );
785 
786  return $this->isRational( $val );
787  case (string)Exif::SHORT_OR_LONG:
788  $this->debug( $val, __FUNCTION__, $debug );
789 
790  return $this->isShort( $val ) || $this->isLong( $val );
791  case (string)Exif::UNDEFINED:
792  $this->debug( $val, __FUNCTION__, $debug );
793 
794  return $this->isUndefined( $val );
795  case (string)Exif::SLONG:
796  $this->debug( $val, __FUNCTION__, $debug );
797 
798  return $this->isSlong( $val );
799  case (string)Exif::SRATIONAL:
800  $this->debug( $val, __FUNCTION__, $debug );
801 
802  return $this->isSrational( $val );
803  case (string)Exif::IGNORE:
804  $this->debug( $val, __FUNCTION__, $debug );
805 
806  return false;
807  default:
808  $this->debug( $val, __FUNCTION__, "The tag '$tag' is unknown" );
809 
810  return false;
811  }
812  }
813 
821  private function debug( $in, $fname, $action = null ) {
822  if ( !$this->log ) {
823  return;
824  }
825  $type = gettype( $in );
826  $class = ucfirst( __CLASS__ );
827  if ( is_array( $in ) ) {
828  $in = print_r( $in, true );
829  }
830 
831  if ( $action === true ) {
832  wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)" );
833  } elseif ( $action === false ) {
834  wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)" );
835  } elseif ( $action === null ) {
836  wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)" );
837  } else {
838  wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')" );
839  }
840  }
841 
848  private function debugFile( $fname, $io ) {
849  if ( !$this->log ) {
850  return;
851  }
852  $class = ucfirst( __CLASS__ );
853  if ( $io ) {
854  wfDebugLog( $this->log, "$class::$fname: begin processing: '{$this->basename}'" );
855  } else {
856  wfDebugLog( $this->log, "$class::$fname: end processing: '{$this->basename}'" );
857  }
858  }
859 }
Exif\isRational
isRational( $in)
Definition: Exif.php:662
data
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
Definition: hooks.txt:6
of
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
Definition: globals.txt:10
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Exif\isSrational
isSrational( $in)
Definition: Exif.php:707
Exif\makeFilteredData
makeFilteredData()
Make $this->mFilteredExifData.
Definition: Exif.php:311
is
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for except in special pages derived from QueryPage It s a common pitfall for new developers to submit code containing SQL queries which examine huge numbers of rows Remember that COUNT * is(N), counting rows in atable is like counting beans in a bucket.------------------------------------------------------------------------ Replication------------------------------------------------------------------------The largest installation of MediaWiki, Wikimedia, uses a large set ofslave MySQL servers replicating writes made to a master MySQL server. Itis important to understand the issues associated with this setup if youwant to write code destined for Wikipedia.It 's often the case that the best algorithm to use for a given taskdepends on whether or not replication is in use. Due to our unabashedWikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB() ->getServerCount() > 1 tocheck to see if replication is in use.===Lag===Lag primarily occurs when large write queries are sent to the master.Writes on the master are executed in parallel, but they are executed inserial when they are replicated to the slaves. The master writes thequery to the binlog when the transaction is committed. The slaves pollthe binlog and start executing the query as soon as it appears. They canservice reads while they are performing a write query, but will not readanything more from the binlog and thus will perform no more writes. Thismeans that if the write query runs for a long time, the slaves will lagbehind the master for the time it takes for the write query to complete.Lag can be exacerbated by high read load. MediaWiki 's load balancer willstop sending reads to a slave when it is lagged by more than 30 seconds.If the load ratios are set incorrectly, or if there is too much loadgenerally, this may lead to a slave permanently hovering around 30seconds lag.If all slaves are lagged by more than 30 seconds, MediaWiki will stopwriting to the database. All edits and other write operations will berefused, with an error returned to the user. This gives the slaves achance to catch up. Before we had this mechanism, the slaves wouldregularly lag by several minutes, making review of recent editsdifficult.In addition to this, MediaWiki attempts to ensure that the user seesevents occurring on the wiki in chronological order. A few seconds of lagcan be tolerated, as long as the user sees a consistent picture fromsubsequent requests. This is done by saving the master binlog positionin the session, and then at the start of each request, waiting for theslave to catch up to that position before doing any reads from it. Ifthis wait times out, reads are allowed anyway, but the request isconsidered to be in "lagged slave mode". Lagged slave mode can bechecked by calling wfGetLB() ->getLaggedSlaveMode(). The onlypractical consequence at present is a warning displayed in the pagefooter.===Lag avoidance===To avoid excessive lag, queries which write large numbers of rows shouldbe split up, generally to write one row at a time. Multi-row INSERT ...SELECT queries are the worst offenders should be avoided altogether.Instead do the select first and then the insert.===Working with lag===Despite our best efforts, it 's not practical to guarantee a low-lagenvironment. Lag will usually be less than one second, but mayoccasionally be up to 30 seconds. For scalability, it 's very importantto keep load on the master low, so simply sending all your queries tothe master is not the answer. So when you have a genuine need forup-to-date data, the following approach is advised:1) Do a quick query to the master for a sequence number or timestamp 2) Run the full query on the slave and check if it matches the data you gotfrom the master 3) If it doesn 't, run the full query on the masterTo avoid swamping the master every time the slaves lag, use of thisapproach should be kept to a minimum. In most cases you should just readfrom the slave and let the user deal with the delay.------------------------------------------------------------------------ Lock contention------------------------------------------------------------------------Due to the high write rate on Wikipedia(and some other wikis), MediaWiki developers need to be very careful to structure their writesto avoid long-lasting locks. By default, MediaWiki opens a transactionat the first query, and commits it before the output is sent. Locks willbe held from the time when the query is done until the commit. So youcan reduce lock time by doing as much processing as possible before youdo your write queries.Often this approach is not good enough, and it becomes necessary toenclose small groups of queries in their own transaction. Use thefollowing syntax:$dbw=wfGetDB(DB_MASTER
Exif\validate
validate( $section, $tag, $val, $recursive=false)
#-
Definition: Exif.php:733
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1040
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
Exif\ASCII
const ASCII
An 8-bit byte containing one 7-bit ASCII code.
Definition: Exif.php:39
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:35
Exif
Class to extract and validate Exif data from jpeg (and possibly tiff) files.
Definition: Exif.php:32
$in
$in
Definition: Utf8Test.php:42
Exif\isShort
isShort( $in)
Definition: Exif.php:630
Exif\SHORT_OR_LONG
const SHORT_OR_LONG
A 16-bit (2-byte) or 32-bit (4-byte) unsigned integer.
Definition: Exif.php:53
conversion
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 conversion
Definition: postgres.txt:22
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
file
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:93
Exif\isUndefined
isUndefined( $in)
Definition: Exif.php:681
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:50
MWException
MediaWiki exception.
Definition: MWException.php:26
Exif\LONG
const LONG
A 32-bit (4-byte) unsigned integer.
Definition: Exif.php:45
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
Exif\IGNORE
const IGNORE
A fake value for things we don't want or don't support.
Definition: Exif.php:67
Exif\$log
string $log
The private log to log to, e.g.
Definition: Exif.php:85
version
Prior to version
Definition: maintenance.txt:1
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Exif\version
static version()
#-
Definition: Exif.php:580
Exif\getFilteredData
getFilteredData()
Get $this->mFilteredExifData.
Definition: Exif.php:562
Exif\getData
getData()
#-
Definition: Exif.php:555
list
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
Exif\charCodeString
charCodeString( $prop)
Do userComment tags and similar.
Definition: Exif.php:440
Exif\RATIONAL
const RATIONAL
Two LONGs.
Definition: Exif.php:50
$section
$section
Definition: Utf8Test.php:88
user
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
Exif\$mExifTags
array $mExifTags
Exif tags grouped by category, the tagname itself is the key and the type is the value,...
Definition: Exif.php:72
$value
$value
Definition: styleTest.css.php:45
Exif\debug
debug( $in, $fname, $action=null)
Convenience function for debugging output.
Definition: Exif.php:814
Exif\debugFile
debugFile( $fname, $io)
Convenience function for debugging output.
Definition: Exif.php:841
Exif\isSlong
isSlong( $in)
Definition: Exif.php:691
Exif\exifGPStoNumber
exifGPStoNumber( $prop)
Convert gps in exif form to a single floating point number for example 10 degress 2040` S -> -10....
Definition: Exif.php:515
tags
pre inside other HTML tags(bug 54946) !! wikitext a< div >< pre > foo</pre ></div >< pre ></pre > !! html< p >a</p >< div >< pre > foo</pre ></div >< pre ></pre > !! end !! test HTML pre followed by indent-pre !! wikitext< pre >foo</pre > bar !! html< pre >foo</pre >< pre >bar</pre > !! end !!test Block tag pre !!options parsoid !! wikitext< p >< pre >foo</pre ></p > !! html< p data-parsoid
Exif\exifPropToOrd
exifPropToOrd( $prop)
Convert an Exif::UNDEFINED from a raw binary string to its value.
Definition: Exif.php:504
Exif\collapseData
collapseData()
Collapse some fields together.
Definition: Exif.php:357
Exif\$mFilteredExifData
array $mFilteredExifData
A Filtered version of $mRawExifData that has been pruned of invalid tags and tags that contain conten...
Definition: Exif.php:79
$count
$count
Definition: UtfNormalTest2.php:96
Exif\SLONG
const SLONG
A 32-bit (4-byte) signed integer (2's complement notation),.
Definition: Exif.php:59
it
=Architecture==Two class hierarchies are used to provide the functionality associated with the different content models:*Content interface(and AbstractContent base class) define functionality that acts on the concrete content of a page, and *ContentHandler base class provides functionality specific to a content model, but not acting on concrete content. The most important function of ContentHandler is to act as a factory for the appropriate implementation of Content. These Content objects are to be used by MediaWiki everywhere, instead of passing page content around as text. All manipulation and analysis of page content must be done via the appropriate methods of the Content object. For each content model, a subclass of ContentHandler has to be registered with $wgContentHandlers. The ContentHandler object for a given content model can be obtained using ContentHandler::getForModelID($id). Also Title, WikiPage and Revision now have getContentHandler() methods for convenience. ContentHandler objects are singletons that provide functionality specific to the content type, but not directly acting on the content of some page. ContentHandler::makeEmptyContent() and ContentHandler::unserializeContent() can be used to create a Content object of the appropriate type. However, it is recommended to instead use WikiPage::getContent() resp. Revision::getContent() to get a page 's content as a Content object. These two methods should be the ONLY way in which page content is accessed. Another important function of ContentHandler objects is to define custom action handlers for a content model, see ContentHandler::getActionOverrides(). This is similar to what WikiPage::getActionOverrides() was already doing.==Serialization==With the ContentHandler facility, page content no longer has to be text based. Objects implementing the Content interface are used to represent and handle the content internally. For storage and data exchange, each content model supports at least one serialization format via ContentHandler::serializeContent($content). The list of supported formats for a given content model can be accessed using ContentHandler::getSupportedFormats(). Content serialization formats are identified using MIME type like strings. The following formats are built in:*text/x-wiki - wikitext *text/javascript - for js pages *text/css - for css pages *text/plain - for future use, e.g. with plain text messages. *text/html - for future use, e.g. with plain html messages. *application/vnd.php.serialized - for future use with the api and for extensions *application/json - for future use with the api, and for use by extensions *application/xml - for future use with the api, and for use by extensions In PHP, use the corresponding CONTENT_FORMAT_XXX constant. Note that when using the API to access page content, especially action=edit, action=parse and action=query &prop=revisions, the model and format of the content should always be handled explicitly. Without that information, interpretation of the provided content is not reliable. The same applies to XML dumps generated via maintenance/dumpBackup.php or Special:Export. Also note that the API will provide encapsulated, serialized content - so if the API was called with format=json, and contentformat is also json(or rather, application/json), the page content is represented as a string containing an escaped json structure. Extensions that use JSON to serialize some types of page content may provide specialized API modules that allow access to that content in a more natural form.==Compatibility==The ContentHandler facility is introduced in a way that should allow all existing code to keep functioning at least for pages that contain wikitext or other text based content. However, a number of functions and hooks have been deprecated in favor of new versions that are aware of the page 's content model, and will now generate warnings when used. Most importantly, the following functions have been deprecated:*Revisions::getText() and Revisions::getRawText() is deprecated in favor Revisions::getContent() *WikiPage::getText() is deprecated in favor WikiPage::getContent() Also, the old Article::getContent()(which returns text) is superceded by Article::getContentObject(). However, both methods should be avoided since they do not provide clean access to the page 's actual content. For instance, they may return a system message for non-existing pages. Use WikiPage::getContent() instead. Code that relies on a textual representation of the page content should eventually be rewritten. However, ContentHandler::getContentText() provides a stop-gap that can be used to get text for a page. Its behavior is controlled by $wgContentHandlerTextFallback it
Definition: contenthandler.txt:107
$debug
$debug
Definition: Setup.php:498
Exif\isByte
isByte( $in)
#+ Validates if a tag value is of the type it should be according to the Exif spec
Definition: Exif.php:590
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
Exif\$byteOrder
string $byteOrder
The byte order of the file.
Definition: Exif.php:89
in
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning in
Definition: maintenance.txt:1
used
you don t have to do a grep find to see where the $wgReverseTitle variable is used
Definition: hooks.txt:117
Exif\$basename
string $basename
The basename of the file being processed *.
Definition: Exif.php:83
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 such as
Definition: distributors.txt:9
Exif\__construct
__construct( $file, $byteOrder='')
Constructor.
Definition: Exif.php:103
values
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:177
Exif\SRATIONAL
const SRATIONAL
Two SLONGs.
Definition: Exif.php:64
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1141
Exif\$mRawExifData
array $mRawExifData
The raw Exif data returned by exif_read_data() *.
Definition: Exif.php:74
change
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
Definition: distributors.txt:9
Exif\SHORT
const SHORT
A 16-bit (2-byte) unsigned integer.
Definition: Exif.php:42
Exif\isASCII
isASCII( $in)
Definition: Exif.php:606
Exif\UNDEFINED
const UNDEFINED
An 8-bit byte that can take any value depending on the field definition.
Definition: Exif.php:56
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
Exif\BYTE
const BYTE
An 8-bit (1-byte) unsigned integer.
Definition: Exif.php:34
$res
$res
Definition: database.txt:21
Exif\$file
string $file
The file being processed *.
Definition: Exif.php:81
Exif\isLong
isLong( $in)
Definition: Exif.php:646
UtfNormal\quickIsNFCVerify
static quickIsNFCVerify(&$string)
Returns true if the string is definitely in NFC.
Definition: UtfNormal.php:243
$type
$type
Definition: testCompression.php:46