r24415 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24414‎ | r24415 | r24416 >
Date:05:25, 28 July 2007
Author:david
Status:old
Tags:
Comment:
Merged revisions 24409-24414 via svnmerge from
svn+ssh://david@svn.wikimedia.org/svnroot/mediawiki/trunk/phase3

........
r24410 | tstarling | 2007-07-27 18:15:35 -0700 (Fri, 27 Jul 2007) | 1 line

Committing some work in progress -- abstraction of handler-specific metadata formatting. The return format of MediaHandler::formatMetadata() might still need some tweaking, but I believe there is feature parity at this point.
........
Modified paths:
  • /branches/liquidthreads (modified) (history)
  • /branches/liquidthreads/includes/ImagePage.php (modified) (history)
  • /branches/liquidthreads/includes/filerepo/File.php (modified) (history)
  • /branches/liquidthreads/includes/media/Bitmap.php (modified) (history)
  • /branches/liquidthreads/includes/media/Generic.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/includes/ImagePage.php
@@ -46,10 +46,9 @@
4747 return Article::view();
4848
4949 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;
5252 } else {
53 - $exif = false;
5453 $showmeta = false;
5554 }
5655
@@ -82,12 +81,12 @@
8382 $this->imageHistory();
8483 $this->imageLinks();
8584
86 - if ( $exif ) {
 85+ if ( $showmeta ) {
8786 global $wgStylePath, $wgStyleVersion;
8887 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
8988 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
9089 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
91 - $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
 90+ $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
9291 $wgOut->addHTML(
9392 "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?$wgStyleVersion\"></script>\n" .
9493 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
@@ -121,45 +120,25 @@
122121 * @param array $exif The array containing the EXIF data
123122 * @return string
124123 */
125 - function makeMetadataTable( $exif ) {
 124+ function makeMetadataTable( $metadata ) {
126125 $r = wfMsg( 'metadata-help' ) . "\n\n";
127126 $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";
135136 }
136 - $r .= "|- class=\"$class\"\n";
137 - $r .= "!| $msg\n";
138 - $r .= "|| $v\n";
139137 }
140138 $r .= '|}';
141139 return $r;
142140 }
143141
144142 /**
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 - /**
164143 * Overloading Article's getContent method.
165144 *
166145 * Omit noarticletext if sharedupload; text will be fetched from the
Index: branches/liquidthreads/includes/filerepo/File.php
@@ -814,22 +814,11 @@
815815 return $retVal;
816816 }
817817
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;
821821 }
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() );
834823 }
835824
836825 /**
Index: branches/liquidthreads/includes/media/Bitmap.php
@@ -234,6 +234,56 @@
235235 return true;
236236 }
237237
 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+ }
238288 }
239289
240290
Index: branches/liquidthreads/includes/media/Generic.php
@@ -158,6 +158,37 @@
159159 'height' => $gis[1]
160160 );
161161 }
 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+
162193 }
163194
164195 /**
Property changes on: branches/liquidthreads
___________________________________________________________________
Modified: svnmerge-integrated
165196 - /trunk/phase3:1-24408
166197 + /trunk/phase3:1-24414

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r24410Committing some work in progress -- abstraction of handler-specific metadata ...tstarling01:15, 28 July 2007

Status & tagging log