r71116 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71115‎ | r71116 | r71117 >
Date:13:28, 15 August 2010
Author:bawolff
Status:deferred
Tags:
Comment:
Fixup some stuff, specificly:
*Improve how multilingual metadata fields are shown to user
*Make the metadata box wider, and some other minor css things.
*Make Altitude and GPS data embedded in XMP be handled properly.
*fixup a couple code comments.
Modified paths:
  • /branches/img_metadata/phase3/includes/media/FormatMetadata.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/IPTC.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/Jpeg.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/XMP.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/XMPInfo.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/XMPValidate.php (modified) (history)
  • /branches/img_metadata/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /branches/img_metadata/phase3/languages/messages/MessagesQqq.php (modified) (history)
  • /branches/img_metadata/phase3/maintenance/language/messageTypes.inc (modified) (history)
  • /branches/img_metadata/phase3/maintenance/language/messages.inc (modified) (history)
  • /branches/img_metadata/phase3/skins/common/shared.css (modified) (history)

Diff [purge]

Index: branches/img_metadata/phase3/maintenance/language/messages.inc
@@ -2584,6 +2584,8 @@
25852585 'metadata-expand',
25862586 'metadata-collapse',
25872587 'metadata-fields',
 2588+ 'metadata-langitem',
 2589+ 'metadata-langitem-default',
25882590 ),
25892591 'exif' => array(
25902592 'exif-imagewidth',
Index: branches/img_metadata/phase3/maintenance/language/messageTypes.inc
@@ -364,6 +364,8 @@
365365 'usermessage-template',
366366 'revisionmove-backlink',
367367 'filepage.css',
 368+ 'metadata-langitem',
 369+ 'metadata-langitem-default',
368370 );
369371
370372 /** EXIF messages, which may be set as optional in several checks, but are generally mandatory */
Index: branches/img_metadata/phase3/skins/common/shared.css
@@ -750,7 +750,7 @@
751751 font-size: 0.8em;
752752 margin-left: 0.5em;
753753 margin-bottom: 0.5em;
754 - width: 300px;
 754+ width: 400px;
755755 }
756756
757757 table.mw_metadata caption {
@@ -773,8 +773,8 @@
774774 table.mw_metadata td, table.mw_metadata th {
775775 text-align: center;
776776 border: 1px solid #aaaaaa;
777 - padding-left: 0.1em;
778 - padding-right: 0.1em;
 777+ padding-left: 5px;
 778+ padding-right: 5px;
779779 }
780780
781781 table.mw_metadata th {
@@ -785,6 +785,14 @@
786786 background-color: #fcfcfc;
787787 }
788788
 789+table.mw_metadata ul.metadata-langlist {
 790+ list-style-type: none;
 791+ list-style-image: none;
 792+ padding-right: 5px;
 793+ padding-left: 5px;
 794+ margin: 0;
 795+}
 796+
789797 /* Galleries */
790798 table.gallery {
791799 border: 1px solid #ccc;
Index: branches/img_metadata/phase3/includes/media/FormatMetadata.php
@@ -738,21 +738,61 @@
739739 else {
740740 switch( $type ) {
741741 case 'lang':
742 - // fixme incomplete
743 - // should place x-default, content language, user language
744 - // first. then the others, hidden by defualt.
745 - // also should use much better markup.
746 - $content = "";
747 - if ( $vals['x-default'] ) {
748 - $content .= "\n*" . $vals['x-default'];
 742+ global $wgContLang;
 743+ // Display default, followed by ContLang,
 744+ // followed by the rest in no paticular
 745+ // order.
 746+
 747+ // Todo: hide some items if really long list.
 748+
 749+ $content = '';
 750+
 751+ $cLang = $wgContLang->getCode();
 752+ $default = false;
 753+ $defaultLang = false;
 754+
 755+ // If default is set, save it for later,
 756+ // as we don't know if it's equal to
 757+ // one of the lang codes. (In xmp
 758+ // you specify the language for a
 759+ // default property by having both
 760+ // a default prop, and one in the language
 761+ // that are identical)
 762+ if ( isset( $vals['x-default'] ) ) {
 763+ $defaultItem = $vals['x-default'];
749764 unset( $vals['x-default'] );
750765 }
 766+ // Do contentLanguage.
 767+ if ( isset( $vals[$cLang] ) ) {
 768+ $isDefault = false;
 769+ if ( $vals[$cLang] === $defaultItem ) {
 770+ $defaultItem = false;
 771+ $isDefault = true;
 772+ }
 773+ $content .= self::langItem(
 774+ $vals[$cLang], $cLang,
 775+ $isDefault );
 776+
 777+ unset( $vals[$cLang] );
 778+ }
 779+
 780+ // Now do the rest.
751781 foreach ( $vals as $lang => $item ) {
752 - global $wgContLang;
753 - $content .= "\n*<span lang=\"$lang\">"
754 - . "'''$lang''' $item</span>";
 782+ if ( $item === $defaultItem ) {
 783+ $defaultLang = $lang;
 784+ continue;
 785+ }
 786+ $content .= self::langItem( $item,
 787+ $lang );
755788 }
756 - return $content;
 789+ if ( $defaultItem !== false ) {
 790+ $content = self::langItem( $defaultItem,
 791+ $defaultLang, true )
 792+ . $content;
 793+ }
 794+ return '<ul class="metadata-langlist">' .
 795+ $content .
 796+ '</ul>';
757797 case 'ol':
758798 return "<ol><li>" . implode( "</li>\n<li>", $vals ) . '</li></ol>';
759799 case 'ul':
@@ -761,6 +801,53 @@
762802 }
763803 }
764804 }
 805+ /** Helper function for creating lists of translations.
 806+ *
 807+ * @param $value String value (this is not escaped)
 808+ * @param $lang String lang code of item or false
 809+ * @param $default if it is default value.
 810+ * @return language item (Note: despite how this looks,
 811+ * this is treated as wikitext not html).
 812+ */
 813+ private static function langItem( $value, $lang, $default = false ) {
 814+ global $wgContLang;
 815+ if ( $lang === false && $default === false) {
 816+ throw new MWException('$lang and $default cannot both '
 817+ . 'be false.');
 818+ }
 819+
 820+ $wrappedValue = '<span class="mw-metadata-lang-value">'
 821+ . $value . '</span>';
 822+
 823+ if ( $lang === false ) {
 824+ return '<li class="mw-metadata-lang-default">'
 825+ . wfMsg( 'metadata-langitem-default',
 826+ $wrappedValue )
 827+ . "</li>\n";
 828+ }
 829+ $langName = $wgContLang->getLanguageName( strtolower( $lang ) );
 830+ if ( $langName === '' ) {
 831+ //try just the base language name. (aka en-US -> en ).
 832+ list( $langPrefix ) = explode( '-', strtolower( $lang ),
 833+ 2 );
 834+ $langName = $wgContLang->getLanguageName( $langPrefix );
 835+ if ( $langName === '' ) {
 836+ // give up.
 837+ $langName = $lang;
 838+ }
 839+ }
 840+ // else we have a language specified
 841+ $item = '<li class="mw-metadata-lang-code-'
 842+ . $lang;
 843+ if ( $default ) {
 844+ $item .= ' mw-metadata-lang-default';
 845+ }
 846+ $item .= '" lang="' . $lang . '">';
 847+ $item .= wfMsg( 'metadata-langitem',
 848+ $wrappedValue, $langName, $lang );
 849+ $item .= "</li>\n";
 850+ return $item;
 851+ }
765852 /**
766853 * Convenience function for getFormattedData()
767854 *
Index: branches/img_metadata/phase3/includes/media/IPTC.php
@@ -278,6 +278,7 @@
279279 case '2#070':
280280 case '2#060':
281281 case '2#063':
 282+ case '2#085':
282283 //ignore. Handled elsewhere.
283284 break;
284285
Index: branches/img_metadata/phase3/includes/media/XMP.php
@@ -11,9 +11,12 @@
1212 * feature. If it comes across properties it doesn't recognize, it should
1313 * ignore them.
1414 *
15 -* The main methods one would call in this class are
 15+* The public methods one would call in this class are
1616 * - parse( $content )
1717 * Reads in xmp content.
 18+* Can potentially be called multiple times with partial data each time.
 19+* - parseExtended( $content )
 20+* Reads XMPExtended blocks (jpeg files only).
1821 * - getResults
1922 * Outputs a results array.
2023 *
@@ -111,15 +114,29 @@
112115 xml_parser_free( $this->xmlParser );
113116 }
114117
115 - /** Get the result array
 118+ /** Get the result array. Do some post-processing before returning
 119+ * the array.
 120+ *
116121 * @return Array array of results as an array of arrays suitable for
117 - * FormatExif.
 122+ * FormatMetadata::getFormattedData().
118123 */
119124 public function getResults() {
120125 // xmp-special is for metadata that affects how stuff
121 - // is extracted. For example xmpNote:HasExtendedXMP
122 - unset( $this->results['xmp-special'] );
123 - return $this->results;
 126+ // is extracted. For example xmpNote:HasExtendedXMP.
 127+ $data = $this->results;
 128+ unset( $data['xmp-special'] );
 129+
 130+ // Convert GPSAltitude to negative if below sea level.
 131+ if ( isset( $data['xmp-exif']['GPSAltitudeRef'] ) ) {
 132+ if ( $data['xmp-exif']['GPSAltitudeRef'] == '1'
 133+ && isset( $data['xmp-exif']['GPSAltitude'] )
 134+ ) {
 135+ $data['xmp-exif']['GPSAltitude'] *= -1;
 136+ }
 137+ unset( $data['xmp-exif']['GPSAltitudeRef'] );
 138+ }
 139+
 140+ return $data;
124141 }
125142
126143 /**
@@ -293,11 +310,7 @@
294311 if ( $this->charContent === false ) {
295312 $this->charContent = $data;
296313 } else {
297 - // I don't think this should happen,
298 - // but just in case.
299314 $this->charContent .= $data;
300 - // FIXME
301 - wfDebugLog( 'XMP', 'XMP: Consecuitive CDATA' );
302315 }
303316
304317 }
Index: branches/img_metadata/phase3/includes/media/XMPValidate.php
@@ -254,5 +254,55 @@
255255 }
256256
257257 }
 258+ /** function to validate, and more importantly
 259+ * translate the XMP DMS form of gps coords to
 260+ * the decimal form we use.
 261+ *
 262+ * @see http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart2.pdf
 263+ * section 1.2.7.4 on page 23
 264+ *
 265+ * @param $info Array unused (info about prop)
 266+ * @param &$val String GPS string in either DDD,MM,SSk or
 267+ * or DDD,MM.mmk form
 268+ * @param $standalone Boolean if its a simple prop (should always be true)
 269+ */
 270+ public static function validateGPS ( $info, &$val, $standalone ) {
 271+ if ( !$standalone ) {
 272+ return;
 273+ }
258274
 275+ $m = array();
 276+ if ( preg_match(
 277+ '/(\d{1,3}),(\d{1,2}),(\d{1,2})([NWSE])/D',
 278+ $val, $m )
 279+ ) {
 280+ $coord = intval( $m[1] );
 281+ $coord += intval( $m[2] ) * (1/60);
 282+ $coord += intval( $m[3] ) * (1/3600);
 283+ if ( $m[4] === 'S' || $m[4] === 'W' ) {
 284+ $coord = -$coord;
 285+ }
 286+ $val = $coord;
 287+ return;
 288+ } elseif ( preg_match(
 289+ '/(\d{1,3}),(\d{1,2}(?:.\d*)?)([NWSE])/D',
 290+ $val, $m )
 291+ ) {
 292+ $coord = intval( $m[1] );
 293+ $coord += floatval( $m[2] ) * (1/60);
 294+ if ( $m[3] === 'S' || $m[3] === 'W' ) {
 295+ $coord = -$coord;
 296+ }
 297+ $val = $coord;
 298+ return;
 299+
 300+ } else {
 301+ wfDebugLog( 'XMP', __METHOD__
 302+ . " Expected GPSCoordinate, but got $val." );
 303+ $val = null;
 304+ return;
 305+ }
 306+
 307+ }
 308+
259309 }
Index: branches/img_metadata/phase3/includes/media/XMPInfo.php
@@ -95,7 +95,11 @@
9696 'mode' => XMPReader::MODE_SIMPLE,
9797 'validate' => 'validateRational'
9898 ),
99 - /* FIXME GPSAltitude */
 99+ 'GPSAltitude' => array(
 100+ 'map_group' => 'exif',
 101+ 'mode' => XMPReader::MODE_SIMPLE,
 102+ 'validate' => 'validateRational',
 103+ ),
