r86307 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86306‎ | r86307 | r86308 >
Date:13:08, 18 April 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Few style/whitespace/comment issues from r86169
Modified paths:
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)
  • /trunk/phase3/includes/media/BitmapMetadataHandler.php (modified) (history)
  • /trunk/phase3/includes/media/Exif.php (modified) (history)
  • /trunk/phase3/includes/media/FormatMetadata.php (modified) (history)
  • /trunk/phase3/includes/media/IPTC.php (modified) (history)
  • /trunk/phase3/includes/media/Jpeg.php (modified) (history)
  • /trunk/phase3/includes/media/JpegMetadataExtractor.php (modified) (history)
  • /trunk/phase3/includes/media/PNG.php (modified) (history)
  • /trunk/phase3/includes/media/XMP.php (modified) (history)
  • /trunk/phase3/includes/media/XMPValidate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/File.php
@@ -312,12 +312,12 @@
313313 */
314314 public function convertMetadataVersion($metadata, $version) {
315315 $handler = $this->getHandler();
316 - if (!is_array($metadata)) {
 316+ if ( !is_array( $metadata ) ) {
317317 //just to make the return type consistant
318318 $metadata = unserialize( $metadata );
319319 }
320320 if ( $handler ) {
321 - return $handler->convertMetadataVersion($metadata, $version);
 321+ return $handler->convertMetadataVersion( $metadata, $version );
322322 } else {
323323 return $metadata;
324324 }
Index: trunk/phase3/includes/media/FormatMetadata.php
@@ -567,8 +567,6 @@
568568 }
569569 break;
570570
571 -
572 -
573571 // This is not in the Exif standard, just a special
574572 // case for our purposes which enables wikis to wikify
575573 // the make, model and software name to link to their articles.
@@ -1171,8 +1169,6 @@
11721170 * Format a coordinate value, convert numbers from floating point
11731171 * into degree minute second representation.
11741172 *
1175 - * @private
1176 - *
11771173 * @param $coords Array: degrees, minutes and seconds
11781174 * @param $type String: latitude or longitude (for if its a NWS or E)
11791175 * @return mixed A floating point number or whatever we were fed
@@ -1345,8 +1341,8 @@
13461342 wfDeprecated(__METHOD__);
13471343 $this->meta = $meta;
13481344 }
 1345+
13491346 function getFormattedData ( ) {
13501347 return FormatMetadata::getFormattedData( $this->meta );
13511348 }
1352 -
13531349 }
Index: trunk/phase3/includes/media/Exif.php
@@ -584,6 +584,10 @@
585585 }
586586 }
587587
 588+ /**
 589+ * @param $in
 590+ * @return bool
 591+ */
588592 private function isASCII( $in ) {
589593 if ( is_array( $in ) ) {
590594 return false;
@@ -602,6 +606,10 @@
603607 return true;
604608 }
605609
 610+ /**
 611+ * @param $in
 612+ * @return bool
 613+ */
606614 private function isShort( $in ) {
607615 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
608616 $this->debug( $in, __FUNCTION__, true );
@@ -612,6 +620,10 @@
613621 }
614622 }
615623
 624+ /**
 625+ * @param $in
 626+ * @return bool
 627+ */
616628 private function isLong( $in ) {
617629 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
618630 $this->debug( $in, __FUNCTION__, true );
@@ -622,6 +634,10 @@
623635 }
624636 }
625637
 638+ /**
 639+ * @param $in
 640+ * @return bool
 641+ */
626642 private function isRational( $in ) {
627643 $m = array();
628644 if ( !is_array( $in ) && @preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
@@ -632,24 +648,19 @@
633649 }
634650 }
635651
 652+ /**
 653+ * @param $in
 654+ * @return bool
 655+ */
636656 private function isUndefined( $in ) {
637 -
638657 $this->debug( $in, __FUNCTION__, true );
639658 return true;
640 -
641 - /* Exif::UNDEFINED means string of bytes
642 - so this validation does not make sense.
643 - comment out for now.
644 - if ( !is_array( $in ) && preg_match( '/^\d{4}$/', $in ) ) { // Allow ExifVersion and FlashpixVersion
645 - $this->debug( $in, __FUNCTION__, true );
646 - return true;
647 - } else {
648 - $this->debug( $in, __FUNCTION__, false );
649 - return false;
650 - }
651 - */
652659 }
653660
 661+ /**
 662+ * @param $in
 663+ * @return bool
 664+ */
