From: Roan Kattouw Date: Sat, 20 Oct 2007 18:27:39 +0000 (+0000) Subject: API: Fixing bug in iiprop=metadata handling: X-Git-Tag: 1.31.0-rc.0~51108 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=26e301c6a9de3398e4999ef37d0b0a0266339da7;p=lhc%2Fweb%2Fwiklou.git API: Fixing bug in iiprop=metadata handling: * Using ApiResult::setIndexedTagName_recursive() to recursively add tags to all subarrays of the metadata array --- 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.