Page MenuHomePhabricator

converttitle parameter for the mobileview API
Closed, ResolvedPublic

Description

The Android app team is working on improving the app's support for language variants. One problem we've found is that, for languages with variants, we store the canonical page title (which may be in a different variant than the user wants) and display that to the user in UI such as reading lists, history, and so forth. We'd like to be able to hold the title in an arbitrary variant of the user's choice for correct in-app display, and be able to submit it to the mobileview API to retrieve page content, but ApiMobileView doesn't implement anything like the converttitles parameter in the core API query module. (It does have a variant parameter that allows us to get content in any variant provided we have the canonical title, but that's not the case we're looking at).

It looks like updating ApiMobileView to handle this case would be as easy as adding a call to Language::findVariantLink (h/t @Tgr). Is there any reason not to do this?

Event Timeline

Could you elaborate here with some examples? I'm not really understanding the problem here.

Consider this article on zhwiki: 天闻角川
The above link spells the title in Simplified characters. However, we can also reference the same article spelled in Traditional characters: 天聞角川

However, let's try passing these titles to the mobileview API:

Here's a mobileview request that uses the Simplified title.
And here's the same request that uses the Traditional title.

Notice that the mobileview request using the Traditional title doesn't work, because it doesn't automatically resolve the Traditional title into the Simplified title (which is the title under which the page is stored on wiki).

Now, if we use the action=query API, it does indeed work with either title, because it offers the converttitles=true parameter that does precisely the job of converting any language-variant title to the "canonical" title in the wiki.

.. but why are we using the mobile view in apps? MCS no longer uses that API and I thought the plan was to move away from using it..? (The web team only maintain the API now).

Ah, because MCS / Parsoid doesn't yet handle language variants, so in the special case of zhwiki, we fall back to using mobileview. Once that is fixed, we will of course move away from mobileview entirely.

MobileView at this point should be considered deprecated. I think with everything else the web team has on its plate it's unlikely we're be able to make changes/review code for it. Are there any other more stable APIs in api.php that could be used for your purpose?

You could make use of action=parse I think..? Albeit this would not have sections; would that be an acceptable trade off until we fix this in MCS?
?formatversion=2&format=json&action=parse&prop=text

FWIW I've got a working patch that just needs documentation and testing added, but I understand if you've got too much on your plate for reviewing.

If patch is small I can take a look, but I'm a little concerned that more attractive the API becomes the more consumers it might end up having and I'm concerned about giving the impression that we are accepting pull requests to it when really we should be winding it down.

Given apps are the only consumer that I know of, we might also want to consider moving the API to the MobileApps extension.

Change 381155 had a related patch set uploaded (by Mholloway; owner: Mholloway):
[mediawiki/extensions/MobileFrontend@master] ApiMobileView: Support queries for titles in any language variant

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

Thanks, @Jdlrobson!

I couldn't think of a situation in which we wouldn't want the title converted if necessary, so I decided to just add the behavior for all cases. Still, easy enough to put behind a parameter if you think it's better that way.

The actual functional change is 7 lines of code, the rest is just a couple of tests.

Also, moving the mobileview API to the MobileApp extension sounds reasonable to me. (BTW, the iOS app still uses mobileview for 100% of its page requests, AFAIK. I'm not sure when they plan on switching to MCS.)

Change 381155 merged by jenkins-bot:
[mediawiki/extensions/MobileFrontend@master] ApiMobileView: Support queries for titles in any language variant

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

Ta da: https://zh.wikipedia.beta.wmflabs.org/w/api.php?action=mobileview&format=json&page=%E4%BE%B5%E6%9D%83&sections=0

For those not intimately familiar with the the MW release process, it should roll out to the production wikis next week.

Jdlrobson claimed this task.