Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -95,7 +95,8 @@ |
96 | 96 | as lastTabIndex(). |
97 | 97 | * (bug 29332) Warn if user requests mediawiki-announce subscription but does not |
98 | 98 | enter an e-mail address. |
99 | | -* (bug 25375) Add canonical namespaces to JavaScript "wgNamespaceIds" |
| 99 | +* (bug 25375) Add canonical namespaces to JavaScript "wgNamespaceIds" |
| 100 | +* The class JpegOrTiffHandler was renamed ExifBitmapHandler. |
100 | 101 | |
101 | 102 | === API changes in 1.19 === |
102 | 103 | * BREAKING CHANGE: action=watch now requires POST and token. |
Index: trunk/phase3/includes/media/JpegOrTiff.php |
— | — | @@ -1,127 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * @file |
5 | | - * @ingroup Media |
6 | | - */ |
7 | | - |
8 | | -/** |
9 | | - * Stuff specific to JPEG and (built-in) TIFF handler. |
10 | | - * All metadata related, since both JPEG and TIFF support Exif. |
11 | | - * |
12 | | - * @ingroup Media |
13 | | - */ |
14 | | -class JpegOrTiffHandler extends BitmapHandler { |
15 | | - |
16 | | - const BROKEN_FILE = '-1'; // error extracting metadata |
17 | | - const OLD_BROKEN_FILE = '0'; // outdated error extracting metadata. |
18 | | - |
19 | | - function convertMetadataVersion( $metadata, $version = 1 ) { |
20 | | - // basically flattens arrays. |
21 | | - $version = explode(';', $version, 2); |
22 | | - $version = intval($version[0]); |
23 | | - if ( $version < 1 || $version >= 2 ) { |
24 | | - return $metadata; |
25 | | - } |
26 | | - |
27 | | - $avoidHtml = true; |
28 | | - |
29 | | - if ( !is_array( $metadata ) ) { |
30 | | - $metadata = unserialize( $metadata ); |
31 | | - } |
32 | | - if ( !isset( $metadata['MEDIAWIKI_EXIF_VERSION'] ) || $metadata['MEDIAWIKI_EXIF_VERSION'] != 2 ) { |
33 | | - return $metadata; |
34 | | - } |
35 | | - |
36 | | - // Treat Software as a special case because in can contain |
37 | | - // an array of (SoftwareName, Version). |
38 | | - if (isset( $metadata['Software'] ) |
39 | | - && is_array( $metadata['Software'] ) |
40 | | - && is_array( $metadata['Software'][0]) |
41 | | - && isset( $metadata['Software'][0][0] ) |
42 | | - && isset( $metadata['Software'][0][1]) |
43 | | - ) { |
44 | | - $metadata['Software'] = $metadata['Software'][0][0] . ' (Version ' |
45 | | - . $metadata['Software'][0][1] . ')'; |
46 | | - } |
47 | | - |
48 | | - // ContactInfo also has to be dealt with specially |
49 | | - if ( isset( $metadata['Contact'] ) ) { |
50 | | - $metadata['Contact'] = |
51 | | - FormatMetadata::collapseContactInfo( |
52 | | - $metadata['Contact'] ); |
53 | | - } |
54 | | - |
55 | | - foreach ( $metadata as &$val ) { |
56 | | - if ( is_array( $val ) ) { |
57 | | - $val = FormatMetadata::flattenArray( $val, 'ul', $avoidHtml ); |
58 | | - } |
59 | | - } |
60 | | - $metadata['MEDIAWIKI_EXIF_VERSION'] = 1; |
61 | | - return $metadata; |
62 | | - } |
63 | | - |
64 | | - function isMetadataValid( $image, $metadata ) { |
65 | | - global $wgShowEXIF; |
66 | | - if ( !$wgShowEXIF ) { |
67 | | - # Metadata disabled and so an empty field is expected |
68 | | - return self::METADATA_GOOD; |
69 | | - } |
70 | | - if ( $metadata === self::OLD_BROKEN_FILE ) { |
71 | | - # Old special value indicating that there is no EXIF data in the file. |
72 | | - # or that there was an error well extracting the metadata. |
73 | | - wfDebug( __METHOD__ . ": back-compat version\n"); |
74 | | - return self::METADATA_COMPATIBLE; |
75 | | - } |
76 | | - if ( $metadata === self::BROKEN_FILE ) { |
77 | | - return self::METADATA_GOOD; |
78 | | - } |
79 | | - wfSuppressWarnings(); |
80 | | - $exif = unserialize( $metadata ); |
81 | | - wfRestoreWarnings(); |
82 | | - if ( !isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) || |
83 | | - $exif['MEDIAWIKI_EXIF_VERSION'] != Exif::version() ) |
84 | | - { |
85 | | - if ( isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) && |
86 | | - $exif['MEDIAWIKI_EXIF_VERSION'] == 1 ) |
87 | | - { |
88 | | - //back-compatible but old |
89 | | - wfDebug( __METHOD__.": back-compat version\n" ); |
90 | | - return self::METADATA_COMPATIBLE; |
91 | | - } |
92 | | - # Wrong (non-compatible) version |
93 | | - wfDebug( __METHOD__.": wrong version\n" ); |
94 | | - return self::METADATA_BAD; |
95 | | - } |
96 | | - return self::METADATA_GOOD; |
97 | | - } |
98 | | - |
99 | | - /** |
100 | | - * @param $image File |
101 | | - * @return array|bool |
102 | | - */ |
103 | | - function formatMetadata( $image ) { |
104 | | - $metadata = $image->getMetadata(); |
105 | | - if ( !$metadata || |
106 | | - $this->isMetadataValid( $image, $metadata ) === self::METADATA_BAD ) |
107 | | - { |
108 | | - // So we don't try and display metadata from PagedTiffHandler |
109 | | - // for example when using InstantCommons. |
110 | | - return false; |
111 | | - } |
112 | | - |
113 | | - $exif = unserialize( $metadata ); |
114 | | - if ( !$exif ) { |
115 | | - return false; |
116 | | - } |
117 | | - unset( $exif['MEDIAWIKI_EXIF_VERSION'] ); |
118 | | - if ( count( $exif ) == 0 ) { |
119 | | - return false; |
120 | | - } |
121 | | - return $this->formatMetadataHelper( $exif ); |
122 | | - } |
123 | | - |
124 | | - function getMetadataType( $image ) { |
125 | | - return 'exif'; |
126 | | - } |
127 | | -} |
128 | | - |
Index: trunk/phase3/includes/media/Jpeg.php |
— | — | @@ -8,11 +8,12 @@ |
9 | 9 | * JPEG specific handler. |
10 | 10 | * Inherits most stuff from BitmapHandler, just here to do the metadata handler differently. |
11 | 11 | * |
12 | | - * Metadata stuff common to Jpeg and built-in Tiff (not PagedTiffHandler) is in JpegOrTiffHandler. |
| 12 | + * Metadata stuff common to Jpeg and built-in Tiff (not PagedTiffHandler) is |
| 13 | + * in ExifBitmapHandler. |
13 | 14 | * |
14 | 15 | * @ingroup Media |
15 | 16 | */ |
16 | | -class JpegHandler extends JpegOrTiffHandler { |
| 17 | +class JpegHandler extends ExifBitmapHandler { |
17 | 18 | |
18 | 19 | function getMetadata ( $image, $filename ) { |
19 | 20 | try { |
— | — | @@ -28,7 +29,7 @@ |
29 | 30 | // BitmapMetadataHandler throws an exception in certain exceptional cases like if file does not exist. |
30 | 31 | wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" ); |
31 | 32 | |
32 | | - /* This used to use 0 (JpegOrTiffHandler::OLD_BROKEN_FILE) for the cases |
| 33 | + /* This used to use 0 (ExifBitmapHandler::OLD_BROKEN_FILE) for the cases |
33 | 34 | * * No metadata in the file |
34 | 35 | * * Something is broken in the file. |
35 | 36 | * However, if the metadata support gets expanded then you can't tell if the 0 is from |
— | — | @@ -37,7 +38,7 @@ |
38 | 39 | * Thus switch to using -1 to denote only a broken file, and use an array with only |
39 | 40 | * MEDIAWIKI_EXIF_VERSION to denote no props. |
40 | 41 | */ |
41 | | - return JpegOrTiffHandler::BROKEN_FILE; |
| 42 | + return ExifBitmapHandler::BROKEN_FILE; |
42 | 43 | } |
43 | 44 | } |
44 | 45 | |
Index: trunk/phase3/includes/media/ExifBitmap.php |
— | — | @@ -0,0 +1,127 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * @ingroup Media |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Stuff specific to JPEG and (built-in) TIFF handler. |
| 10 | + * All metadata related, since both JPEG and TIFF support Exif. |
| 11 | + * |
| 12 | + * @ingroup Media |
| 13 | + */ |
| 14 | +class ExifBitmapHandler extends BitmapHandler { |
| 15 | + |
| 16 | + const BROKEN_FILE = '-1'; // error extracting metadata |
| 17 | + const OLD_BROKEN_FILE = '0'; // outdated error extracting metadata. |
| 18 | + |
| 19 | + function convertMetadataVersion( $metadata, $version = 1 ) { |
| 20 | + // basically flattens arrays. |
| 21 | + $version = explode(';', $version, 2); |
| 22 | + $version = intval($version[0]); |
| 23 | + if ( $version < 1 || $version >= 2 ) { |
| 24 | + return $metadata; |
| 25 | + } |
| 26 | + |
| 27 | + $avoidHtml = true; |
| 28 | + |
| 29 | + if ( !is_array( $metadata ) ) { |
| 30 | + $metadata = unserialize( $metadata ); |
| 31 | + } |
| 32 | + if ( !isset( $metadata['MEDIAWIKI_EXIF_VERSION'] ) || $metadata['MEDIAWIKI_EXIF_VERSION'] != 2 ) { |
| 33 | + return $metadata; |
| 34 | + } |
| 35 | + |
| 36 | + // Treat Software as a special case because in can contain |
| 37 | + // an array of (SoftwareName, Version). |
| 38 | + if (isset( $metadata['Software'] ) |
| 39 | + && is_array( $metadata['Software'] ) |
| 40 | + && is_array( $metadata['Software'][0]) |
| 41 | + && isset( $metadata['Software'][0][0] ) |
| 42 | + && isset( $metadata['Software'][0][1]) |
| 43 | + ) { |
| 44 | + $metadata['Software'] = $metadata['Software'][0][0] . ' (Version ' |
| 45 | + . $metadata['Software'][0][1] . ')'; |
| 46 | + } |
| 47 | + |
| 48 | + // ContactInfo also has to be dealt with specially |
| 49 | + if ( isset( $metadata['Contact'] ) ) { |
| 50 | + $metadata['Contact'] = |
| 51 | + FormatMetadata::collapseContactInfo( |
| 52 | + $metadata['Contact'] ); |
| 53 | + } |
| 54 | + |
| 55 | + foreach ( $metadata as &$val ) { |
| 56 | + if ( is_array( $val ) ) { |
| 57 | + $val = FormatMetadata::flattenArray( $val, 'ul', $avoidHtml ); |
| 58 | + } |
| 59 | + } |
| 60 | + $metadata['MEDIAWIKI_EXIF_VERSION'] = 1; |
| 61 | + return $metadata; |
| 62 | + } |
| 63 | + |
| 64 | + function isMetadataValid( $image, $metadata ) { |
| 65 | + global $wgShowEXIF; |
| 66 | + if ( !$wgShowEXIF ) { |
| 67 | + # Metadata disabled and so an empty field is expected |
| 68 | + return self::METADATA_GOOD; |
| 69 | + } |
| 70 | + if ( $metadata === self::OLD_BROKEN_FILE ) { |
| 71 | + # Old special value indicating that there is no EXIF data in the file. |
| 72 | + # or that there was an error well extracting the metadata. |
| 73 | + wfDebug( __METHOD__ . ": back-compat version\n"); |
| 74 | + return self::METADATA_COMPATIBLE; |
| 75 | + } |
| 76 | + if ( $metadata === self::BROKEN_FILE ) { |
| 77 | + return self::METADATA_GOOD; |
| 78 | + } |
| 79 | + wfSuppressWarnings(); |
| 80 | + $exif = unserialize( $metadata ); |
| 81 | + wfRestoreWarnings(); |
| 82 | + if ( !isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) || |
| 83 | + $exif['MEDIAWIKI_EXIF_VERSION'] != Exif::version() ) |
| 84 | + { |
| 85 | + if ( isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) && |
| 86 | + $exif['MEDIAWIKI_EXIF_VERSION'] == 1 ) |
| 87 | + { |
| 88 | + //back-compatible but old |
| 89 | + wfDebug( __METHOD__.": back-compat version\n" ); |
| 90 | + return self::METADATA_COMPATIBLE; |
| 91 | + } |
| 92 | + # Wrong (non-compatible) version |
| 93 | + wfDebug( __METHOD__.": wrong version\n" ); |
| 94 | + return self::METADATA_BAD; |
| 95 | + } |
| 96 | + return self::METADATA_GOOD; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * @param $image File |
| 101 | + * @return array|bool |
| 102 | + */ |
| 103 | + function formatMetadata( $image ) { |
| 104 | + $metadata = $image->getMetadata(); |
| 105 | + if ( !$metadata || |
| 106 | + $this->isMetadataValid( $image, $metadata ) === self::METADATA_BAD ) |
| 107 | + { |
| 108 | + // So we don't try and display metadata from PagedTiffHandler |
| 109 | + // for example when using InstantCommons. |
| 110 | + return false; |
| 111 | + } |
| 112 | + |
| 113 | + $exif = unserialize( $metadata ); |
| 114 | + if ( !$exif ) { |
| 115 | + return false; |
| 116 | + } |
| 117 | + unset( $exif['MEDIAWIKI_EXIF_VERSION'] ); |
| 118 | + if ( count( $exif ) == 0 ) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + return $this->formatMetadataHelper( $exif ); |
| 122 | + } |
| 123 | + |
| 124 | + function getMetadataType( $image ) { |
| 125 | + return 'exif'; |
| 126 | + } |
| 127 | +} |
| 128 | + |
Property changes on: trunk/phase3/includes/media/ExifBitmap.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
1 | 129 | Merged /branches/REL1_15/phase3/includes/media/Jpeg.php:r51646 |
2 | 130 | Merged /branches/sqlite/includes/media/Jpeg.php:r58211-58321 |
3 | 131 | Merged /branches/new-installer/phase3/includes/media/Jpeg.php:r43664-66004 |
4 | 132 | Merged /branches/wmf-deployment/includes/media/Jpeg.php:r53381 |
Added: svn:eol-style |
5 | 133 | + native |
Index: trunk/phase3/includes/media/Tiff.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * |
13 | 13 | * @ingroup Media |
14 | 14 | */ |
15 | | -class TiffHandler extends JpegOrTiffHandler { |
| 15 | +class TiffHandler extends ExifBitmapHandler { |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Conversion to PNG for inline display can be disabled here... |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | $data['MEDIAWIKI_EXIF_VERSION'] = Exif::version(); |
65 | 65 | return serialize( $data ); |
66 | 66 | } else { |
67 | | - return JpegOrTiffHandler::BROKEN_FILE; |
| 67 | + return ExifBitmapHandler::BROKEN_FILE; |
68 | 68 | } |
69 | 69 | } else { |
70 | 70 | return ''; |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -528,7 +528,7 @@ |
529 | 529 | 'IPTC' => 'includes/media/IPTC.php', |
530 | 530 | 'JpegHandler' => 'includes/media/Jpeg.php', |
531 | 531 | 'JpegMetadataExtractor' => 'includes/media/JpegMetadataExtractor.php', |
532 | | - 'JpegOrTiffHandler' => 'includes/media/JpegOrTiff.php', |
| 532 | + 'ExifBitmapHandler' => 'includes/media/ExifBitmap.php', |
533 | 533 | 'MediaHandler' => 'includes/media/Generic.php', |
534 | 534 | 'MediaTransformError' => 'includes/media/MediaTransformOutput.php', |
535 | 535 | 'MediaTransformOutput' => 'includes/media/MediaTransformOutput.php', |