Index: trunk/phase3/includes/filerepo/File.php |
— | — | @@ -312,12 +312,12 @@ |
313 | 313 | */ |
314 | 314 | public function convertMetadataVersion($metadata, $version) { |
315 | 315 | $handler = $this->getHandler(); |
316 | | - if (!is_array($metadata)) { |
| 316 | + if ( !is_array( $metadata ) ) { |
317 | 317 | //just to make the return type consistant |
318 | 318 | $metadata = unserialize( $metadata ); |
319 | 319 | } |
320 | 320 | if ( $handler ) { |
321 | | - return $handler->convertMetadataVersion($metadata, $version); |
| 321 | + return $handler->convertMetadataVersion( $metadata, $version ); |
322 | 322 | } else { |
323 | 323 | return $metadata; |
324 | 324 | } |
Index: trunk/phase3/includes/media/FormatMetadata.php |
— | — | @@ -567,8 +567,6 @@ |
568 | 568 | } |
569 | 569 | break; |
570 | 570 | |
571 | | - |
572 | | - |
573 | 571 | // This is not in the Exif standard, just a special |
574 | 572 | // case for our purposes which enables wikis to wikify |
575 | 573 | // the make, model and software name to link to their articles. |
— | — | @@ -1171,8 +1169,6 @@ |
1172 | 1170 | * Format a coordinate value, convert numbers from floating point |
1173 | 1171 | * into degree minute second representation. |
1174 | 1172 | * |
1175 | | - * @private |
1176 | | - * |
1177 | 1173 | * @param $coords Array: degrees, minutes and seconds |
1178 | 1174 | * @param $type String: latitude or longitude (for if its a NWS or E) |
1179 | 1175 | * @return mixed A floating point number or whatever we were fed |
— | — | @@ -1345,8 +1341,8 @@ |
1346 | 1342 | wfDeprecated(__METHOD__); |
1347 | 1343 | $this->meta = $meta; |
1348 | 1344 | } |
| 1345 | + |
1349 | 1346 | function getFormattedData ( ) { |
1350 | 1347 | return FormatMetadata::getFormattedData( $this->meta ); |
1351 | 1348 | } |
1352 | | - |
1353 | 1349 | } |
Index: trunk/phase3/includes/media/Exif.php |
— | — | @@ -584,6 +584,10 @@ |
585 | 585 | } |
586 | 586 | } |
587 | 587 | |
| 588 | + /** |
| 589 | + * @param $in |
| 590 | + * @return bool |
| 591 | + */ |
588 | 592 | private function isASCII( $in ) { |
589 | 593 | if ( is_array( $in ) ) { |
590 | 594 | return false; |
— | — | @@ -602,6 +606,10 @@ |
603 | 607 | return true; |
604 | 608 | } |
605 | 609 | |
| 610 | + /** |
| 611 | + * @param $in |
| 612 | + * @return bool |
| 613 | + */ |
606 | 614 | private function isShort( $in ) { |
607 | 615 | if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) { |
608 | 616 | $this->debug( $in, __FUNCTION__, true ); |
— | — | @@ -612,6 +620,10 @@ |
613 | 621 | } |
614 | 622 | } |
615 | 623 | |
| 624 | + /** |
| 625 | + * @param $in |
| 626 | + * @return bool |
| 627 | + */ |
616 | 628 | private function isLong( $in ) { |
617 | 629 | if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) { |
618 | 630 | $this->debug( $in, __FUNCTION__, true ); |
— | — | @@ -622,6 +634,10 @@ |
623 | 635 | } |
624 | 636 | } |
625 | 637 | |
| 638 | + /** |
| 639 | + * @param $in |
| 640 | + * @return bool |
| 641 | + */ |
626 | 642 | private function isRational( $in ) { |
627 | 643 | $m = array(); |
628 | 644 | if ( !is_array( $in ) && @preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero |
— | — | @@ -632,24 +648,19 @@ |
633 | 649 | } |
634 | 650 | } |
635 | 651 | |
| 652 | + /** |
| 653 | + * @param $in |
| 654 | + * @return bool |
| 655 | + */ |
636 | 656 | private function isUndefined( $in ) { |
637 | | - |
638 | 657 | $this->debug( $in, __FUNCTION__, true ); |
639 | 658 | 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 | | - */ |
652 | 659 | } |
653 | 660 | |
| 661 | + /** |
| 662 | + * @param $in |
| 663 | + * @return bool |
| 664 | + */ |
654 | 665 | private function isSlong( $in ) { |
655 | 666 | if ( $this->isLong( abs( $in ) ) ) { |
656 | 667 | $this->debug( $in, __FUNCTION__, true ); |
— | — | @@ -660,6 +671,10 @@ |
661 | 672 | } |
662 | 673 | } |
663 | 674 | |
| 675 | + /** |
| 676 | + * @param $in |
| 677 | + * @return bool |
| 678 | + */ |
664 | 679 | private function isSrational( $in ) { |
665 | 680 | $m = array(); |
666 | 681 | if ( !is_array( $in ) && preg_match( '/^(-?\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero |
— | — | @@ -756,17 +771,19 @@ |
757 | 772 | } |
758 | 773 | $type = gettype( $in ); |
759 | 774 | $class = ucfirst( __CLASS__ ); |
760 | | - if ( $type === 'array' ) |
| 775 | + if ( $type === 'array' ) { |
761 | 776 | $in = print_r( $in, true ); |
| 777 | + } |
762 | 778 | |
763 | | - if ( $action === true ) |
| 779 | + if ( $action === true ) { |
764 | 780 | wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n"); |
765 | | - elseif ( $action === false ) |
| 781 | + } elseif ( $action === false ) { |
766 | 782 | wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n"); |
767 | | - elseif ( $action === null ) |
| 783 | + } elseif ( $action === null ) { |
768 | 784 | wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)\n"); |
769 | | - else |
| 785 | + } else { |
770 | 786 | wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')\n"); |
| 787 | + } |
771 | 788 | } |
772 | 789 | |
773 | 790 | /** |
Index: trunk/phase3/includes/media/IPTC.php |
— | — | @@ -157,8 +157,6 @@ |
158 | 158 | } else { |
159 | 159 | $data['Software'] = $software; |
160 | 160 | } |
161 | | - |
162 | | - |
163 | 161 | break; |
164 | 162 | case '2#075': |
165 | 163 | /* Object cycle. |
— | — | @@ -430,8 +428,11 @@ |
431 | 429 | // most of the time if there is no 1:90 tag, it is either ascii, latin1, or utf-8 |
432 | 430 | $oldData = $data; |
433 | 431 | 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 | + } |
436 | 437 | } |
437 | 438 | return trim( $data ); |
438 | 439 | } |
Index: trunk/phase3/includes/media/XMP.php |
— | — | @@ -296,10 +296,9 @@ |
297 | 297 | // or programs that make such files.. |
298 | 298 | $guid = substr( $content, 0, 32 ); |
299 | 299 | if ( !isset( $this->results['xmp-special']['HasExtendedXMP'] ) |
300 | | - || $this->results['xmp-special']['HasExtendedXMP'] !== $guid ) |
301 | | - { |
| 300 | + || $this->results['xmp-special']['HasExtendedXMP'] !== $guid ) { |
302 | 301 | wfDebugLog('XMP', __METHOD__ . " Ignoring XMPExtended block due to wrong guid (guid= '$guid' )"); |
303 | | - return; |
| 302 | + return false; |
304 | 303 | } |
305 | 304 | $len = unpack( 'Nlength/Noffset', substr( $content, 32, 8 ) ); |
306 | 305 | |
— | — | @@ -646,7 +645,6 @@ |
647 | 646 | } |
648 | 647 | } |
649 | 648 | |
650 | | - |
651 | 649 | /** |
652 | 650 | * Hit an opening element while in MODE_IGNORE |
653 | 651 | * |
— | — | @@ -664,6 +662,7 @@ |
665 | 663 | array_unshift( $this->mode, self::MODE_IGNORE ); |
666 | 664 | } |
667 | 665 | } |
| 666 | + |
668 | 667 | /** |
669 | 668 | * Start element in MODE_BAG (unordered array) |
670 | 669 | * this should always be <rdf:Bag> |
— | — | @@ -679,6 +678,7 @@ |
680 | 679 | } |
681 | 680 | |
682 | 681 | } |
| 682 | + |
683 | 683 | /** |
684 | 684 | * Start element in MODE_SEQ (ordered array) |
685 | 685 | * this should always be <rdf:Seq> |
— | — | @@ -699,6 +699,7 @@ |
700 | 700 | } |
701 | 701 | |
702 | 702 | } |
| 703 | + |
703 | 704 | /** |
704 | 705 | * Start element in MODE_LANG (language alternative) |
705 | 706 | * this should always be <rdf:Alt> |
— | — | @@ -721,6 +722,7 @@ |
722 | 723 | } |
723 | 724 | |
724 | 725 | } |
| 726 | + |
725 | 727 | /** |
726 | 728 | * Handle an opening element when in MODE_SIMPLE |
727 | 729 | * |
— | — | @@ -761,6 +763,7 @@ |
762 | 764 | } |
763 | 765 | |
764 | 766 | } |
| 767 | + |
765 | 768 | /** |
766 | 769 | * Start an element when in MODE_QDESC. |
767 | 770 | * This generally happens when a simple element has an inner |
— | — | @@ -784,6 +787,7 @@ |
785 | 788 | array_unshift( $this->curItem, $elm ); |
786 | 789 | } |
787 | 790 | } |
| 791 | + |
788 | 792 | /** |
789 | 793 | * Starting an element when in MODE_INITIAL |
790 | 794 | * This usually happens when we hit an element inside |
— | — | @@ -836,6 +840,7 @@ |
837 | 841 | // process attributes |
838 | 842 | $this->doAttribs( $attribs ); |
839 | 843 | } |
| 844 | + |
840 | 845 | /** |
841 | 846 | * Hit an opening element when in a Struct (MODE_STRUCT) |
842 | 847 | * This is generally for fields of a compound property. |
— | — | @@ -887,6 +892,7 @@ |
888 | 893 | array_unshift( $this->curItem, $this->curItem[0] ); |
889 | 894 | } |
890 | 895 | } |
| 896 | + |
891 | 897 | /** |
892 | 898 | * opening element in MODE_LI |
893 | 899 | * process elements of arrays. |
— | — | @@ -937,6 +943,7 @@ |
938 | 944 | } |
939 | 945 | |
940 | 946 | } |
| 947 | + |
941 | 948 | /** |
942 | 949 | * Opening element in MODE_LI_LANG. |
943 | 950 | * process elements of language alternatives |
— | — | @@ -1055,9 +1062,6 @@ |
1056 | 1063 | throw new MWException( 'StartElement in unknown mode: ' . $this->mode[0] ); |
1057 | 1064 | break; |
1058 | 1065 | } |
1059 | | - |
1060 | | - |
1061 | | - |
1062 | 1066 | } |
1063 | 1067 | /** |
1064 | 1068 | * Process attributes. |
— | — | @@ -1162,6 +1166,4 @@ |
1163 | 1167 | $this->results['xmp-' . $info['map_group']][$finalName] = $val; |
1164 | 1168 | } |
1165 | 1169 | } |
1166 | | - |
1167 | | - |
1168 | 1170 | } |
Index: trunk/phase3/includes/media/BitmapMetadataHandler.php |
— | — | @@ -10,16 +10,16 @@ |
11 | 11 | */ |
12 | 12 | class BitmapMetadataHandler { |
13 | 13 | |
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' ), |
24 | 24 | ); |
25 | 25 | private $iptcType = 'iptc-no-hash'; |
26 | 26 | |
Index: trunk/phase3/includes/media/XMPValidate.php |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | } |
39 | 39 | |
40 | 40 | } |
| 41 | + |
41 | 42 | /** |
42 | 43 | * function to validate rational properties ( 12/10 ) |
43 | 44 | * |
— | — | @@ -55,6 +56,7 @@ |
56 | 57 | } |
57 | 58 | |
58 | 59 | } |
| 60 | + |
59 | 61 | /** |
60 | 62 | * function to validate rating properties -1, 0-5 |
61 | 63 | * |
— | — | @@ -93,6 +95,7 @@ |
94 | 96 | } |
95 | 97 | } |
96 | 98 | } |
| 99 | + |
97 | 100 | /** |
98 | 101 | * function to validate integers |
99 | 102 | * |
— | — | @@ -111,6 +114,7 @@ |
112 | 115 | } |
113 | 116 | |
114 | 117 | } |
| 118 | + |
115 | 119 | /** |
116 | 120 | * function to validate properties with a fixed number of allowed |
117 | 121 | * choices. (closed choice) |
— | — | @@ -141,6 +145,7 @@ |
142 | 146 | $val = null; |
143 | 147 | } |
144 | 148 | } |
| 149 | + |
145 | 150 | /** |
146 | 151 | * function to validate and modify flash structure |
147 | 152 | * |
— | — | @@ -169,6 +174,7 @@ |
170 | 175 | | ( ( $val['RedEyeMode'] === 'True' ) << 6 ) ); |
171 | 176 | } |
172 | 177 | } |
| 178 | + |
173 | 179 | /** |
174 | 180 | * function to validate LangCode properties ( en-GB, etc ) |
175 | 181 | * |
— | — | @@ -193,6 +199,7 @@ |
194 | 200 | } |
195 | 201 | |
196 | 202 | } |
| 203 | + |
197 | 204 | /** |
198 | 205 | * function to validate date properties, and convert to Exif format. |
199 | 206 | * |
— | — | @@ -263,6 +270,7 @@ |
264 | 271 | } |
265 | 272 | |
266 | 273 | } |
| 274 | + |
267 | 275 | /** function to validate, and more importantly |
268 | 276 | * translate the XMP DMS form of gps coords to |
269 | 277 | * the decimal form we use. |
— | — | @@ -311,7 +319,5 @@ |
312 | 320 | $val = null; |
313 | 321 | return; |
314 | 322 | } |
315 | | - |
316 | 323 | } |
317 | | - |
318 | 324 | } |
Index: trunk/phase3/includes/media/JpegMetadataExtractor.php |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | * Based somewhat on GIFMetadataExtrator. |
8 | 8 | */ |
9 | 9 | class JpegMetadataExtractor { |
| 10 | + |
10 | 11 | const MAX_JPEG_SEGMENTS = 200; |
11 | 12 | // the max segment is a sanity check. |
12 | 13 | // A jpeg file should never even remotely have |
— | — | @@ -27,17 +28,25 @@ |
28 | 29 | |
29 | 30 | $segmentCount = 0; |
30 | 31 | |
31 | | - $segments = Array( 'XMP_ext' => array(), 'COM' => array() ); |
| 32 | + $segments = array( 'XMP_ext' => array(), 'COM' => array() ); |
32 | 33 | |
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 | + } |
35 | 40 | |
36 | 41 | $fh = fopen( $filename, "rb" ); |
37 | 42 | |
38 | | - if ( !$fh ) throw new MWException( "Could not open file $filename" ); |
| 43 | + if ( !$fh ) { |
| 44 | + throw new MWException( "Could not open file $filename" ); |
| 45 | + } |
39 | 46 | |
40 | 47 | $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 | + } |
42 | 51 | while ( !feof( $fh ) ) { |
43 | 52 | $buffer = fread( $fh, 1 ); |
44 | 53 | $segmentCount++; |
— | — | @@ -136,7 +145,9 @@ |
137 | 146 | * @return String if the iptc hash is good or not. |
138 | 147 | */ |
139 | 148 | public static function doPSIR ( $app13 ) { |
140 | | - if ( !$app13 ) return; |
| 149 | + if ( !$app13 ) { |
| 150 | + return; |
| 151 | + } |
141 | 152 | // First compare hash with real thing |
142 | 153 | // 0x404 contains IPTC, 0x425 has hash |
143 | 154 | // This is used to determine if the iptc is newer than |
— | — | @@ -171,7 +182,9 @@ |
172 | 183 | |
173 | 184 | $lenName = ord( substr( $app13, $offset, 1 ) ) + 1; |
174 | 185 | // 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. |
176 | 189 | $offset += $lenName; |
177 | 190 | |
178 | 191 | // now length of data (unsigned long big endian) |
Index: trunk/phase3/includes/media/PNG.php |
— | — | @@ -109,16 +109,19 @@ |
110 | 110 | $info = array(); |
111 | 111 | $info[] = $original; |
112 | 112 | |
113 | | - if ($metadata['loopCount'] == 0) |
| 113 | + if ( $metadata['loopCount'] == 0 ) { |
114 | 114 | $info[] = wfMsgExt( 'file-info-png-looped', 'parseinline' ); |
115 | | - elseif ($metadata['loopCount'] > 1) |
| 115 | + } elseif ( $metadata['loopCount'] > 1 ) { |
116 | 116 | $info[] = wfMsgExt( 'file-info-png-repeat', 'parseinline', $metadata['loopCount'] ); |
| 117 | + } |
117 | 118 | |
118 | | - if ($metadata['frameCount'] > 0) |
| 119 | + if ( $metadata['frameCount'] > 0 ) { |
119 | 120 | $info[] = wfMsgExt( 'file-info-png-frames', 'parseinline', $metadata['frameCount'] ); |
| 121 | + } |
120 | 122 | |
121 | | - if ($metadata['duration']) |
| 123 | + if ( $metadata['duration'] ) { |
122 | 124 | $info[] = $wgLang->formatTimePeriod( $metadata['duration'] ); |
| 125 | + } |
123 | 126 | |
124 | 127 | return $wgLang->commaList( $info ); |
125 | 128 | } |
Index: trunk/phase3/includes/media/Jpeg.php |
— | — | @@ -135,6 +135,4 @@ |
136 | 136 | } |
137 | 137 | return $this->formatMetadataHelper( $exif ); |
138 | 138 | } |
139 | | - |
140 | | - |
141 | 139 | } |