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: $wgMFAutodetectMobileView = true; in you 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 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
This is what the WMF does for device detection. If you are using front-end caching, you will want to set up device detection at this layer, otherwise, set it up at the web server layer. Ultimately, you will need to set a custom 'X-Device' http request header, with the value matching one of the device types in includes/DeviceDetection.php - we recommend that you follow what we do in our Varnish configuration.

One domain for mobile and desktop views
If you are using the same domain for your desktop and mobile sites, you will want to be careful to *not* set the X-Device header for non-mobile device browsers; otherwise, everyone will get the mobile site unless they explicitly switch to the desktop view.

Separate mobile and desktop domains (Recommended)
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. Follow the guidelines above for ensuring you set an X-Device HTTP header for your mobile domain, and be sure to not set an X-Device HTTP header for the desktop domain. A ME NN ANNO DATO UN BEL NIENTE PER ME NN INTERESSA  MA UN PO DI COMPASSIONE PER 4 FIGLI CHE SONO IN MISERIA   VEDO CHE LI SUCCHIANO IL LORO SANGUE  MA NN LI AIUTANO    E UNA VERA  TRAGEDIA PER ME SOPPORTARE  TUTTO PRIGIONIRA NEL COMPITER AL TELEFONO E ANCHE DISPETTI   NN NE POSSO PIU'  LO GIURO  O MILIONI DI HOTEL RISTORTANTI  MA DOVE SONO LE MACCHINE TANTE MACCHINE PRESI DDAI PRESIDENTI TUTTI DEL 2013- TUTTI RUBATI   MIO FIGLIO NN A MACCHINA E LO VEDONO PERCHE SOTTO CASA C'E UNA MACCHINA CHE CONTROLLA   O CERCATO IN GINOCCHIO UNA MACCINA ANCHE VECCHIA NN ME L'ANNO DATA   IO NN POSSO STARE +++ A TUTTO QUELLO CHE MI STANNO FACENDO PASSARE   ABBIAMO   PASSATO UN FERRAGOSTO DA CANI  DENTRO CASA CHE NN POTEVAMO USCIRE PER LA MACCHINA  E TANTE CASE ANNO I COMMM NN MI ANNO DATO UNA CASA    NN NE POSSO + BASTA SOFFRIRE POI SCRIVONO CHE DEVO COMPERARE  IL MIO CUORE STA SCOPPIANDO   NELLE FATTORIE  MI FANNO DI TUTTO   O ECISO DI ROMPERE IL COMPIUTER LO ODIO IL COMPIUTER Then, you will need to define your mobile domain by setting  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. So, if, %h0 is 'en', %h1 is 'wikipedia', %h2 is 'org'. Given this, the above  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 .wikipedia.org, so the mobile domain will always look like .m.wikipedia.org.