On Thu, May 28, 2015 at 2:58 PM, Brian Gerstle <[email protected]>
wrote:

>
> "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": []
> >     }
> > }
>

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_format

Cheers,
-- 
=S Page  WMF Tech writer
_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to