62 throw new MWException(
"No filename specified for " . __METHOD__ );
64 if ( !file_exists( $filename ) || is_dir( $filename ) ) {
65 throw new MWException(
"Invalid file $filename passed to " . __METHOD__ );
68 $fh = fopen( $filename,
"rb" );
71 throw new MWException(
"Could not open file $filename" );
78 while ( !feof( $fh ) ) {
81 if ( $segmentCount > self::MAX_JPEG_SEGMENTS ) {
83 throw new MWException(
'Too many jpeg segments. Aborting' );
86 throw new MWException(
"Error reading jpeg file marker. " .
87 "Expected 0xFF but got " . bin2hex(
$buffer ) );
91 while (
$buffer ===
"\xFF" && !feof( $fh ) ) {
100 $com = $oldCom = trim( self::jpegExtractMarker( $fh ) );
101 UtfNormal\Validator::quickIsNFCVerify( $com );
104 if ( $com !== $oldCom ) {
105 MediaWiki\suppressWarnings();
106 $com = $oldCom = iconv(
'windows-1252',
'UTF-8//IGNORE', $oldCom );
107 MediaWiki\restoreWarnings();
111 UtfNormal\Validator::quickIsNFCVerify( $com );
112 if ( $com === $oldCom ) {
113 $segments[
"COM"][] = $oldCom;
115 wfDebug( __METHOD__ .
" Ignoring JPEG comment as is garbage.\n" );
117 } elseif (
$buffer ===
"\xE1" ) {
120 $temp = self::jpegExtractMarker( $fh );
122 if ( substr( $temp, 0, 29 ) ===
"http://ns.adobe.com/xap/1.0/\x00" && $showXMP ) {
123 $segments[
"XMP"] = substr( $temp, 29 );
124 } elseif ( substr( $temp, 0, 35 ) ===
"http://ns.adobe.com/xmp/extension/\x00" && $showXMP ) {
125 $segments[
"XMP_ext"][] = substr( $temp, 35 );
126 } elseif ( substr( $temp, 0, 29 ) ===
"XMP\x00://ns.adobe.com/xap/1.0/\x00" && $showXMP ) {
130 $segments[
"XMP"] = substr( $temp, 29 );
131 wfDebug( __METHOD__ .
' Found XMP section with wrong app identifier '
132 .
"Using anyways.\n" );
133 } elseif ( substr( $temp, 0, 6 ) ===
"Exif\0\0" ) {
137 $byteOrderMarker = substr( $temp, 6, 2 );
138 if ( $byteOrderMarker ===
'MM' ) {
139 $segments[
'byteOrder'] =
'BE';
140 } elseif ( $byteOrderMarker ===
'II' ) {
141 $segments[
'byteOrder'] =
'LE';
143 wfDebug( __METHOD__ .
" Invalid byte ordering?!\n" );
146 } elseif (
$buffer ===
"\xED" ) {
148 $temp = self::jpegExtractMarker( $fh );
149 if ( substr( $temp, 0, 14 ) ===
"Photoshop 3.0\x00" ) {
150 $segments[
"PSIR"][] = $temp;
157 $size =
wfUnpack(
"nint", fread( $fh, 2 ), 2 );
158 if ( $size[
'int'] <= 2 ) {
159 throw new MWException(
"invalid marker size in jpeg" );
161 fseek( $fh, $size[
'int'] - 2, SEEK_CUR );
165 throw new MWException(
"Reached end of jpeg file unexpectedly" );
175 $size =
wfUnpack(
"nint", fread( $fh, 2 ), 2 );
176 if ( $size[
'int'] <= 2 ) {
177 throw new MWException(
"invalid marker size in jpeg" );
179 $segment = fread( $fh, $size[
'int'] - 2 );
180 if ( strlen( $segment ) !== $size[
'int'] - 2 ) {
181 throw new MWException(
"Segment shorter than expected" );
201 public static function doPSIR( $app13 ) {
212 $appLen = strlen( $app13 );
217 while ( $offset + 12 <= $appLen ) {
219 if ( substr( $app13, $offset, 4 ) !==
'8BIM' ) {
226 $id = substr( $app13, $offset, 2 );
237 $lenName = ord( substr( $app13, $offset, 1 ) ) + 1;
239 if ( $lenName % 2 == 1 ) {
245 $lenData =
wfUnpack(
'Nlen', substr( $app13, $offset, 4 ), 4 );
249 if ( $lenData[
'len'] < 0 ) {
250 throw new MWException(
"Too big PSIR (" . $lenData[
'len'] .
')' );
256 if ( $lenData[
'len'] + $offset > $appLen ) {
257 throw new MWException(
"PSIR data too long. (item length=" . $lenData[
'len']
258 .
"; offset=$offset; total length=$appLen)" );
265 $realHash = md5( substr( $app13, $offset, $lenData[
'len'] ),
true );
268 $recordedHash = substr( $app13, $offset, $lenData[
'len'] );
275 if ( $lenData[
'len'] % 2 == 1 ) {
278 $offset += $lenData[
'len'];
281 if ( !$realHash || !$recordedHash ) {
282 return 'iptc-no-hash';
283 } elseif ( $realHash === $recordedHash ) {
284 return 'iptc-good-hash';
286 return 'iptc-bad-hash';
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static isSupported()
Check if this instance supports using this class.
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
wfUnpack($format, $data, $length=false)
Wrapper around php's unpack.