From: Brian Wolff Date: Thu, 5 Dec 2013 23:50:17 +0000 (-0400) Subject: Make DjVu metadata be stored as serialized PHP array. X-Git-Tag: 1.31.0-rc.0~16250^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=1f995639ea6a57e63348e57c619d81f919f9ef7b;p=lhc%2Fweb%2Fwiklou.git Make DjVu metadata be stored as serialized PHP array. Previously metadata was stored as a string of XML. Some of the code in File expects the metadata to be an array serialized using PHP's serialization format. In particular, this fixes the api query=imageinfo module, and by extension instantCommons. This supersedes Icaa16eeb Bug: 37764 Change-Id: I5c1d2d2434f70b57137837bade797d4133c47b70 --- diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php index 1202c9a2ed..3bc56361c6 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -230,6 +230,30 @@ class DjVuHandler extends ImageHandler { return $deja; } + /** + * Get metadata, unserializing it if neccessary. + * + * @param File $file The DjVu file in question + * @return String XML metadata as a string. + */ + private function getUnserializedMetadata( File $file ) { + $metadata = $file->getMetadata(); + if ( substr( $metadata, 0, 3 ) === 'dejaMetaTree; } - $metadata = $image->getMetadata(); + $metadata = $this->getUnserializedMetadata( $image ); if ( !$this->isMetadataValid( $image, $metadata ) ) { wfDebug( "DjVu XML metadata is invalid or missing, should have been fixed in upgradeRow\n" ); @@ -307,7 +331,12 @@ class DjVuHandler extends ImageHandler { function getMetadata( $image, $path ) { wfDebug( "Getting DjVu metadata for $path\n" ); - return $this->getDjVuImage( $image, $path )->retrieveMetaData(); + $xml = $this->getDjVuImage( $image, $path )->retrieveMetaData(); + if ( $xml === false ) { + return false; + } else { + return serialize( array( 'xml' => $xml ) ); + } } function getMetadataType( $image ) {