Extension:MobileFrontend

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
MobileFrontend

Release status: stable

Description Adds mobile-friendly view capabilities to MediaWiki
Author(s) Patrick Reilly, Max Semenik, Jon Robson, Arthur Richards, Brion Vibber, Juliusz Gonera
MediaWiki 1.22
PHP 5.3+
License GPL v2 or later
Download
Hooks used
RequestContextCreateSkin

BeforePageRedirect
SkinTemplateOutputPageBeforeExec
TestCanonicalRedirect
ResourceLoaderTestModules
GetCacheVaryCookies
ResourceLoaderRegisterModules
APIGetAllowedParams
APIAfterExecute
APIGetParamDescription
APIGetDescription
UnitTestsList

Check usage and version matrix
Bugs: list open list all report

MobileFrontend is a MediaWiki extension providing a mobile front-end to MediaWiki sites.

Contents

Download [edit]

You can download the extension directly from the MediaWiki source code repository (browse code). You can get:

One of the extensions tags

Not all extensions have tags. Some extensions have tags for each release, in which case those tags have the same stability as the release. To download a tag

  • Go to the tags list
  • Click the name of the tag you want to download
  • Click "snapshot"
The latest version of one of the extensions branches

Each extension has a master branch containing the latest code (might be unstable). Extensions can have further branches as well.

  • Go to the branches list
  • Click the branch name
  • Click "snapshot"
A snapshot made during the release of a MediaWiki version.

This might be unstable and is not guaranteed to work with the associated MediaWiki version.

After you've got the code, save it into the extensions/MobileFrontend directory of your wiki.

If you are familiar with git and have shell access to your server, you can obtain the extension, with all its tags and branches, as follows:

cd extensions
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/MobileFrontend.git

Installation [edit]

  1. Copy the files from the git repository to your server (see the "Download" links in the sidebox).
  2. Add this link to the bottom of LocalSettings.php:
    require_once("$IP/extensions/MobileFrontend/MobileFrontend.php");
    

Configuration settings [edit]

The following variables can be defined in LocalSettings.php after calling require_once("$IP/extensions/MobileFrontend/MobileFrontend.php"):

Setting name Default value Description
$wgMFPhotoUploadEndpoint URL of MediaWiki API entry point to which upload images. If it's an empty string, upload locally.
$wgMFPhotoUploadWiki null ID/database name of the wiki with uploaded images. If null, use local database.
$wgMobileFrontendLogo false, defaults to $wgExtensionAssetsPath . '/MobileFrontend/stylesheets/images/mw.png' Url to the logo used in the mobile view. Should be 35 x 22px.
$wgMobileUrlTemplate Template used to transcode regular URLs into mobile URLs. Can either be set as a static domain (eg 'mobile.mydomain.com'), or can use a template based off the host portion of your desktop domain. The token '%h0' represents the first portion of the hostname, '%h1' the second, and so on. For example, to achieve http://en.m.wikipedia.org from http://en.wikipedia.org, you would use: %h0.m.%h1.%h2
$wgMFRemovableClasses array() Make the classes, tags and ids stripped from page content configurable. Each item will be stripped from the page. The extension adds some classes by default.
$wgMFCustomLogos array( array() ) Makes the logos configurable. Example: array( 'site' => 'mysite', 'copyright' => 'img.jpg' ) Note that 'copyright' controls the image shown in the footer of the mobile page.
$wgMFExtendOpenSearchXml false Whether this extension should provide its excerpts to OpenSearchXml extension
$wgMobileFrontendFormatCookieExpiry The number of seconds the 'useformat' cookie should be valid (used to keep you on mobile or desktop view of site when manually toggling between the two). If unset, defaults to $wgCookieExpiration.
$wgMFRemotePostFeedback

$wgMFRemotePostFeedbackUrl $wgMFRemotePostFeedbackUsername $wgMFRemotePostFeedbackPassword $wgMFRemotePostFeedbackArticle

