Index: branches/liquidthreads/includes/ImagePage.php |
— | — | @@ -46,10 +46,9 @@ |
47 | 47 | return Article::view(); |
48 | 48 | |
49 | 49 | if ($wgShowEXIF && $this->img->exists()) { |
50 | | - $exif = $this->img->getExifData(); |
51 | | - $showmeta = count($exif) ? true : false; |
| 50 | + $formattedMetadata = $this->img->formatMetadata(); |
| 51 | + $showmeta = $formattedMetadata !== false; |
52 | 52 | } else { |
53 | | - $exif = false; |
54 | 53 | $showmeta = false; |
55 | 54 | } |
56 | 55 | |
— | — | @@ -82,12 +81,12 @@ |
83 | 82 | $this->imageHistory(); |
84 | 83 | $this->imageLinks(); |
85 | 84 | |
86 | | - if ( $exif ) { |
| 85 | + if ( $showmeta ) { |
87 | 86 | global $wgStylePath, $wgStyleVersion; |
88 | 87 | $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) ); |
89 | 88 | $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) ); |
90 | 89 | $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" ); |
91 | | - $wgOut->addWikiText( $this->makeMetadataTable( $exif ) ); |
| 90 | + $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) ); |
92 | 91 | $wgOut->addHTML( |
93 | 92 | "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?$wgStyleVersion\"></script>\n" . |
94 | 93 | "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" ); |
— | — | @@ -121,45 +120,25 @@ |
122 | 121 | * @param array $exif The array containing the EXIF data |
123 | 122 | * @return string |
124 | 123 | */ |
125 | | - function makeMetadataTable( $exif ) { |
| 124 | + function makeMetadataTable( $metadata ) { |
126 | 125 | $r = wfMsg( 'metadata-help' ) . "\n\n"; |
127 | 126 | $r .= "{| id=mw_metadata class=mw_metadata\n"; |
128 | | - $visibleFields = $this->visibleMetadataFields(); |
129 | | - foreach( $exif as $k => $v ) { |
130 | | - $tag = strtolower( $k ); |
131 | | - $msg = wfMsg( "exif-$tag" ); |
132 | | - $class = "exif-$tag"; |
133 | | - if( !in_array( $tag, $visibleFields ) ) { |
134 | | - $class .= ' collapsable'; |
| 127 | + foreach ( $metadata as $type => $stuff ) { |
| 128 | + foreach ( $stuff as $k => $v ) { |
| 129 | + $class = Sanitizer::escapeId( $v['id'] ); |
| 130 | + if( $type == 'collapsed' ) { |
| 131 | + $class .= ' collapsable'; |
| 132 | + } |
| 133 | + $r .= "|- class=\"$class\"\n"; |
| 134 | + $r .= "!| {$v['name']}\n"; |
| 135 | + $r .= "|| {$v['value']}\n"; |
135 | 136 | } |
136 | | - $r .= "|- class=\"$class\"\n"; |
137 | | - $r .= "!| $msg\n"; |
138 | | - $r .= "|| $v\n"; |
139 | 137 | } |
140 | 138 | $r .= '|}'; |
141 | 139 | return $r; |
142 | 140 | } |
143 | 141 | |
144 | 142 | /** |
145 | | - * Get a list of EXIF metadata items which should be displayed when |
146 | | - * the metadata table is collapsed. |
147 | | - * |
148 | | - * @return array of strings |
149 | | - * @access private |
150 | | - */ |
151 | | - function visibleMetadataFields() { |
152 | | - $fields = array(); |
153 | | - $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) ); |
154 | | - foreach( $lines as $line ) { |
155 | | - $matches = array(); |
156 | | - if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) { |
157 | | - $fields[] = $matches[1]; |
158 | | - } |
159 | | - } |
160 | | - return $fields; |
161 | | - } |
162 | | - |
163 | | - /** |
164 | 143 | * Overloading Article's getContent method. |
165 | 144 | * |
166 | 145 | * Omit noarticletext if sharedupload; text will be fetched from the |
Index: branches/liquidthreads/includes/filerepo/File.php |
— | — | @@ -814,22 +814,11 @@ |
815 | 815 | return $retVal; |
816 | 816 | } |
817 | 817 | |
818 | | - function getExifData() { |
819 | | - if ( !$this->getHandler() || $this->handler->getMetadataType( $this ) != 'exif' ) { |
820 | | - return array(); |
| 818 | + function formatMetadata() { |
| 819 | + if ( !$this->getHandler() ) { |
| 820 | + return false; |
821 | 821 | } |
822 | | - $metadata = $this->getMetadata(); |
823 | | - if ( !$metadata ) { |
824 | | - return array(); |
825 | | - } |
826 | | - $exif = unserialize( $metadata ); |
827 | | - if ( !$exif ) { |
828 | | - return array(); |
829 | | - } |
830 | | - unset( $exif['MEDIAWIKI_EXIF_VERSION'] ); |
831 | | - $format = new FormatExif( $exif ); |
832 | | - |
833 | | - return $format->getFormattedData(); |
| 822 | + return $this->getHandler()->formatMetadata( $this, $this->getMetadata() ); |
834 | 823 | } |
835 | 824 | |
836 | 825 | /** |
Index: branches/liquidthreads/includes/media/Bitmap.php |
— | — | @@ -234,6 +234,56 @@ |
235 | 235 | return true; |
236 | 236 | } |
237 | 237 | |
| 238 | + /** |
| 239 | + * Get a list of EXIF metadata items which should be displayed when |
| 240 | + * the metadata table is collapsed. |
| 241 | + * |
| 242 | + * @return array of strings |
| 243 | + * @access private |
| 244 | + */ |
| 245 | + function visibleMetadataFields() { |
| 246 | + $fields = array(); |
| 247 | + $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) ); |
| 248 | + foreach( $lines as $line ) { |
| 249 | + $matches = array(); |
| 250 | + if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) { |
| 251 | + $fields[] = $matches[1]; |
| 252 | + } |
| 253 | + } |
| 254 | + $fields = array_map( 'strtolower', $fields ); |
| 255 | + return $fields; |
| 256 | + } |
| 257 | + |
| 258 | + function formatMetadata( $image ) { |
| 259 | + $result = array( |
| 260 | + 'visible' => array(), |
| 261 | + 'collapsed' => array() |
| 262 | + ); |
| 263 | + $metadata = $image->getMetadata(); |
| 264 | + if ( !$metadata ) { |
| 265 | + return false; |
| 266 | + } |
| 267 | + $exif = unserialize( $metadata ); |
| 268 | + if ( !$exif ) { |
| 269 | + return false; |
| 270 | + } |
| 271 | + unset( $exif['MEDIAWIKI_EXIF_VERSION'] ); |
| 272 | + $format = new FormatExif( $exif ); |
| 273 | + |
| 274 | + $formatted = $format->getFormattedData(); |
| 275 | + // Sort fields into visible and collapsed |
| 276 | + $visibleFields = $this->visibleMetadataFields(); |
| 277 | + foreach ( $formatted as $name => $value ) { |
| 278 | + $tag = strtolower( $k ); |
| 279 | + self::addMeta( $result, |
| 280 | + in_array( $tag, $visibleFields ) ? 'visible' : 'collapsed', |
| 281 | + 'exif', |
| 282 | + "exif-$tag", |
| 283 | + $value |
| 284 | + ); |
| 285 | + } |
| 286 | + return $result; |
| 287 | + } |
238 | 288 | } |
239 | 289 | |
240 | 290 | |
Index: branches/liquidthreads/includes/media/Generic.php |
— | — | @@ -158,6 +158,37 @@ |
159 | 159 | 'height' => $gis[1] |
160 | 160 | ); |
161 | 161 | } |
| 162 | + |
| 163 | + /** |
| 164 | + * Get an array structure that looks like this: |
| 165 | + * |
| 166 | + * array( |
| 167 | + * 'visible' => array( |
| 168 | + * 'Human-readable name' => 'Human readable value', |
| 169 | + * ... |
| 170 | + * ), |
| 171 | + * 'collapsed' => array( |
| 172 | + * 'Human-readable name' => 'Human readable value', |
| 173 | + * ... |
| 174 | + * ) |
| 175 | + * ) |
| 176 | + * The UI will format this into a table where the visible fields are always |
| 177 | + * visible, and the collapsed fields are optionally visible. |
| 178 | + * |
| 179 | + * The function should return false if there is no metadata to display. |
| 180 | + */ |
| 181 | + function formatMetadata( $image, $metadata ) { |
| 182 | + return false; |
| 183 | + } |
| 184 | + |
| 185 | + protected static function addMeta( &$array, $visibility, $type, $id, $value, $param = false ) { |
| 186 | + $array[$visibility][] = array( |
| 187 | + 'id' => "$type-$id", |
| 188 | + 'name' => wfMsg( "$type-$id", $param ), |
| 189 | + 'value' => wfEscapeWikiText( $value ) |
| 190 | + ); |
| 191 | + } |
| 192 | + |
162 | 193 | } |
163 | 194 | |
164 | 195 | /** |
Property changes on: branches/liquidthreads |
___________________________________________________________________ |
Modified: svnmerge-integrated |
165 | 196 | - /trunk/phase3:1-24408 |
166 | 197 | + /trunk/phase3:1-24414 |