From 26e301c6a9de3398e4999ef37d0b0a0266339da7 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 20 Oct 2007 18:27:39 +0000 Subject: [PATCH] API: Fixing bug in iiprop=metadata handling: * Using ApiResult::setIndexedTagName_recursive() to recursively add tags to all subarrays of the metadata array --- includes/api/ApiQueryImageInfo.php | 1 + includes/api/ApiResult.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 61090957e3..9d1026387c 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -96,6 +96,7 @@ class ApiQueryImageInfo extends ApiQueryBase { if ($fld_metadata) { $metadata = unserialize($row["{$prefix}_metadata"]); $vals['metadata'] = $metadata ? $metadata : null; + $this->getResult()->setIndexedTagName_recursive($vals['metadata'], 'meta'); } $data[] = $vals; diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 63aaa2498a..7e8b51aa55 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -139,6 +139,22 @@ class ApiResult extends ApiBase { // Do not use setElement() as it is ok to call this more than once $arr['_element'] = $tag; } + + /** + * Calls setIndexedTagName() on $arr and each sub-array + */ + public function setIndexedTagName_recursive(&$arr, $tag) + { + if(!is_array($arr)) + return; + foreach($arr as $a) + { + if(!is_array($a)) + continue; + $this->setIndexedTagName($a, $tag); + $this->setIndexedTagName_recursive($a, $tag); + } + } /** * Add value to the output data at the given path. -- 2.20.1