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' );
92 while (
$buffer ===
"\xFF" && !feof( $fh ) ) {
101 $com = $oldCom = trim( self::jpegExtractMarker( $fh ) );
102 UtfNormal\Validator::quickIsNFCVerify( $com );
105 if ( $com !== $oldCom ) {
106 MediaWiki\suppressWarnings();
107 $com = $oldCom = iconv(
'windows-1252',
'UTF-8//IGNORE', $oldCom );
108 MediaWiki\restoreWarnings();
112 UtfNormal\Validator::quickIsNFCVerify( $com );
113 if ( $com === $oldCom ) {
114 $segments[
"COM"][] = $oldCom;
116 wfDebug( __METHOD__ .
" Ignoring JPEG comment as is garbage.\n" );
118 } elseif (
$buffer ===
"\xE1" ) {
121 $temp = self::jpegExtractMarker( $fh );
123 if ( substr( $temp, 0, 29 ) ===
"http://ns.adobe.com/xap/1.0/\x00" && $showXMP ) {
124 $segments[
"XMP"] = substr( $temp, 29 );
125 } elseif ( substr( $temp, 0, 35 ) ===
"http://ns.adobe.com/xmp/extension/\x00" && $showXMP ) {
126 $segments[
"XMP_ext"][] = substr( $temp, 35 );
127 } elseif ( substr( $temp, 0, 29 ) ===
"XMP\x00://ns.adobe.com/xap/1.0/\x00" && $showXMP ) {
131 $segments[
"XMP"] = substr( $temp, 29 );
132 wfDebug( __METHOD__ .
' Found XMP section with wrong app identifier '
133 .
"Using anyways.\n" );
134 } elseif ( substr( $temp, 0, 6 ) ===
"Exif\0\0" ) {
138 $byteOrderMarker = substr( $temp, 6, 2 );
139 if ( $byteOrderMarker ===
'MM' ) {
140 $segments[
'byteOrder'] =
'BE';
141 } elseif ( $byteOrderMarker ===
'II' ) {
142 $segments[
'byteOrder'] =
'LE';
144 wfDebug( __METHOD__ .
" Invalid byte ordering?!\n" );
147 } elseif (
$buffer ===
"\xED" ) {
149 $temp = self::jpegExtractMarker( $fh );
150 if ( substr( $temp, 0, 14 ) ===
"Photoshop 3.0\x00" ) {
151 $segments[
"PSIR"][] = $temp;
158 $size =
wfUnpack(
"nint", fread( $fh, 2 ), 2 );
159 if ( $size[
'int'] < 2 ) {
160 throw new MWException(
"invalid marker size in jpeg" );
162 fseek( $fh, $size[
'int'] - 2, SEEK_CUR );
166 throw new MWException(
"Reached end of jpeg file unexpectedly" );
176 $size =
wfUnpack(
"nint", fread( $fh, 2 ), 2 );
177 if ( $size[
'int'] < 2 ) {
178 throw new MWException(
"invalid marker size in jpeg" );
180 if ( $size[
'int'] === 2 ) {
184 $segment = fread( $fh, $size[
'int'] - 2 );
185 if ( strlen( $segment ) !== $size[
'int'] - 2 ) {
186 throw new MWException(
"Segment shorter than expected" );
206 public static function doPSIR( $app13 ) {
217 $appLen = strlen( $app13 );
222 while ( $offset + 12 <= $appLen ) {
224 if ( substr( $app13, $offset, 4 ) !==
'8BIM' ) {
231 $id = substr( $app13, $offset, 2 );
242 $lenName = ord( substr( $app13, $offset, 1 ) ) + 1;
244 if ( $lenName % 2 == 1 ) {
250 $lenData =
wfUnpack(
'Nlen', substr( $app13, $offset, 4 ), 4 );
254 if ( $lenData[
'len'] < 0 ) {
255 throw new MWException(
"Too big PSIR (" . $lenData[
'len'] .
')' );
261 if ( $lenData[
'len'] + $offset > $appLen ) {
262 throw new MWException(
"PSIR data too long. (item length=" . $lenData[
'len']
263 .
"; offset=$offset; total length=$appLen)" );
270 $realHash = md5( substr( $app13, $offset, $lenData[
'len'] ),
true );
273 $recordedHash = substr( $app13, $offset, $lenData[
'len'] );
280 if ( $lenData[
'len'] % 2 == 1 ) {
283 $offset += $lenData[
'len'];
286 if ( !$realHash || !$recordedHash ) {
287 return 'iptc-no-hash';
288 } elseif ( $realHash === $recordedHash ) {
289 return 'iptc-good-hash';
291 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.