Extension:MobileFrontend/Configuring browser auto-detection

From MediaWiki.org
Jump to: navigation, search

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[edit | edit source]

As of commit 5a1867e, MobileFrontend supports automatic device detection with minimal configuration. All you need to do is set:

$wgMFAutodetectMobileView = true;

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)[edit | edit source]

As of commit 0fb2c72d, MobileFrontend supports the 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[edit | edit source]

MobileFrontend supports the usage of two separate domains for a mobile version and desktop version of the site, and this is the recommended approach. While more complicated to set up, it is ultimately easier to manage and to scale - particularly if you are using frontend caching. This way, you need to point both domains, mobile and desktop, to the same MediaWiki installation however set a custom header for requests coming from from the mobile domain.

For example, in Varnish:

sub vcl_recv {
   if (req.http.host == "<mobile domain>") {
       set req.http.host = "<desktop domain>";
       set req.http.X-WAP = "no";
   }
}

Then, you will need to define your mobile domain by setting $wgMobileUrlTemplate in LocalSettings.php.

The simplest, and likely most common, thing to do is to define a completely unique domain for your mobile site:

$wgMobileUrlTemplate = 'mobile.mydomain.com';

Or, if you use one configuration to manage multiple wikis, you could define a mobile domain template:

$wgMobileUrlTemplate = '%h0.m.%h1.%h2';

Where '%h<#>' maps to a segment of the hostname of $wgServer. So, if $wgServer = 'en.wikipedia.org';, %h0 is 'en', %h1 is 'wikipedia', %h2 is 'org'. Given this, the above $wgMobileUrlTemplate will automatically interpolate your mobile URL as 'en.m.wikipedia.org'. This is particularly useful for the WMF and projects like Wikipedia, which follow a template of <lang code>.wikipedia.org, so the mobile domain will always look like <lang code>.m.wikipedia.org.