100104 'GPSDestBearing' => array(
101105 'map_group' => 'exif',
102106 'mode' => XMPReader::MODE_SIMPLE,
Index: branches/img_metadata/phase3/includes/media/Jpeg.php
@@ -58,7 +58,7 @@
5959
6060 foreach ( $metadata as &$val ) {
6161 if ( is_array( $val ) ) {
62 - $val = formatExif::flattenArray( $val );
 62+ $val = FormatMetadata::flattenArray( $val );
6363 }
6464 }
6565 $metadata['MEDIAWIKI_EXIF_VERSION'] = 1;
Index: branches/img_metadata/phase3/languages/messages/MessagesQqq.php
@@ -3099,6 +3099,10 @@
31003100 {{Identical|Metadata}}',
31013101 'metadata-expand' => 'On an image description page, there is mostly a table containing data (metadata) about the image. The most important data are shown, but if you click on this link, you can see more data and information. For the link to hide back the less important data, see "[[MediaWiki:Metadata-collapse/{{SUBPAGENAME}}|{{int:metadata-collapse}}]]".',
31023102 'metadata-collapse' => 'On an image description page, there is mostly a table containing data (metadata) about the image. The most important data are shown, but if you click on the link "[[MediaWiki:Metadata-expand/{{SUBPAGENAME}}|{{int:metadata-expand}}]]", you can see more data and information. This message is for the link to hide back the less important data.',
 3103+'metadata-langitem' => 'This is used for constructing the list of translations when a metadata property is translated into multiple languages.
 3104+
 3105+$1 is the value of the property (in one language), $2 is the language name that this translation is for (or language code if language name cannot be determined), $3 is the language code.',
 3106+'metadata-langitem-default' => 'Similar to "metadata-langitem" but for the case where a multilingual property has a default specified that does not specify what language the default is in. $1 is the value of the property. ',
31033107 'metadata-fields' => "'''Warning:''' Do not translate list items, only translate the text! So leave \"<tt>* make</tt>\" and the other items exactly as they are.
31043108
31053109 The sentences are for explanation only and are not shown to the user.",
Index: branches/img_metadata/phase3/languages/messages/MessagesEn.php
@@ -3634,12 +3634,14 @@
36353635 'variantname-tg' => 'tg', # only translate this message to other languages if you have to change it
36363636
36373637 # Metadata
3638 -'metadata' => 'Metadata',
3639 -'metadata-help' => 'This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
 3638+'metadata' => 'Metadata',
 3639+'metadata-help' => 'This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
36403640 If the file has been modified from its original state, some details may not fully reflect the modified file.',
3641 -'metadata-expand' => 'Show extended details',
3642 -'metadata-collapse' => 'Hide extended details',
3643 -'metadata-fields' => 'EXIF metadata fields listed in this message will be included on image page display when the metadata table is collapsed.
 3641+'metadata-expand' => 'Show extended details',
 3642+'metadata-collapse' => 'Hide extended details',
 3643+'metadata-langitem' => '\'\'\'$2:\'\'\' $1',
 3644+'metadata-langitem-default' => '$1',
 3645+'metadata-fields' => 'EXIF metadata fields listed in this message will be included on image page display when the metadata table is collapsed.
36443646 Others will be hidden by default.
36453647 * make
36463648 * model

Status & tagging log