Page MenuHomePhabricator

wgMFMode does not appear to be documented
Closed, ResolvedPublic

Description

There is now advice in T390923 to query wgMFMode for mobile status. This config option appears to be documented neither in code nor on MediaWiki.org.

See also https://www.mediawiki.org/wiki/Extension_talk:MobileFrontend#How_do_I_check_with_JS_that_I'm_on_mobile_version...

Event Timeline

That is because it is not to be considered stable. Please do not use it on wiki. We only document stable code.

For mobile the mw- prefixed class is better covered by https://m.mediawiki.org/wiki/Stable_interface_policy/Frontend

The linked task seems to have decided that it's basically stable, recommending it officially for use, pointing out the mechanism for its use is over 10 years old... so, that response doesn't jive with the reality.

And at a minimum, there should be documentation in place for the now dozen extensions /and core/ which are querying that configuration item in Javascript. Otherwise it's just an undocumented configuration item, and that is strictly worse than some documentation saying it's in use for X reason or turns on/off Y behavior but shouldn't be relied on in Z contexts.

That is because it is not to be considered stable. Please do not use it on wiki. We only document stable code.

For mobile the mw- prefixed class is better covered by https://m.mediawiki.org/wiki/Stable_interface_policy/Frontend

I have trouble inferring from your answer what's the stable way to tell MobileFrontend from Minerva. This is kind of a very basic need for JavaScript tools like Convenient-Discussions; I'm ashamed I still use a /(^|\.)m\./.test(location.hostname) check (which fails in MobileFrontend at wikitech.wikimedia.org), but turns out the alternative isn't clear.

Okay let me dig into this more, but personally I would recommend:

document.body.classList.contains('mw-mf')

since this was added with that purpose in mind.

@Jdlrobson-WMF Thanks for researching this. The funny thing is that the only occurrence of mw-mf in global code says this:

	// TODO: Replace this with whatever config variable is decided on in
	//  https://phabricator.wikimedia.org/T299772.
	//
	// This used to be determined by checking whether <body> had the "mw-mf" class. However, this
	// was determined to be a non-trivial read from the DOM and one that could cause a forced style
	// recalculation in certain situations.
	//
	// See https://gerrit.wikimedia.org/r/c/mediawiki/extensions/WikimediaEvents/+/799353/1#message-21b63aebf69dc330933ef27deb11279b226656b8
	// for a detailed explanation.
	const isMobileFrontendActive = c( 'wgMFMode' ) !== null;

So, we figured out the task for deciding on the stable interface for this; it's T299772: Provide a standard way for clients to know that they are viewing the mobile version of the site (regardless of skin), which is... closed as resolved, although, judging by the code comment above, mw-mf is suboptimal. I'll reopen.

Jdlrobson-WMF added a project: Web-Team.
Jdlrobson-WMF moved this task from Incoming to Q4 on the Web-Team board.
Jdlrobson-WMF claimed this task.

I've documented in https://www.mediawiki.org/wiki/Extension:MobileFrontend#Q:_How_do_I_detect_the_mobile_site_in_frontend_code? that this is not stable for use in gadgets. For now it is acceptable to use it in extension code with the understanding this may be deprecated in future.

If you have any follow up questions please feel free to clarify on the talk page.