25use Wikimedia\XMPReader\Reader as
XMPReader;
45 60 => [
'iptc-good-hash',
'iptc-no-hash' ],
46 70 => [
'xmp-deprecated' ],
47 80 => [
'xmp-general' ],
49 100 => [
'iptc-bad-hash' ],
67 }
catch ( Exception
$e ) {
71 wfDebug(
"Error parsing iptc data of file: " .
$e->getMessage() .
"\n" );
72 $this->iptcType =
'iptc-no-hash';
89 function getExif( $filename, $byteOrder ) {
92 $exif =
new Exif( $filename, $byteOrder );
93 $data = $exif->getFilteredData();
107 if ( isset( $this->metadata[
$type] ) ) {
109 $metaArray = $metaArray + $this->metadata[
$type];
112 $this->metadata[
$type] = $metaArray;
128 krsort( $this->metaPriority );
129 foreach ( $this->metaPriority as $pri ) {
130 foreach ( $pri as
$type ) {
131 if ( isset( $this->metadata[
$type] ) ) {
134 foreach ( $this->metadata[
$type] as $itemName => $item ) {
135 if ( is_array( $item ) && isset( $item[
'_type'] ) && $item[
'_type'] ===
'lang' ) {
136 if ( isset( $temp[$itemName] ) && !is_array( $temp[$itemName] ) ) {
137 $default = $temp[$itemName];
138 $temp[$itemName] = $item;
139 $temp[$itemName][
'x-default'] = $default;
140 unset( $this->metadata[
$type][$itemName] );
145 $temp = $temp + $this->metadata[
$type];
159 static function Jpeg( $filename ) {
160 $showXMP = XMPReader::isSupported();
165 if ( isset( $seg[
'COM'] ) && isset( $seg[
'COM'][0] ) ) {
166 $meta->addMetadata( [
'JPEGFileComment' => $seg[
'COM'] ],
'native' );
168 if ( isset( $seg[
'PSIR'] ) && count( $seg[
'PSIR'] ) > 0 ) {
169 foreach ( $seg[
'PSIR'] as $curPSIRValue ) {
170 $meta->doApp13( $curPSIRValue );
173 if ( isset( $seg[
'XMP'] ) && $showXMP ) {
174 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ), $filename );
175 $xmp->parse( $seg[
'XMP'] );
176 foreach ( $seg[
'XMP_ext'] as $xmpExt ) {
180 $xmp->parseExtended( $xmpExt );
182 $res = $xmp->getResults();
184 $meta->addMetadata( $array,
$type );
188 $meta->getExif( $filename, $seg[
'byteOrder'] ??
'BE' );
190 return $meta->getMetadataArray();
201 public static function PNG( $filename ) {
202 $showXMP = XMPReader::isSupported();
206 if ( isset( $array[
'text'][
'xmp'][
'x-default'] )
207 && $array[
'text'][
'xmp'][
'x-default'] !==
'' && $showXMP
209 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ), $filename );
210 $xmp->parse( $array[
'text'][
'xmp'][
'x-default'] );
211 $xmpRes = $xmp->getResults();
212 foreach ( $xmpRes as
$type => $xmpSection ) {
213 $meta->addMetadata( $xmpSection,
$type );
216 unset( $array[
'text'][
'xmp'] );
217 $meta->addMetadata( $array[
'text'],
'native' );
218 unset( $array[
'text'] );
219 $array[
'metadata'] = $meta->getMetadataArray();
233 public static function GIF( $filename ) {
237 if ( count( $baseArray[
'comment'] ) > 0 ) {
238 $meta->addMetadata( [
'GIFFileComment' => $baseArray[
'comment'] ],
'native' );
241 if ( $baseArray[
'xmp'] !==
'' && XMPReader::isSupported() ) {
242 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ), $filename );
243 $xmp->parse( $baseArray[
'xmp'] );
244 $xmpRes = $xmp->getResults();
245 foreach ( $xmpRes as
$type => $xmpSection ) {
246 $meta->addMetadata( $xmpSection,
$type );
250 unset( $baseArray[
'comment'] );
251 unset( $baseArray[
'xmp'] );
253 $baseArray[
'metadata'] = $meta->getMetadataArray();
272 public static function Tiff( $filename ) {
273 if ( file_exists( $filename ) ) {
276 throw new MWException(
"Error determining byte order of $filename" );
278 $exif =
new Exif( $filename, $byteOrder );
279 $data = $exif->getFilteredData();
285 throw new MWException(
"Could not extract data from tiff file $filename" );
288 throw new MWException(
"File doesn't exist - $filename" );
300 $fh = fopen( $filename,
'rb' );
304 $head = fread( $fh, 2 );
$wgShowEXIF
Show Exif data, on by default if available.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Class to extract and validate Exif data from jpeg (and possibly tiff) files.
static parse( $rawData)
This takes the results of iptcparse() and puts it into a form that can be handled by mediawiki.
returning false will NOT prevent logging $e
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))