*/
public function convertMetadataVersion($metadata, $version) {
$handler = $this->getHandler();
- if (!is_array($metadata)) {
+ if ( !is_array( $metadata ) ) {
//just to make the return type consistant
$metadata = unserialize( $metadata );
}
if ( $handler ) {
- return $handler->convertMetadataVersion($metadata, $version);
+ return $handler->convertMetadataVersion( $metadata, $version );
} else {
return $metadata;
}
*/
class BitmapMetadataHandler {
- private $metadata = Array();
- private $metaPriority = Array(
- 20 => Array( 'other' ),
- 40 => Array( 'native' ),
- 60 => Array( 'iptc-good-hash', 'iptc-no-hash' ),
- 70 => Array( 'xmp-deprecated' ),
- 80 => Array( 'xmp-general' ),
- 90 => Array( 'xmp-exif' ),
- 100 => Array( 'iptc-bad-hash' ),
- 120 => Array( 'exif' ),
+ private $metadata = array();
+ private $metaPriority = array(
+ 20 => array( 'other' ),
+ 40 => array( 'native' ),
+ 60 => array( 'iptc-good-hash', 'iptc-no-hash' ),
+ 70 => array( 'xmp-deprecated' ),
+ 80 => array( 'xmp-general' ),
+ 90 => array( 'xmp-exif' ),
+ 100 => array( 'iptc-bad-hash' ),
+ 120 => array( 'exif' ),
);
private $iptcType = 'iptc-no-hash';
}
}
+ /**
+ * @param $in
+ * @return bool
+ */
private function isASCII( $in ) {
if ( is_array( $in ) ) {
return false;
return true;
}
+ /**
+ * @param $in
+ * @return bool
+ */
private function isShort( $in ) {
if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
$this->debug( $in, __FUNCTION__, true );
}
}
+ /**
+ * @param $in
+ * @return bool
+ */
private function isLong( $in ) {
if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
$this->debug( $in, __FUNCTION__, true );
}
}
+ /**
+ * @param $in
+ * @return bool
+ */
private function isRational( $in ) {
$m = array();
if ( !is_array( $in ) && @preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
}
}
+ /**
+ * @param $in
+ * @return bool
+ */
private function isUndefined( $in ) {
-
$this->debug( $in, __FUNCTION__, true );
return true;
-
- /* Exif::UNDEFINED means string of bytes
- so this validation does not make sense.
- comment out for now.
- if ( !is_array( $in ) && preg_match( '/^\d{4}$/', $in ) ) { // Allow ExifVersion and FlashpixVersion
- $this->debug( $in, __FUNCTION__, true );
- return true;
- } else {
- $this->debug( $in, __FUNCTION__, false );
- return false;
- }
- */
}
+ /**
+ * @param $in
+ * @return bool
+ */
private function isSlong( $in ) {
if ( $this->isLong( abs( $in ) ) ) {
$this->debug( $in, __FUNCTION__, true );
}
}
+ /**
+ * @param $in
+ * @return bool
+ */
private function isSrational( $in ) {
$m = array();
if ( !is_array( $in ) && preg_match( '/^(-?\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
}
$type = gettype( $in );
$class = ucfirst( __CLASS__ );
- if ( $type === 'array' )
+ if ( $type === 'array' ) {
$in = print_r( $in, true );
+ }
- if ( $action === true )
+ if ( $action === true ) {
wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n");
- elseif ( $action === false )
+ } elseif ( $action === false ) {
wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n");
- elseif ( $action === null )
+ } elseif ( $action === null ) {
wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)\n");
- else
+ } else {
wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')\n");
+ }
}
/**
}
break;
-
-
// This is not in the Exif standard, just a special
// case for our purposes which enables wikis to wikify
// the make, model and software name to link to their articles.
* Format a coordinate value, convert numbers from floating point
* into degree minute second representation.
*
- * @private
- *
* @param $coords Array: degrees, minutes and seconds
* @param $type String: latitude or longitude (for if its a NWS or E)
* @return mixed A floating point number or whatever we were fed
wfDeprecated(__METHOD__);
$this->meta = $meta;
}
+
function getFormattedData ( ) {
return FormatMetadata::getFormattedData( $this->meta );
}
-
}
} else {
$data['Software'] = $software;
}
-
-
break;
case '2#075':
/* Object cycle.
// most of the time if there is no 1:90 tag, it is either ascii, latin1, or utf-8
$oldData = $data;
UtfNormal::quickIsNFCVerify( $data ); //make $data valid utf-8
- if ($data === $oldData) return $data; //if validation didn't change $data
- else return self::convIPTCHelper ( $oldData, 'Windows-1252' );
+ if ($data === $oldData) {
+ return $data; //if validation didn't change $data
+ } else {
+ return self::convIPTCHelper ( $oldData, 'Windows-1252' );
+ }
}
return trim( $data );
}
}
return $this->formatMetadataHelper( $exif );
}
-
-
}
* Based somewhat on GIFMetadataExtrator.
*/
class JpegMetadataExtractor {
+
const MAX_JPEG_SEGMENTS = 200;
// the max segment is a sanity check.
// A jpeg file should never even remotely have
$segmentCount = 0;
- $segments = Array( 'XMP_ext' => array(), 'COM' => array() );
+ $segments = array( 'XMP_ext' => array(), 'COM' => array() );
- if ( !$filename ) throw new MWException( "No filename specified for " . __METHOD__ );
- if ( !file_exists( $filename ) || is_dir( $filename ) ) throw new MWException( "Invalid file $filename passed to " . __METHOD__ );
+ if ( !$filename ) {
+ throw new MWException( "No filename specified for " . __METHOD__ );
+ }
+ if ( !file_exists( $filename ) || is_dir( $filename ) ) {
+ throw new MWException( "Invalid file $filename passed to " . __METHOD__ );
+ }
$fh = fopen( $filename, "rb" );
- if ( !$fh ) throw new MWException( "Could not open file $filename" );
+ if ( !$fh ) {
+ throw new MWException( "Could not open file $filename" );
+ }
$buffer = fread( $fh, 2 );
- if ( $buffer !== "\xFF\xD8" ) throw new MWException( "Not a jpeg, no SOI" );
+ if ( $buffer !== "\xFF\xD8" ) {
+ throw new MWException( "Not a jpeg, no SOI" );
+ }
while ( !feof( $fh ) ) {
$buffer = fread( $fh, 1 );
$segmentCount++;
* @return String if the iptc hash is good or not.
*/
public static function doPSIR ( $app13 ) {
- if ( !$app13 ) return;
+ if ( !$app13 ) {
+ return;
+ }
// First compare hash with real thing
// 0x404 contains IPTC, 0x425 has hash
// This is used to determine if the iptc is newer than
$lenName = ord( substr( $app13, $offset, 1 ) ) + 1;
// we never use the name so skip it. +1 for length byte
- if ( $lenName % 2 == 1 ) $lenName++; // pad to even.
+ if ( $lenName % 2 == 1 ) {
+ $lenName++;
+ } // pad to even.
$offset += $lenName;
// now length of data (unsigned long big endian)
$info = array();
$info[] = $original;
- if ($metadata['loopCount'] == 0)
+ if ( $metadata['loopCount'] == 0 ) {
$info[] = wfMsgExt( 'file-info-png-looped', 'parseinline' );
- elseif ($metadata['loopCount'] > 1)
+ } elseif ( $metadata['loopCount'] > 1 ) {
$info[] = wfMsgExt( 'file-info-png-repeat', 'parseinline', $metadata['loopCount'] );
+ }
- if ($metadata['frameCount'] > 0)
+ if ( $metadata['frameCount'] > 0 ) {
$info[] = wfMsgExt( 'file-info-png-frames', 'parseinline', $metadata['frameCount'] );
+ }
- if ($metadata['duration'])
+ if ( $metadata['duration'] ) {
$info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
+ }
return $wgLang->commaList( $info );
}
// or programs that make such files..
$guid = substr( $content, 0, 32 );
if ( !isset( $this->results['xmp-special']['HasExtendedXMP'] )
- || $this->results['xmp-special']['HasExtendedXMP'] !== $guid )
- {
+ || $this->results['xmp-special']['HasExtendedXMP'] !== $guid ) {
wfDebugLog('XMP', __METHOD__ . " Ignoring XMPExtended block due to wrong guid (guid= '$guid' )");
- return;
+ return false;
}
$len = unpack( 'Nlength/Noffset', substr( $content, 32, 8 ) );
}
}
-
/**
* Hit an opening element while in MODE_IGNORE
*
array_unshift( $this->mode, self::MODE_IGNORE );
}
}
+
/**
* Start element in MODE_BAG (unordered array)
* this should always be <rdf:Bag>
}
}
+
/**
* Start element in MODE_SEQ (ordered array)
* this should always be <rdf:Seq>
}
}
+
/**
* Start element in MODE_LANG (language alternative)
* this should always be <rdf:Alt>
}
}
+
/**
* Handle an opening element when in MODE_SIMPLE
*
}
}
+
/**
* Start an element when in MODE_QDESC.
* This generally happens when a simple element has an inner
array_unshift( $this->curItem, $elm );
}
}
+
/**
* Starting an element when in MODE_INITIAL
* This usually happens when we hit an element inside
// process attributes
$this->doAttribs( $attribs );
}
+
/**
* Hit an opening element when in a Struct (MODE_STRUCT)
* This is generally for fields of a compound property.
array_unshift( $this->curItem, $this->curItem[0] );
}
}
+
/**
* opening element in MODE_LI
* process elements of arrays.
}
}
+
/**
* Opening element in MODE_LI_LANG.
* process elements of language alternatives
throw new MWException( 'StartElement in unknown mode: ' . $this->mode[0] );
break;
}
-
-
-
}
/**
* Process attributes.
$this->results['xmp-' . $info['map_group']][$finalName] = $val;
}
}
-
-
}
}
}
+
/**
* function to validate rational properties ( 12/10 )
*
}
}
+
/**
* function to validate rating properties -1, 0-5
*
}
}
}
+
/**
* function to validate integers
*
}
}
+
/**
* function to validate properties with a fixed number of allowed
* choices. (closed choice)
$val = null;
}
}
+
/**
* function to validate and modify flash structure
*
| ( ( $val['RedEyeMode'] === 'True' ) << 6 ) );
}
}
+
/**
* function to validate LangCode properties ( en-GB, etc )
*
}
}
+
/**
* function to validate date properties, and convert to Exif format.
*
}
}
+
/** function to validate, and more importantly
* translate the XMP DMS form of gps coords to
* the decimal form we use.
$val = null;
return;
}
-
}
-
}