40 static function parse( $rawData ) {
41 $parsed = iptcparse( $rawData );
43 if ( !is_array( $parsed ) ) {
49 if ( isset( $parsed[
'1#090'] ) && isset( $parsed[
'1#090'][0] ) ) {
57 unset( $parsed[
'1#090'] );
60 foreach ( $parsed
as $tag => $val ) {
61 if ( isset( $val[0] ) && trim( $val[0] ) ==
'' ) {
62 wfDebugLog(
'iptc',
"IPTC tag $tag had only whitespace as its value." );
81 if ( isset( $parsed[
'2#085'] ) ) {
88 for ( $i = 0; $i < $titleCount; $i++ ) {
89 if ( isset( $bylines[$i] ) ) {
92 $bylines[$i] =
$titles[$i] .
', ' . $bylines[$i];
95 $data[
'Artist'] = $bylines;
167 if (
count( $software ) !== 1 ) {
171 wfDebugLog(
'iptc',
'IPTC: Wrong count on 2:65 Software field' );
175 if ( isset( $parsed[
'2#070'] ) ) {
178 unset( $parsed[
'2#070'] );
179 $data[
'Software'] = [ [ $software[0], $softwareVersion[0] ] ];
181 $data[
'Software'] = $software;
225 if ( isset( $parsed[
'2#060'] ) ) {
226 $time = $parsed[
'2#060'];
232 $data[
'DateTimeOriginal'] = $timestamp;
239 if ( isset( $parsed[
'2#063'] ) ) {
240 $time = $parsed[
'2#063'];
246 $data[
'DateTimeDigitized'] = $timestamp;
252 if ( isset( $parsed[
'2#035'] ) ) {
253 $time = $parsed[
'2#035'];
259 $data[
'DateTimeReleased'] = $timestamp;
265 if ( isset( $parsed[
'2#038'] ) ) {
266 $time = $parsed[
'2#038'];
272 $data[
'DateTimeExpires'] = $timestamp;
280 if ( strlen( $val[0] ) == 2 ) {
282 $versionValue = ord( substr( $val[0], 0, 1 ) ) * 256;
283 $versionValue += ord( substr( $val[0], 1, 1 ) );
284 $data[
'iimVersion'] = $versionValue;
299 if ( strlen( $con[0] ) < 5 ) {
305 $extracted = substr( $con[0], 4 );
306 $data[
'IntellectualGenre'] = $extracted;
315 foreach ( $codes
as $ic ) {
316 $fields = explode(
':', $ic, 3 );
318 if (
count( $fields ) < 2 || $fields[0] !==
'IPTC' ) {
320 .
'Invalid 2:12 - ' . $ic );
323 $data[
'SubjectNewsCode'] = $fields[1];
342 wfDebugLog(
'iptc',
"Unsupported iptc tag: $tag. Value: " . implode(
',', $val ) );
360 if (
count( $date ) === 1 ) {
372 $time =
'000000+0000';
376 if ( !( preg_match(
'/\d\d\d\d\d\d[-+]\d\d\d\d/',
$time )
377 && preg_match(
'/\d\d\d\d\d\d\d\d/', $date )
378 && substr( $date, 0, 4 ) !==
'0000'
379 && substr( $date, 4, 2 ) !==
'00'
380 && substr( $date, 6, 2 ) !==
'00'
387 wfDebugLog(
'iptc',
"IPTC: invalid time ( $time ) or date ( $date )" );
393 if ( $unixTS ===
false ) {
394 wfDebugLog(
'iptc',
"IPTC: can't convert date to TS_UNIX: $date $time." );
399 $tz = ( intval( substr(
$time, 7, 2 ) ) * 60 * 60 )
400 + ( intval( substr(
$time, 9, 2 ) ) * 60 );
402 if ( substr(
$time, 6, 1 ) ===
'-' ) {
406 $finalTimestamp =
wfTimestamp( TS_EXIF, $unixTS + $tz );
407 if ( $finalTimestamp ===
false ) {
408 wfDebugLog(
'iptc',
"IPTC: can't make final timestamp. Date: " . ( $unixTS + $tz ) );
414 return substr( $finalTimestamp, 0, 10 );
416 return $finalTimestamp;
427 private static function convIPTC( $data, $charset ) {
428 if ( is_array( $data ) ) {
429 foreach ( $data
as &$val ) {
448 MediaWiki\suppressWarnings();
449 $data = iconv( $charset,
"UTF-8//IGNORE", $data );
450 MediaWiki\restoreWarnings();
451 if ( $data ===
false ) {
453 wfDebugLog(
'iptc', __METHOD__ .
" Error converting iptc data charset $charset to utf-8" );
459 UtfNormal\Validator::quickIsNFCVerify( $data );
460 if ( $data === $oldData ) {
467 return trim( $data );
554 $c =
"CSA_Z243.4-1985-1";
557 $c =
"CSA_Z243.4-1985-2";
561 case "\x1b&@\x1b\$B":
562 case "\x1b&@\x1b\$(B":
563 $c =
"JIS_C6226-1983";
595 wfDebugLog(
'iptc', __METHOD__ .
'Unknown charset in iptc 1:90: ' . bin2hex( $tag ) );