57 self::$gifFrameSep = pack(
"C", ord(
"," ) );
58 self::$gifExtensionSep = pack(
"C", ord(
"!" ) );
59 self::$gifTerm = pack(
"C", ord(
";" ) );
68 throw new Exception(
"No file name specified" );
69 } elseif ( !file_exists( $filename ) || is_dir( $filename ) ) {
70 throw new Exception(
"File $filename does not exist" );
73 $fh = fopen( $filename,
'rb' );
76 throw new Exception(
"Unable to open file $filename" );
80 $buf = fread( $fh, 6 );
81 if ( !( $buf ==
'GIF87a' || $buf ==
'GIF89a' ) ) {
82 throw new Exception(
"Not a valid GIF file; header: $buf" );
89 $buf = fread( $fh, 1 );
90 $bpp = self::decodeBPP( $buf );
96 self::readGCT( $fh, $bpp );
98 while ( !feof( $fh ) ) {
99 $buf = fread( $fh, 1 );
101 if ( $buf == self::$gifFrameSep ) {
105 # # Skip bounding box
109 $buf = fread( $fh, 1 );
110 $bpp = self::decodeBPP( $buf );
113 self::readGCT( $fh, $bpp );
115 self::skipBlock( $fh );
116 } elseif ( $buf == self::$gifExtensionSep ) {
117 $buf = fread( $fh, 1 );
118 if ( strlen( $buf ) < 1 ) {
119 throw new Exception(
"Ran out of input" );
121 $extension_code = unpack(
'C', $buf )[1];
123 if ( $extension_code == 0xF9 ) {
129 $buf = fread( $fh, 2 );
130 if ( strlen( $buf ) < 2 ) {
131 throw new Exception(
"Ran out of input" );
133 $delay = unpack(
'v', $buf )[1];
134 $duration += $delay * 0.01;
138 $term = fread( $fh, 1 );
139 if ( strlen(
$term ) < 1 ) {
140 throw new Exception(
"Ran out of input" );
144 throw new Exception(
"Malformed Graphics Control Extension block" );
146 } elseif ( $extension_code == 0xFE ) {
148 $data = self::readBlock( $fh );
149 if ( $data ===
"" ) {
150 throw new Exception(
'Read error, zero-length comment block' );
158 UtfNormal\Validator::quickIsNFCVerify( $dataCopy );
160 if ( $dataCopy !== $data ) {
161 MediaWiki\suppressWarnings();
162 $data = iconv(
'windows-1252',
'UTF-8', $data );
163 MediaWiki\restoreWarnings();
167 if ( $commentCount === 0
168 ||
$comment[$commentCount - 1] !== $data
175 } elseif ( $extension_code == 0xFF ) {
178 $blockLength = fread( $fh, 1 );
179 if ( strlen( $blockLength ) < 1 ) {
180 throw new Exception(
"Ran out of input" );
182 $blockLength = unpack(
'C', $blockLength )[1];
183 $data = fread( $fh, $blockLength );
185 if ( $blockLength != 11 ) {
186 wfDebug( __METHOD__ .
" GIF application block with wrong length\n" );
187 fseek( $fh, -( $blockLength + 1 ), SEEK_CUR );
188 self::skipBlock( $fh );
193 if ( $data ==
'NETSCAPE2.0' ) {
194 $data = fread( $fh, 2 );
196 if ( $data !=
"\x03\x01" ) {
197 throw new Exception(
"Expected \x03\x01, got $data" );
201 $loopData = fread( $fh, 2 );
202 if ( strlen( $loopData ) < 2 ) {
203 throw new Exception(
"Ran out of input" );
205 $loopCount = unpack(
'v', $loopData )[1];
207 if ( $loopCount != 1 ) {
213 } elseif ( $data ==
'XMP DataXMP' ) {
217 $xmp = self::readBlock( $fh,
true );
219 if ( substr( $xmp, -257, 3 ) !==
"\x01\xFF\xFE"
220 || substr( $xmp, -4 ) !==
"\x03\x02\x01\x00"
223 throw new Exception(
"XMP does not have magic trailer!" );
227 $xmp = substr( $xmp, 0, -257 );
230 fseek( $fh, -( $blockLength + 1 ), SEEK_CUR );
231 self::skipBlock( $fh );
235 self::skipBlock( $fh );
237 } elseif ( $buf == self::$gifTerm ) {
240 if ( strlen( $buf ) < 1 ) {
241 throw new Exception(
"Ran out of input" );
243 $byte = unpack(
'C', $buf )[1];
244 throw new Exception(
"At position: " . ftell( $fh ) .
", Unknown byte " . $byte );
249 'frameCount' => $frameCount,
250 'looped' => $isLooped,
251 'duration' => $duration,
264 $max = pow( 2, $bpp );
265 for ( $i = 1; $i <= $max; ++$i ) {
277 if ( strlen( $data ) < 1 ) {
278 throw new Exception(
"Ran out of input" );
280 $buf = unpack(
'C', $data )[1];
281 $bpp = ( $buf & 7 ) + 1;
284 $have_map = $buf & 1;
286 return $have_map ? $bpp : 0;
294 while ( !feof( $fh ) ) {
295 $buf = fread( $fh, 1 );
296 if ( strlen( $buf ) < 1 ) {
297 throw new Exception(
"Ran out of input" );
299 $block_len = unpack(
'C', $buf )[1];
300 if ( $block_len == 0 ) {
303 fread( $fh, $block_len );
321 static function readBlock( $fh, $includeLengths =
false ) {
323 $subLength = fread( $fh, 1 );
326 while ( $subLength !==
"\0" ) {
328 if ( $blocks > self::MAX_SUBBLOCKS ) {
329 throw new Exception(
"MAX_SUBBLOCKS exceeded (over $blocks sub-blocks)" );
332 throw new Exception(
"Read error: Unexpected EOF." );
334 if ( $includeLengths ) {
338 $data .= fread( $fh, ord( $subLength ) );
339 $subLength = fread( $fh, 1 );
external whereas SearchGetNearMatch runs after $term
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
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