For example:
"mainpage" field is omitted when querying Barack Obama https://en.wikipedia.org/wiki/Special:ApiSandbox#action=mobileview&format=json&page=Barack_Obama&prop=pageprops&pageprops=mainpage :
{ "mobileview": { "pageprops": [], "sections": [] } }
But, it's present when querying Main Page https://en.wikipedia.org/wiki/Special:ApiSandbox#action=mobileview&format=json&page=Main_Page&prop=pageprops&pageprops=mainpage :
{ "mobileview": { "pageprops": [], "mainpage": "", "sections": [ ... ]
}
}
Is this the desired behavior?
That's pretty normal (but admittedly confusing). For example, if you do a query for a page property, it will return empty string for true and nothing for false (which both evaluate to false in PHP): https://en.wikipedia.org/w/api.php?action=query&titles=Bug&prop=page... https://en.wikipedia.org/w/api.php?action=query&titles=Elvis&prop=pa...
This is mainly due to the fact that our API typically returns data as it exists in the database, not in a form most usable or parsable for 3rd party developers (unfortunately).
On Thu, May 28, 2015 at 2:58 PM, Brian Gerstle bgerstle@wikimedia.org wrote:
For example:
"mainpage" field is omitted when querying Barack Obama < https://en.wikipedia.org/wiki/Special:ApiSandbox#action=mobileview&forma...
:
{ "mobileview": { "pageprops": [], "sections": [] } }
But, it's present when querying Main Page < https://en.wikipedia.org/wiki/Special:ApiSandbox#action=mobileview&forma...
:
{ "mobileview": { "pageprops": [], "mainpage": "", "sections": [ ... ]
}
}
Is this the desired behavior?
-- EN Wikipedia user page: https://en.wikipedia.org/wiki/User:Brian.gerstle IRC: bgerstle _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Feel free to reopen the declined bug: https://phabricator.wikimedia.org/T15299
I've always supported making our API more intuitive, but every bug I file about it gets declined :(
On Thu, May 28, 2015 at 2:58 PM, Brian Gerstle bgerstle@wikimedia.org wrote:
For example:
"mainpage" field is omitted when querying Barack Obama < https://en.wikipedia.org/wiki/Special:ApiSandbox#action=mobileview&forma...
:
{ "mobileview": { "pageprops": [], "sections": [] } }
But, it's present when querying Main Page < https://en.wikipedia.org/wiki/Special:ApiSandbox#action=mobileview&forma...
:
{ "mobileview": { "pageprops": [], "mainpage": "", "sections": [ ... ]
}
}
Is this the desired behavior?
-- EN Wikipedia user page: https://en.wikipedia.org/wiki/User:Brian.gerstle IRC: bgerstle _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On 05/28/2015 02:58 PM, Brian Gerstle wrote:
Is this the desired behavior?
Yes-ish. It's a leftover from when XML was the primary API format. If you pass formatversion=2 in the request, you'll get proper booleans (as well as other improvements).
I re-closed https://phabricator.wikimedia.org/T15299 to indicate that.
-- Legoktm
Guess I shouldn't be so quick to complain ;) Thanks Anomie and others for finally fixing that 7-year-old bug!
On Thu, May 28, 2015 at 4:17 PM, Legoktm legoktm.wikipedia@gmail.com wrote:
On 05/28/2015 02:58 PM, Brian Gerstle wrote:
Is this the desired behavior?
Yes-ish. It's a leftover from when XML was the primary API format. If you pass formatversion=2 in the request, you'll get proper booleans (as well as other improvements).
I re-closed https://phabricator.wikimedia.org/T15299 to indicate that.
-- Legoktm
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Thu, May 28, 2015 at 2:58 PM, Brian Gerstle bgerstle@wikimedia.org wrote:
"mainpage" field is omitted when querying Barack Obama < https://en.wikipedia.org/wiki/Special:ApiSandbox#action=mobileview&forma...
:
{ "mobileview": { "pageprops": [], "sections": [] } }
API results often omit return parameters that have their default value in order to save space.
Legoktm wrote:
If you pass formatversion=2 in the request, you'll get proper booleans (as
well as other improvements).
Well, after API modules are changed to return booleans (which are turned into empty string for backwards compatibility if you don't specify formatversion=2). Legoktm fixed ApiMobileView.php with https://gerrit.wikimedia.org/r/#/c/214636/ last night : $resultObj->addValue( null, $moduleName, * // was: array( 'mainpage' => '' )* array( 'mainpage' => true ) ); so specifying formatversion=2 now gets you the boolean behavior on beta labs, and soon on enwiki. http://en.wikipedia.*beta.wmflabs* .org/w/api.php?action=mobileview&format=jsonfm&page=Main_Page&pageprops=mainpage& *formatversion=2* http://en.wikipedia.beta.wmflabs.org/w/api.php?action=mobileview&format=jsonfm&page=Main_Page&pageprops=mainpage&formatversion=2 works: returns:
{ "mobileview": { "normalizedtitle": "Main Page", "mainpage": true, "sections": [...
If you're writing an extension for the WMF cluster or 1.26 only, you should always use formatversion=2 (with the proviso that some API modules may change). It gives you cleaner return values and defaults to utf8 instead of ascii with unicode escape sequences. More at https://www.mediawiki.org/wiki/API:JSON_version_2#Using_the_new_JSON_results...
Cheers,
wikitech-l@lists.wikimedia.org