https://bugzilla.wikimedia.org/show_bug.cgi?id=26250

--- Comment #7 from Brion Vibber <[email protected]> 2011-01-19 21:55:27 UTC ---
json_decode() produces stdClass objects for JSON objects/maps/dicts by default;
to get an associative array, we pass in 'true' as the second parameter.

For our FormatJson::decode() wrapper, if json_decode is not natively available
passes the object retrieved from another library through wfObjectToArray().

It looks like wfObjectToArray()'s recursion isn't actually sufficient:
json_decode($img, true) and wfObjectToArray(json_decode($img)) give different
results, and the latter fails to translate the imageinfo entry:

Testing on API return data from
http://commons.wikimedia.org/w/api.php?action=query&titles=Image:Wikipedia.png&iiprop=timestamp|user|comment|url|size|sha1|metadata|mime&prop=imageinfo&format=json

> return wfObjectToArray(json_decode($img, false));
array(2) {
  ["query"]=>
  array(2) {
    ["normalized"]=>
    array(1) {
      [0]=>
      object(stdClass)#22 (2) {
        ["from"]=>
        string(19) "Image:Wikipedia.png"
        ["to"]=>
        string(18) "File:Wikipedia.png"
      }
    }
    ["pages"]=>
    array(1) {
      [17105]=>
      array(5) {
        ["pageid"]=>
        int(17105)
        ["ns"]=>
        int(6)
        ["title"]=>
        string(18) "File:Wikipedia.png"
        ["imagerepository"]=>
        string(5) "local"
        ["imageinfo"]=>
        array(1) {
          [0]=>
          object(stdClass)#25 (11) {
            ["timestamp"]=>
            string(20) "2005-08-13T20:55:13Z"
            ["user"]=>
            string(9) "Thuresson"
            ["size"]=>
            int(11742)
            ["width"]=>
            int(135)
            ["height"]=>
            int(155)
            ["url"]=>
            string(64)
"http://upload.wikimedia.org/wikipedia/commons/1/12/Wikipedia.png";
            ["descriptionurl"]=>
            string(52) "http://commons.wikimedia.org/wiki/File:Wikipedia.png";
            ["comment"]=>
            string(29) "Återgått till yngre version"
            ["sha1"]=>
            string(40) "f755e536d96cb430f23b53806ffcd88eada3d572"
            ["metadata"]=>
            NULL
            ["mime"]=>
            string(9) "image/png"
          }
        }
      }
    }
  }
  ["query-continue"]=>
  array(1) {
    ["imageinfo"]=>
    array(1) {
      ["iistart"]=>
      string(20) "2005-08-08T20:30:06Z"
    }
  }
}

So if we're on a system without PHP's native JSON module, we'll run the object
form through wfObjectToArray() and get that bogus output. Most of the data
structure is associative arrays -- so we extract the imageinfo entry
successfully -- but when things try to read out of it, they've got the wrong
data type.

Looks like the recursion isn't diving into linear arrays:

    foreach ( get_object_vars( $object ) as $key => $value ) {
        if ( is_object( $value ) && $recursive ) {
            $value = wfObjectToArray( $value );
        }

        $array[$key] = $value;
    }

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to