Page MenuHomePhabricator

API: Provide a way to combine prefixsearch results with knowledge of whether they are in a given collection
Closed, ResolvedPublic

Description

As a developer with a collection id I need to be able to generate a list of titles with a property telling me whether the page is in the given collection or not.
Use case: Do a prefix search and combine with this new query via a generator.

@Yurik proposed using a new prop

action=query & titles=pageA|pageB & prop=listmembership & lsmid=<listID>

Resulting in

{ 'query': { 'pages': [ {
   'id':10, 'title':'pageA', listmembership:""  // becomes true if formatversion=2+
}, {
   'id':15, 'title':'pageB'
}}]}}

Because its a prop, it can easily use a generator to supply list of titles. Can also do lsmlabel=label, and possibly even other user's public lists with lsmowner=User

Details

Related Changes in Gerrit:

Event Timeline

Change 203003 had a related patch set uploaded (by Yurik):
Implements prop=listmembership

https://gerrit.wikimedia.org/r/203003

@Jdlrobson, this request is done, and needs to be +2ed. The usage of the api is another matter.

I feel it is really weird to return "listmembership:" "" when the page is member and not including the field when it is not. Why not return "listmembership": true or something similar that makes more sense?

According to @Anomie, this is being changed globally - if you use formatversion=latest (2+), you should get true instead of "".

As for not including it - see comment inside the code - calculating items that are NOT part of the list requires going through all the results for each api call. But if you request many different properties in the same call and they doesn't all fit into one response, the next continuation would need to process everything it has done before, which is fairly complex. Thus, it is easier to simply return what is known as TRUE, but don't report the FALSE.

Wait formatversion=version ? The API has versioning (see T41592)?

I feel it is really weird to return "listmembership:" "" when the page is member and not including the field when it is not. Why not return "listmembership": true or something similar that makes more sense?

Historically, the XML format came first and in XML you'll often do a boolean attribute by having it present (with any value) for true and absent for false. When JSON was added boolean outputs were left XML-style instead of fixing it to be actual booleans.

As Yuri pointed out I just recently got around to making that fix, but for backwards compatibility you need to ask for it specifically (along with other structural changes with the same reasoning, like having keys with useful names rather than "*").

Yep, good work on that @Anomie! I really wish I foresaw that XML was a mistake back in 2005. Everyone was heavily into XML, mostly pushed by Microsoft.

@Anomie super cool. So glad this is happening.

lsmlabel is not part of the patch. Is it needed?

Change 203003 merged by jenkins-bot:
Implements prop=listmembership

https://gerrit.wikimedia.org/r/203003