$wgMFRemotePostFeedback = true;

$wgMFRemotePostFeedbackUrl = "http://www.mediawiki.org/w/api.php"; $wgMFRemotePostFeedbackUsername = "username"; $wgMFRemotePostFeedbackPassword = "password"; $wgMFRemotePostFeedbackArticle = "ArticleNameForResults";

Configure the contact us page on the mobile site
$wgMFAutodetectMobileView false Whether or not the MobileFrontend extension autodetects devices for mobile view on its own, rather than using detection at the proxy/webserver layer, or using third party tools like Apache AMF. Depending on your setup, this is probably the easiest method of device detection, though least performant.

Configuring mobile browser auto detection [edit]

See Configuring Browser Auto-Detection

Homepage [edit]

By default, the only content that a user will see on their project homepage is search, license, and action control. In order to see content you have to use the appropriate css selectors. See http://meta.wikimedia.org/wiki/Mobile_Projects/Mobile_Gateway#Mobile_homepage

More information [edit]

If you would like to test the mobile extension on a desktop browser or your device doesn't render the mobile version you can append the following key-value pair to the querystring: useformat=mobile e.g., https://en.wikipedia.org/wiki/Chuck_Schuldiner?useformat=mobile

If you would like to see the wap version of the mobile extension use: ?useformat=mobile-wap instead.

If you would like to view a page in the beta without enabling it across the entire site you can append to the query string of any page ?mobileaction=beta

API [edit]

Extended action=parse [edit]

action=parse receives the following extra parameters:

mobileformat={html|wml}
Return rendered page in a mobile format, HTML for modern phones or WML for dumb phones.
noimages
Disable images in mobile output.
mainpage
Apply mobile main page transformations.

Example:

api.php?action=parse&page=Therion_(band)&mobileformat=html&prop=text&format=json


