Re: [Wikitech-l] API returns empty strings for boolean fields?

2015-05-29 Thread S Page
On Thu, May 28, 2015 at 2:58 PM, Brian Gerstle 
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*
 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
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] API returns empty strings for boolean fields?

2015-05-28 Thread Ryan Kaldari
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 
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  to indicate that.
>
> -- Legoktm
>
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] API returns empty strings for boolean fields?

2015-05-28 Thread Legoktm
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  to indicate that.

-- Legoktm

___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] API returns empty strings for boolean fields?

2015-05-28 Thread Ryan Kaldari
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 
wrote:

> 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?
>
> --
> 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
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] API returns empty strings for boolean fields?

2015-05-28 Thread Ryan Kaldari
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=pageprops&ppprop=disambiguation
https://en.wikipedia.org/w/api.php?action=query&titles=Elvis&prop=pageprops&ppprop=disambiguation

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 
wrote:

> 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?
>
> --
> 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
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

[Wikitech-l] API returns empty strings for boolean fields?

2015-05-28 Thread Brian Gerstle
For example:

"mainpage" field is omitted when querying Barack Obama

:

> {
> "mobileview": {
> "pageprops": [],
> "sections": []
> }
> }


But, it's present when querying Main Page

:

> {
> "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