654665 private function isSlong( $in ) {
655666 if ( $this->isLong( abs( $in ) ) ) {
656667 $this->debug( $in, __FUNCTION__, true );
@@ -660,6 +671,10 @@
661672 }
662673 }
663674
 675+ /**
 676+ * @param $in
 677+ * @return bool
 678+ */
664679 private function isSrational( $in ) {
665680 $m = array();
666681 if ( !is_array( $in ) && preg_match( '/^(-?\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
@@ -756,17 +771,19 @@
757772 }
758773 $type = gettype( $in );
759774 $class = ucfirst( __CLASS__ );
760 - if ( $type === 'array' )
 775+ if ( $type === 'array' ) {
761776 $in = print_r( $in, true );
 777+ }
762778
763 - if ( $action === true )
 779+ if ( $action === true ) {
764780 wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n");
765 - elseif ( $action === false )
 781+ } elseif ( $action === false ) {
766782 wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n");
767 - elseif ( $action === null )
 783+ } elseif ( $action === null ) {
768784 wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)\n");
769 - else
 785+ } else {
770786 wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')\n");
 787+ }
771788 }
772789
773790 /**
Index: trunk/phase3/includes/media/IPTC.php
@@ -157,8 +157,6 @@
158158 } else {
159159 $data['Software'] = $software;
160160 }
161 -
162 -
163161 break;
164162 case '2#075':
165163 /* Object cycle.
@@ -430,8 +428,11 @@
431429 // most of the time if there is no 1:90 tag, it is either ascii, latin1, or utf-8
432430 $oldData = $data;
433431 UtfNormal::quickIsNFCVerify( $data ); //make $data valid utf-8
434 - if ($data === $oldData) return $data; //if validation didn't change $data
435 - else return self::convIPTCHelper ( $oldData, 'Windows-1252' );
 432+ if ($data === $oldData) {
 433+ return $data; //if validation didn't change $data
 434+ } else {
 435+ return self::convIPTCHelper ( $oldData, 'Windows-1252' );
 436+ }
436437 }
437438 return trim( $data );
438439 }
Index: trunk/phase3/includes/media/XMP.php
@@ -296,10 +296,9 @@
297297 // or programs that make such files..
298298 $guid = substr( $content, 0, 32 );
299299 if ( !isset( $this->results['xmp-special']['HasExtendedXMP'] )
300 - || $this->results['xmp-special']['HasExtendedXMP'] !== $guid )
301 - {
 300+ || $this->results['xmp-special']['HasExtendedXMP'] !== $guid ) {
302301 wfDebugLog('XMP', __METHOD__ . " Ignoring XMPExtended block due to wrong guid (guid= '$guid' )");
303 - return;
 302+ return false;
304303 }
305304 $len = unpack( 'Nlength/Noffset', substr( $content, 32, 8 ) );
306305
@@ -646,7 +645,6 @@
647646 }
648647 }
649648
650 -
651649 /**
652650 * Hit an opening element while in MODE_IGNORE
653651 *
@@ -664,6 +662,7 @@
665663 array_unshift( $this->mode, self::MODE_IGNORE );
666664 }
667665 }
 666+
668667 /**
669668 * Start element in MODE_BAG (unordered array)
670669 * this should always be <rdf:Bag>
@@ -679,6 +678,7 @@
680679 }
681680
682681 }
 682+
683683 /**
684684 * Start element in MODE_SEQ (ordered array)
685685 * this should always be <rdf:Seq>
@@ -699,6 +699,7 @@
700700 }
701701
702702 }
 703+
703704 /**
704705 * Start element in MODE_LANG (language alternative)
705706 * this should always be <rdf:Alt>
@@ -721,6 +722,7 @@
722723 }
723724
724725 }
 726+
725727 /**
726728 * Handle an opening element when in MODE_SIMPLE
727729 *
@@ -761,6 +763,7 @@
762764 }
763765
764766 }
 767+
765768 /**
766769 * Start an element when in MODE_QDESC.
767770 * This generally happens when a simple element has an inner
@@ -784,6 +787,7 @@
785788 array_unshift( $this->curItem, $elm );
786789 }
787790 }
 791+
788792 /**
789793 * Starting an element when in MODE_INITIAL
790794 * This usually happens when we hit an element inside
@@ -836,6 +840,7 @@
837841 // process attributes
838842 $this->doAttribs( $attribs );
839843 }
 844+
840845 /**
841846 * Hit an opening element when in a Struct (MODE_STRUCT)
842847 * This is generally for fields of a compound property.
@@ -887,6 +892,7 @@
888893 array_unshift( $this->curItem, $this->curItem[0] );
889894 }
890895 }
 896+
891897 /**
892898 * opening element in MODE_LI
893899 * process elements of arrays.
@@ -937,6 +943,7 @@
938944 }
939945
940946 }
 947+
941948 /**
942949 * Opening element in MODE_LI_LANG.
943950 * process elements of language alternatives
@@ -1055,9 +1062,6 @@
10561063 throw new MWException( 'StartElement in unknown mode: ' . $this->mode[0] );
10571064 break;
10581065 }
1059 -
1060 -
1061 -
10621066 }
10631067 /**
10641068 * Process attributes.
@@ -1162,6 +1166,4 @@
11631167 $this->results['xmp-' . $info['map_group']][$finalName] = $val;
11641168 }
11651169 }
1166 -
1167 -
11681170 }
Index: trunk/phase3/includes/media/BitmapMetadataHandler.php
@@ -10,16 +10,16 @@
1111 */
1212 class BitmapMetadataHandler {
1313
14 - private $metadata = Array();
15 - private $metaPriority = Array(
16 - 20 => Array( 'other' ),
17 - 40 => Array( 'native' ),
18 - 60 => Array( 'iptc-good-hash', 'iptc-no-hash' ),
19 - 70 => Array( 'xmp-deprecated' ),
20 - 80 => Array( 'xmp-general' ),
21 - 90 => Array( 'xmp-exif' ),
22 - 100 => Array( 'iptc-bad-hash' ),
23 - 120 => Array( 'exif' ),
 14+ private $metadata = array();
 15+ private $metaPriority = array(
 16+ 20 => array( 'other' ),
 17+ 40 => array( 'native' ),
 18+ 60 => array( 'iptc-good-hash', 'iptc-no-hash' ),
 19+ 70 => array( 'xmp-deprecated' ),
 20+ 80 => array( 'xmp-general' ),
 21+ 90 => array( 'xmp-exif' ),
 22+ 100 => array( 'iptc-bad-hash' ),
 23+ 120 => array( 'exif' ),
2424 );
2525 private $iptcType = 'iptc-no-hash';
2626
Index: trunk/phase3/includes/media/XMPValidate.php
@@ -37,6 +37,7 @@
3838 }
3939
4040 }
 41+
