Brian Wolff has uploaded a new change for review.
https://gerrit.wikimedia.org/r/99544
Change subject: Make DjVu metadata be stored as serialized PHP array.
......................................................................
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
---
M includes/media/DjVu.php
1 file changed, 27 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/44/99544/1
diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php
index fe3313a..9cd06e4 100644
--- a/includes/media/DjVu.php
+++ b/includes/media/DjVu.php
@@ -229,6 +229,30 @@
}
/**
+ * 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 ) === '<?xml' ) {
+ // Old style. Not serialized but instead just a raw
string of XML.
+ return $metadata;
+ }
+
+ wfSuppressWarnings();
+ $unser = unserialize( $metadata );
+ wfRestoreWarnings();
+ if ( is_array( $unser ) ) {
+ return $unser['xml'];
+ }
+
+ // unserialize failed. Guess it wasn't really serialized after
all,
+ return $metadata;
+ }
+
+ /**
* Cache a document tree for the DjVu XML metadata
* @param $image File
* @param $gettext Boolean: DOCUMENT (Default: false)
@@ -239,7 +263,7 @@
return $image->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" );
@@ -294,7 +318,8 @@
function getMetadata( $image, $path ) {
wfDebug( "Getting DjVu metadata for $path\n" );
- return $this->getDjVuImage( $image, $path )->retrieveMetaData();
+ $xml = $this->getDjVuImage( $image, $path )->retrieveMetaData();
+ return serialize( array( 'xml' => $xml ) );
}
function getMetadataType( $image ) {
--
To view, visit https://gerrit.wikimedia.org/r/99544
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c1d2d2434f70b57137837bade797d4133c47b70
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits