From bb81750f27f5c484b89a8d66e1029c56882cba81 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 3 Feb 2009 16:25:50 +0000 Subject: [PATCH] * API: (bug 17326) BREAKING CHANGE: Changing output format for prop=imageinfo&iiprop=metadata to something based on name/value pairs. This means we don't use parts of the metadata in attributes anymore, something that caused invalid XML to be output. For more info on the exact format, see the mediawiki-api mailing list * Removed the spaces-to-underscores hack in the XML formatter --- RELEASE-NOTES | 1 + includes/api/ApiFormatXml.php | 8 -------- includes/api/ApiQueryImageInfo.php | 19 +++++++++++++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index afc44af5c3..94738fff32 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -156,6 +156,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 17239) Added prop=displaytitle to action=parse * (bug 17317) Added watch parameter to action=protect * (bug 17007) Added export and exportnowrap parameters to action=query +* (bug 17326) BREAKING CHANGE: Changed output format for iiprop=metadata === Languages updated in 1.15 === diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index 5004f1acab..81bcfa7318 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -106,14 +106,6 @@ class ApiFormatXml extends ApiFormatBase { if (is_string($subElemValue) && $this->mDoubleQuote) $subElemValue = $this->doubleQuote($subElemValue); - // Replace spaces with underscores - $newSubElemId = str_replace(' ', '_', $subElemId); - if($newSubElemId != $subElemId) { - $elemValue[$newSubElemId] = $subElemValue; - unset($elemValue[$subElemId]); - $subElemId = $newSubElemId; - } - if (gettype($subElemId) === 'integer') { $indElements[] = $subElemValue; unset ($elemValue[$subElemId]); diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 0924be6a85..03edc355cf 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -140,8 +140,7 @@ class ApiQueryImageInfo extends ApiQueryBase { $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 ); if( isset( $prop['metadata'] ) ) { $metadata = $file->getMetadata(); - $vals['metadata'] = $metadata ? unserialize( $metadata ) : null; - $result->setIndexedTagName_recursive( $vals['metadata'], 'meta' ); + $vals['metadata'] = $metadata ? self::processMetaData( unserialize( $metadata ), $result ) : null; } if( isset( $prop['mime'] ) ) $vals['mime'] = $file->getMimeType(); @@ -154,6 +153,22 @@ class ApiQueryImageInfo extends ApiQueryBase { return $vals; } + + public static function processMetaData($metadata, $result) + { + $retval = array(); + foreach($metadata as $key => $value) + { + $r = array('name' => $key); + if(is_array($value)) + $r['value'] = self::processMetaData($value, $result); + else + $r['value'] = $value; + $retval[] = $r; + } + $result->setIndexedTagName($retval, 'metadata'); + return $retval; + } public function getAllowedParams() { return array ( -- 2.20.1