API: Fixing bug in iiprop=metadata handling:
authorRoan Kattouw <catrope@users.mediawiki.org>
Sat, 20 Oct 2007 18:27:39 +0000 (18:27 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sat, 20 Oct 2007 18:27:39 +0000 (18:27 +0000)
* Using ApiResult::setIndexedTagName_recursive() to recursively add <meta> tags to all subarrays of the metadata array

includes/api/ApiQueryImageInfo.php
includes/api/ApiResult.php

index 6109095..9d10263 100644 (file)
@@ -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;
index 63aaa24..7e8b51a 100644 (file)
@@ -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.