Extension:MobileFrontend/Configuring browser auto-detection

This document explains how a site admin can enable a mobile site for their mediawiki extension such that when a user visits the site from a mobile device they are automatically redirected to the mobile view rather than the desktop view.

Built-in autodetection
As of commit 5a1867e, MobileFrontend supports automatic device detection with minimal configuration.

All you need to do is set  in your LocalSettings.php.

While this is the easiest method, it will almost certainly be the least performant.

This solution is NOT compatible with front-end caching, as it provides no way for your cache to know the difference between a mobile view and a desktop view.

Apache Mobile Filter (AMF)
As of commit 0fb2c72d, MobileFrontend supports the [http://www.apachemobilefilter.org/ Apache Mobile Filter (AMF)] for device detection.

You must be using the Apache webserver.

Follow instructions for setup/configuration of AMF, and it should "just work".

This functions very similarly to built-in auto detection, and will not be compatible with front-end caching without special configuration.

Webserver/proxy-cache device detection
Some reverse proxies (like ) can inform MediaWiki whether mobile version is needed or not, thus creating a cache-friendly autodetection.

Detection using Varnish: mobile site on another domain
Suppose we use Varnish, and we want wiki.example.com to show desktop version, and m.wiki.example.com to show mobile version.

Here is how to do that.

LocalSettings.php should contain the following:

If you have many wikis, it may be convenient to use syntax like:

Where "%h<#>" maps to a segment of the hostname of  .

So, if  , %h0 is "en", %h1 is "<tvar|w>wikipedia</>", %h2 is "<tvar|org>org</>".

Given this, the above <tvar|MobileUrlTemplate> </> will automatically interpolate your mobile URL as "<tvar|url>en.m.wikipedia.org</>".

This is particularly useful for the WMF and projects like Wikipedia, which follow a template of, so the mobile domain will always look like.

Detection using Varnish: same domain for desktop/mobile site
Suppose we use Varnish, and we want <tvar|url>wiki.example.com</> to show desktop/mobile version on the very same URLs (without creating additional domains like "<tvar|url2>m.wiki.example.com</>", etc.).

Here is how to do that.

Otherwise MobileFrontend misbehaves (if we don't set $wgMobileUrlTemplate, it ignores <tvar|wap>X-WAP</> header, if we do, it doesn't set "useformat" cookies for "toggle Mobile view' links in the footer").