* @see http://exif.org/Exif2-2.PDF The Exif 2.2 specification
* @file
*/
+use MediaWiki\MediaWikiServices;
+use Wikimedia\Timestamp\TimestampException;
/**
* Format Image metadata values into a human readable form.
unset( $tags['ResolutionUnit'] );
foreach ( $tags as $tag => &$vals ) {
-
// This seems ugly to wrap non-array's in an array just to unwrap again,
// especially when most of the time it is not an array
if ( !is_array( $tags[$tag] ) ) {
- $vals = array( $vals );
+ $vals = [ $vals ];
}
// _type is a special value to say what array type
}
foreach ( $vals as &$val ) {
-
switch ( $tag ) {
case 'Compression':
switch ( $val ) {
break;
case 'Flash':
- $flashDecode = array(
- 'fired' => $val & bindec( '00000001' ),
- 'return' => ( $val & bindec( '00000110' ) ) >> 1,
- 'mode' => ( $val & bindec( '00011000' ) ) >> 3,
- 'function' => ( $val & bindec( '00100000' ) ) >> 5,
- 'redeye' => ( $val & bindec( '01000000' ) ) >> 6,
-// 'reserved' => ($val & bindec( '10000000' )) >> 7,
- );
- $flashMsgs = array();
+ $flashDecode = [
+ 'fired' => $val & 0b00000001,
+ 'return' => ( $val & 0b00000110 ) >> 1,
+ 'mode' => ( $val & 0b00011000 ) >> 3,
+ 'function' => ( $val & 0b00100000 ) >> 5,
+ 'redeye' => ( $val & 0b01000000 ) >> 6,
+ // 'reserved' => ( $val & 0b10000000 ) >> 7,
+ ];
+ $flashMsgs = [];
# We do not need to handle unknown values since all are used.
foreach ( $flashDecode as $subTag => $subValue ) {
# We do not need any message for zeroed values.
// are included here as we really don't want
// commas inserted.
case 'ImageDescription':
+ case 'UserComment':
case 'Artist':
case 'Copyright':
case 'RelatedSoundFile':
if ( $this->singleLang ) {
return Html::rawElement( 'span',
- array( 'lang' => $pLang ), $vals[$pLang] );
+ [ 'lang' => $pLang ], $vals[$pLang] );
}
}
}
$lang, false, $noHtml );
if ( $this->singleLang ) {
return Html::rawElement( 'span',
- array( 'lang' => $lang ), $item );
+ [ 'lang' => $lang ], $item );
}
}
if ( $defaultItem !== false ) {
* @return mixed A floating point number or whatever we were fed
*/
private function formatNum( $num, $round = false ) {
- $m = array();
+ $m = [];
if ( is_array( $num ) ) {
- $out = array();
+ $out = [];
foreach ( $num as $number ) {
$out[] = $this->formatNum( $number );
}
* @return mixed A floating point number or whatever we were fed
*/
private function formatFraction( $num ) {
- $m = array();
+ $m = [];
if ( preg_match( '/^(-?\d+)\/(\d+)$/', $num, $m ) ) {
$numerator = intval( $m[1] );
$denominator = intval( $m[2] );
. '</span>';
}
if ( isset( $vals['CiEmailWork'] ) ) {
- $emails = array();
+ $emails = [];
// Have to split multiple emails at commas/new lines.
$splitEmails = explode( "\n", $vals['CiEmailWork'] );
foreach ( $splitEmails as $e1 ) {
* @since 1.23
*/
public static function getVisibleFields() {
- $fields = array();
+ $fields = [];
$lines = explode( "\n", wfMessage( 'metadata-fields' )->inContentLanguage()->text() );
foreach ( $lines as $line ) {
- $matches = array();
+ $matches = [];
if ( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) {
$fields[] = $matches[1];
}
* @since 1.23
*/
public function fetchExtendedMetadata( File $file ) {
- $cache = ObjectCache::getMainWANInstance();
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
// If revision deleted, exit immediately
if ( $file->isDeleted( File::DELETED_FILE ) ) {
- return array();
+ return [];
}
- $cacheKey = wfMemcKey(
+ $cacheKey = $cache->makeKey(
'getExtendedMetadata',
$this->getLanguage()->getCode(),
(int)$this->singleLang,
$cachedValue = $cache->get( $cacheKey );
if (
$cachedValue
- && Hooks::run( 'ValidateExtendedMetadataCache', array( $cachedValue['timestamp'], $file ) )
+ && Hooks::run( 'ValidateExtendedMetadataCache', [ $cachedValue['timestamp'], $file ] )
) {
$extendedMetadata = $cachedValue['data'];
} else {
// outside fetchExtendedMetadata, but this way we don't need to redo the
// computation on a cache hit.
$this->sanitizeArrayForAPI( $extendedMetadata );
- $valueToCache = array( 'data' => $extendedMetadata, 'timestamp' => wfTimestampNow() );
+ $valueToCache = [ 'data' => $extendedMetadata, 'timestamp' => wfTimestampNow() ];
$cache->set( $cacheKey, $valueToCache, $maxCacheTime );
}
if ( $file instanceof ForeignAPIFile ) {
// In case of error we pretend no metadata - this will get cached.
// Might or might not be a good idea.
- return $file->getExtendedMetadata() ?: array();
+ return $file->getExtendedMetadata() ?: [];
}
$uploadDate = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
- $fileMetadata = array(
+ $fileMetadata = [
// This is modification time, which is close to "upload" time.
- 'DateTime' => array(
+ 'DateTime' => [
'value' => $uploadDate,
'source' => 'mediawiki-metadata',
- ),
- );
+ ],
+ ];
$title = $file->getTitle();
if ( $title ) {
$name = $text;
}
- $fileMetadata['ObjectName'] = array(
+ $fileMetadata['ObjectName'] = [
'value' => $name,
'source' => 'mediawiki-metadata',
- );
+ ];
}
return $fileMetadata;
protected function getExtendedMetadataFromHook( File $file, array $extendedMetadata,
&$maxCacheTime
) {
-
- Hooks::run( 'GetExtendedMetadata', array(
+ Hooks::run( 'GetExtendedMetadata', [
&$extendedMetadata,
$file,
$this->getContext(),
$this->singleLang,
&$maxCacheTime
- ) );
+ ] );
$visible = array_flip( self::getVisibleFields() );
foreach ( $extendedMetadata as $key => $value ) {
return $value;
} elseif ( isset( $value['_type'] ) && $value['_type'] === 'lang' ) {
// if this is a multilang array, process fields separately
- $newValue = array();
+ $newValue = [];
foreach ( $value as $k => $v ) {
$newValue[$k] = $this->resolveMultivalueValue( $v );
}
$field['value'] = $this->resolveMultivalueValue( $field['value'] );
}
}
-
}
/**