4142 /**
4243 * function to validate rational properties ( 12/10 )
4344 *
@@ -55,6 +56,7 @@
5657 }
5758
5859 }
 60+
5961 /**
6062 * function to validate rating properties -1, 0-5
6163 *
@@ -93,6 +95,7 @@
9496 }
9597 }
9698 }
 99+
97100 /**
98101 * function to validate integers
99102 *
@@ -111,6 +114,7 @@
112115 }
113116
114117 }
 118+
115119 /**
116120 * function to validate properties with a fixed number of allowed
117121 * choices. (closed choice)
@@ -141,6 +145,7 @@
142146 $val = null;
143147 }
144148 }
 149+
145150 /**
146151 * function to validate and modify flash structure
147152 *
@@ -169,6 +174,7 @@
170175 | ( ( $val['RedEyeMode'] === 'True' ) << 6 ) );
171176 }
172177 }
 178+
173179 /**
174180 * function to validate LangCode properties ( en-GB, etc )
175181 *
@@ -193,6 +199,7 @@
194200 }
195201
196202 }
 203+
197204 /**
198205 * function to validate date properties, and convert to Exif format.
199206 *
@@ -263,6 +270,7 @@
264271 }
265272
266273 }
 274+
267275 /** function to validate, and more importantly
268276 * translate the XMP DMS form of gps coords to
269277 * the decimal form we use.
@@ -311,7 +319,5 @@
312320 $val = null;
313321 return;
314322 }
315 -
316323 }
317 -
318324 }
Index: trunk/phase3/includes/media/JpegMetadataExtractor.php
@@ -6,6 +6,7 @@
77 * Based somewhat on GIFMetadataExtrator.
88 */
99 class JpegMetadataExtractor {
 10+
1011 const MAX_JPEG_SEGMENTS = 200;
1112 // the max segment is a sanity check.
1213 // A jpeg file should never even remotely have
@@ -27,17 +28,25 @@
2829
2930 $segmentCount = 0;
3031
31 - $segments = Array( 'XMP_ext' => array(), 'COM' => array() );
 32+ $segments = array( 'XMP_ext' => array(), 'COM' => array() );
3233
33 - if ( !$filename ) throw new MWException( "No filename specified for " . __METHOD__ );
34 - if ( !file_exists( $filename ) || is_dir( $filename ) ) throw new MWException( "Invalid file $filename passed to " . __METHOD__ );
 34+ if ( !$filename ) {
 35+ throw new MWException( "No filename specified for " . __METHOD__ );
 36+ }
 37+ if ( !file_exists( $filename ) || is_dir( $filename ) ) {
 38+ throw new MWException( "Invalid file $filename passed to " . __METHOD__ );
 39+ }
3540
3641 $fh = fopen( $filename, "rb" );
3742
38 - if ( !$fh ) throw new MWException( "Could not open file $filename" );
 43+ if ( !$fh ) {
 44+ throw new MWException( "Could not open file $filename" );
 45+ }
3946
4047 $buffer = fread( $fh, 2 );
41 - if ( $buffer !== "\xFF\xD8" ) throw new MWException( "Not a jpeg, no SOI" );
 48+ if ( $buffer !== "\xFF\xD8" ) {
 49+ throw new MWException( "Not a jpeg, no SOI" );
 50+ }
4251 while ( !feof( $fh ) ) {
4352 $buffer = fread( $fh, 1 );
4453 $segmentCount++;
@@ -136,7 +145,9 @@
137146 * @return String if the iptc hash is good or not.
138147 */
139148 public static function doPSIR ( $app13 ) {
140 - if ( !$app13 ) return;
 149+ if ( !$app13 ) {
 150+ return;
 151+ }
141152 // First compare hash with real thing
142153 // 0x404 contains IPTC, 0x425 has hash
143154 // This is used to determine if the iptc is newer than
@@ -171,7 +182,9 @@
172183
173184 $lenName = ord( substr( $app13, $offset, 1 ) ) + 1;
174185 // we never use the name so skip it. +1 for length byte
175 - if ( $lenName % 2 == 1 ) $lenName++; // pad to even.
 186+ if ( $lenName % 2 == 1 ) {
 187+ $lenName++;
 188+ } // pad to even.
176189 $offset += $lenName;
177190
178191 // now length of data (unsigned long big endian)
Index: trunk/phase3/includes/media/PNG.php
@@ -109,16 +109,19 @@
110110 $info = array();
111111 $info[] = $original;
112112
113 - if ($metadata['loopCount'] == 0)
 113+ if ( $metadata['loopCount'] == 0 ) {
114114 $info[] = wfMsgExt( 'file-info-png-looped', 'parseinline' );
115 - elseif ($metadata['loopCount'] > 1)
 115+ } elseif ( $metadata['loopCount'] > 1 ) {
116116 $info[] = wfMsgExt( 'file-info-png-repeat', 'parseinline', $metadata['loopCount'] );
 117+ }
117118
118 - if ($metadata['frameCount'] > 0)
 119+ if ( $metadata['frameCount'] > 0 ) {
119120 $info[] = wfMsgExt( 'file-info-png-frames', 'parseinline', $metadata['frameCount'] );
 121+ }
120122
121 - if ($metadata['duration'])
 123+ if ( $metadata['duration'] ) {
122124 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
 125+ }
123126
124127 return $wgLang->commaList( $info );
125128 }
Index: trunk/phase3/includes/media/Jpeg.php
@@ -135,6 +135,4 @@
136136 }
137137 return $this->formatMetadataHelper( $exif );
138138 }
139 -
140 -
141139 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86169Merge to trunk everything in img_metadata branch....bawolff01:23, 16 April 2011

Comments

#Comment by Hashar (talk | contribs)   19:33, 7 June 2011

commented code removed in Exif->isUndefined() Maybe we should keep it around.

Status & tagging log