X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fmedia%2FJpegMetadataExtractor.php;h=a0f85247a58b1da7c63250ffb5c1d8e933d180f8;hb=3e96e1c5e7fb0f4d38c2e46585d98c9e555d272c;hp=5165760ef9f9273edd1b87b39b0b336f064270e6;hpb=f7c5ef1307141bdd9bdcc96496fd61ab269e65be;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/JpegMetadataExtractor.php b/includes/media/JpegMetadataExtractor.php index 5165760ef9..a0f85247a5 100644 --- a/includes/media/JpegMetadataExtractor.php +++ b/includes/media/JpegMetadataExtractor.php @@ -30,8 +30,8 @@ * @ingroup Media */ class JpegMetadataExtractor { - const MAX_JPEG_SEGMENTS = 200; + // the max segment is a sanity check. // A jpeg file should never even remotely have // that many segments. Your average file has about 10. @@ -44,7 +44,7 @@ class JpegMetadataExtractor { * and those can't extract xmp on files containing both exif and xmp data * * @param string $filename name of jpeg file - * @return Array of interesting segments. + * @return array of interesting segments. * @throws MWException if given invalid file. */ static function segmentSplitter( $filename ) { @@ -83,7 +83,8 @@ class JpegMetadataExtractor { throw new MWException( 'Too many jpeg segments. Aborting' ); } if ( $buffer !== "\xFF" ) { - throw new MWException( "Error reading jpeg file marker. Expected 0xFF but got " . bin2hex( $buffer ) ); + throw new MWException( "Error reading jpeg file marker. " . + "Expected 0xFF but got " . bin2hex( $buffer ) ); } $buffer = fread( $fh, 1 ); @@ -111,9 +112,8 @@ class JpegMetadataExtractor { if ( $com === $oldCom ) { $segments["COM"][] = $oldCom; } else { - wfDebug( __METHOD__ . ' Ignoring JPEG comment as is garbage.' ); + wfDebug( __METHOD__ . " Ignoring JPEG comment as is garbage.\n" ); } - } elseif ( $buffer === "\xE1" ) { // APP1 section (Exif, XMP, and XMP extended) // only extract if XMP is enabled. @@ -140,7 +140,7 @@ class JpegMetadataExtractor { } elseif ( $byteOrderMarker === 'II' ) { $segments['byteOrder'] = 'LE'; } else { - wfDebug( __METHOD__ . ' Invalid byte ordering?!' ); + wfDebug( __METHOD__ . " Invalid byte ordering?!\n" ); } } } elseif ( $buffer === "\xED" ) { @@ -160,7 +160,6 @@ class JpegMetadataExtractor { } fseek( $fh, $size['int'] - 2, SEEK_CUR ); } - } // shouldn't get here. throw new MWException( "Reached end of jpeg file unexpectedly" ); @@ -168,9 +167,9 @@ class JpegMetadataExtractor { /** * Helper function for jpegSegmentSplitter - * @param &$fh FileHandle for jpeg file + * @param resource &$fh File handle for JPEG file * @throws MWException - * @return string data content of segment. + * @return string Data content of segment. */ private static function jpegExtractMarker( &$fh ) { $size = wfUnpack( "nint", fread( $fh, 2 ), 2 ); @@ -181,6 +180,7 @@ class JpegMetadataExtractor { if ( strlen( $segment ) !== $size['int'] - 2 ) { throw new MWException( "Segment shorter than expected" ); } + return $segment; } @@ -195,7 +195,8 @@ class JpegMetadataExtractor { * * @param string $app13 photoshop psir app13 block from jpg. * @throws MWException (It gets caught next level up though) - * @return String if the iptc hash is good or not. + * @return string If the iptc hash is good or not. One of 'iptc-no-hash', + * 'iptc-good-hash', 'iptc-bad-hash'. */ public static function doPSIR( $app13 ) { if ( !$app13 ) { @@ -275,7 +276,6 @@ class JpegMetadataExtractor { $lenData['len']++; } $offset += $lenData['len']; - } if ( !$realHash || !$recordedHash ) {