Page MenuHomePhabricator

Document that action=parse supports useformat=mobile/desktop, replacing mobileformat=1
Open, Needs TriagePublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

var api = new mw.Api();
var params = {format: 'json',action: 'parse',mobileformat:false,disablelimitreport:true,pst: '1',prop: 'text',formatversion: '2',text:'<div class="nomobile">this div has the nomobile class but mobileformat is disabled, so if you\'re not seeing this it\'s a bug.</div><div>You\'re not seeing it, are you?</div>'};
api.post( params ).done( function ( data ) {console.log(data.parse.text);});

As mobileformat is false it gets stripped which is expected. So you can just as well omit it, makes no difference.

What happens?:
On https://en.wikipedia.org/wiki/Main_Page:

<div class="mw-parser-output"><div class="nomobile">this div has the nomobile class but mobileformat is disabled, so if you're not seeing this it's a bug.</div><div>You're not seeing it, are you?</div></div>

On https://en.m.wikipedia.org/wiki/Main_Page:

<div class="mw-parser-output"><section class="mf-section-0" id="mf-section-0"><div>You're not seeing it, are you?</div></section></div>

What should have happened instead?:
Get both divs regardless of domain as mobileformat:false was specified. Or there should be a "nomobileformat" (or "desktopformat") option. Whatever. The only way to get wikitext parsed in desktop format on the mobile domain is using a super ugly hack.

Event Timeline

AlexisJazz renamed this task from action:parse parameter mobileformat is ignored while on the mobile domain to action:parse always parses mobileformat while on the mobile domain.May 15 2022, 2:23 PM
AlexisJazz updated the task description. (Show Details)

I can offer two better workarounds:

  1. Add useformat: 'desktop' to the API query. This parameter isn't in the API documentation because it is meant for normal page views (e.g. https://en.m.wikipedia.org/wiki/Main_Page?useformat=desktop), but it works with the API too.
  2. Explicitly use the API on the desktop domain: var api = new mw.ForeignApi('https://en.wikipedia.org/w/api.php');. This has a little bit of overhead, since it's intended for cross-wiki API use, but it also works just fine.

The bug is still real though, there should be a documented and supported way of doing this. Maybe useformat should just be added to the autogenerated API docs.

  1. Very interesting! I'm slightly hesitant to rely on an undocumented API feature though, but I'll probably do it anyway.
  1. I really thought I tried that. Strange. In this case mw.loader.using(['mediawiki.ForeignApi'], function(){var api = new mw.ForeignApi('https://en.wikipedia.org/w/api.php',{anonymous:true});}) would be advisable as a few parse requests are unlikely to push one over whatever the relevant ratelimit for anons is and no special permissions are needed, so anon saves a request. But having to load mediawiki.ForeignApi (which, as I learned the hard way, isn't always loaded by default) is a downside that makes this solution possibly slower than the Module:String hack I'm currently using which I consider to be equal parts brilliant and disgusting.
matmarex renamed this task from action:parse always parses mobileformat while on the mobile domain to Document that action=parse supports useformat=mobile/desktop, replacing mobileformat=1.Jul 7 2022, 3:49 PM

It just needs to be added in a couple places in MobileFrontend, next to the existing code for 'mobileformat':
https://codesearch.wmcloud.org/search/?q=mobileformat&i=nope&files=&excludeFiles=.*%5C.json&repos=
(in particular, updating the unit test would ensure that it will remain supported).

Then we could also update the few uses of 'mobileformat' in DiscussionTools and VisualEditor, and mark it as deprecated, so that other people don't run into the issue where it is impossible to turn it off using that parameter (only on).

I fully agree, that's a sane solution.