API: Clean up invalid UTF-8 in the result before feeding it to the formatter. This...
[lhc/web/wiklou.git] / includes / api / ApiResult.php
index f34780d..3071015 100644 (file)
@@ -100,7 +100,7 @@ class ApiResult extends ApiBase {
                }
                elseif (is_array($arr[$name]) && is_array($value)) {
                        $merged = array_intersect_key($arr[$name], $value);
-                       if (empty ($merged))
+                       if (!count($merged))
                                $arr[$name] += $value;
                        else
                                ApiBase :: dieDebug(__METHOD__, "Attempting to merge element $name");
@@ -180,12 +180,21 @@ class ApiResult extends ApiBase {
                        }
                }
 
-               if (empty($name))
+               if (!$name)
                        $data[] = $value;       // Add list element
                else
                        ApiResult :: setElement($data, $name, $value);  // Add named element
        }
 
+       /**
+        * Ensure all values in this result are valid UTF-8.
+        */
+       public function cleanUpUTF8()
+       {
+               $data = & $this->getData();
+               array_walk_recursive($data, array('UtfNormal', 'cleanUp'));
+       }
+
        public function execute() {
                ApiBase :: dieDebug(__METHOD__, 'execute() is not supported on Result object');
        }
@@ -201,7 +210,7 @@ if (!function_exists('array_intersect_key')) {
                $argc = func_num_args();
 
                if ($argc > 2) {
-                       for ($i = 1; !empty($isec) && $i < $argc; $i++) {
+                       for ($i = 1; $isec && $i < $argc; $i++) {
                                $arr = func_get_arg($i);
 
                                foreach (array_keys($isec) as $key) {