{
"parse": {
"title": "Therion (band)",
"text": "\n<table class=\"metadata plainlinks ambox ambox-style ambox-Copy_edit\" style=\"\"><tr>\n<td class=\"mbox-image\">\n<div style=\"width: 52px;\"><img alt=\"\" src=\"\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/5\/52\/Acap.svg\/36px-Acap.svg.png\" width=\"36\" height=\"40\"><\/div>\n<\/td>\n<td class=\"mbox-text\" style=\"\">

. . .

action=mobileview [edit]

Delivers content optimized for mobile devices for use by mobile apps and dynamic section views. Almost like a restricted-functionality action=parse, but more flexible and returns separate sections that are always obtained from full-page parse.

Parameters:

page
Title of page to process.
sections
Pipe-separated list of section numbers for which to return text or all for all sections.
redirect
Whether redirects should be followed, yes (default) or no. This parameter is intentionally made similar to the one to index.php.
prop
Which information to get:
  • text: HTML of selected section(s)
  • sections: Information about all sections on page
  • normalizedtitle: Normalized page title, will be returned only if it differs from the specified one.
sectionprop
What information about sections to get: pipe-separated list of value types defined by parser. It's the same as in action=parse: toclevel, level, line, number, index, fromtitle, anchor. "byteoffset" has been excluded as it makes no sense for this action.
noimages
Return HTML without images.
noheadings
Return HTML without headings.

Returned section information also includes the id for every section - its zero-based number; and for sections that contains references added by Extension:Cite, there's also references data member.

Examples:

{
        "mobileview": {
                "sections": [
                        {
                                "id": 0,
                                "text": "<div id=\"content\"><p>Hi<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]<\/a><\/sup><\/p></div>\n"
                        },
                        {
                                "toclevel": 1,
                                "line": "This is first section",
                                "id": 1
                        },
                        {
                                "toclevel": 2,
                                "line": "This is nested section",
                                "id": 2
                        },
                        {
                                "toclevel": 1,
                                "line": "References",
                                "id": 3,
                                "references": ""
                        }
                ]
        }
}

Same request for XML: api.php?action=mobileview&page=Extension:MobileFrontend/Example&sections=0&prop=text|sections&format=xml

<?xml version="1.0"?>
<api>
  <mobileview>
    <sections>
      <section id="0" xml:space="preserve">&lt;div id=&quot;content&quot;&gt;&lt;p&gt;Hi&lt;sup id=&quot;cite_ref-0&quot; class=&quot;reference&quot;&gt;&lt;a href=&quot;#cite_note-0&quot;&gt;[1]&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
</section>
      <section toclevel="1" line="This is first section" id="1" />
      <section toclevel="2" line="This is nested section" id="2" />
      <section toclevel="1" line="References" id="3" references="" />
    </sections>
  </mobileview>
</api>

prop=extracts [edit]

Returns article extracts. Two formats are available: cleaned up HTML and plain text.

Parameters:

exchars
Length of extracts in characters.
exsentences
Number of sentences to return.
exintro
Return only zeroth section.
exsectionformat
What section heading format to use for plaintext extracts:
wiki — e.g., == Wikitext ==
plain — no special decoration
raw — this extension's internal representation: <ASCII 1><ASCII 2><section level><ASCII 2><ASCII 1>.
exlimit
Maximum number of extracts to return. Because excerpts generation can be slow, the limit is capped at 20 for intro-only extracts and 1 for whole-page extracts.
explaintext
Return plain-text extracts.
excontinue
When more results are available, use this parameter to continue.

Example:

api.php?action=query&prop=extracts&exchars=100&titles=Earth&format=json

{
        "query": {
                "pages": {
                        "9228": {
                                "pageid": 9228,
                                "ns": 0,
                                "title": "Earth",
                                "extract": "<p><b>Earth<\/b> (or <b>the Earth<\/b>) is the third planet from the Sun, and the densest and fifth-largest<\/p>..."
                        }
                }
        }
}

Using the mobile view [edit]

WMF properties [edit]

On Wikimedia Foundation run properties, we use Varnish caching servers to check the user agent of your device. If your user agent appears to be coming from a mobile device, the Varnish servers will set an appropriate 'X-Device' header for your request, and you will be redirected to the MobileFrontend version of an article. Alternatively, you can click 'Mobile view' in the footer of an article or append "useformat=mobile" to the query string to view an article in the mobile view.

Example:

Varnish server vcl config for X-Device

sub vcl_recv {
set req.http.X-Device = req.http.User-Agent;
}


If you are viewing the mobile version of article but wish to see the desktop-version of that article, you can click 'View this article on regular <SITENAME>' to switch back.

If you want to permanently disable the mobile view for your web browser, you can click 'Permanently disable mobile site', which will set a cookie instructing the WMF servers to always display the desktop version of the site.

Non-WMF properties [edit]

For non-WMF properties, you can either set up your configuration to mimic how things are done at the WMF (doing device detection at the proxy layer and setting specific X-Device headers), or you can simply use "?useformat=mobile" to switch an article to use the mobile view.

Beta/Alpha Opt-in [edit]

To see additional features of the mobile site that are not 100% production ready, you can opt in to the beta or alpha ('here be dragons') modes of the site. If you opt in, be aware that there is a higher likelihood of experiencing bugs or other weird issues than when you use the stable version of the site. Features in the beta version of the site are generally more stable and polished than those in the alpha. So, consider yourself warned!

To opt in, tap on the hamburger icon next to the search bar to open the navigation menu. Tap 'Settings'. Then, tap the toggle next to 'Beta' from 'off' to 'on'. Note that you can only enter the alpha if you're already opted into the beta.

WMF cluster deployments [edit]

See Extension:MobileFrontend/Deployments for deployment information on past and upcoming deployments of MobileFrontend to the WMF cluster.

See also [edit]

See also MobileFrontend for more information on this extension.