Extension:MobileFrontend

From MediaWiki.org
(Redirected from MobileFrontend)
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
MobileFrontend

Release status: stable

Description Provides a mobile-friendly view
Author(s) Patrick Reilly, Max Semenik, Jon Robson, Arthur Richards, Brion Vibber, Juliusz Gonera, Ryan Kaldari
MediaWiki 1.23+
PHP 5.3+
License GPL v2 or later
Download
README
Example Any Wikimedia Foundation wiki
Parameters

See below

Added rights

mf-uploadbutton

Hooks used
RequestContextCreateSkin

BeforePageRedirect
SkinTemplateOutputPageBeforeExec
TestCanonicalRedirect
ResourceLoaderTestModules
GetCacheVaryCookies
ResourceLoaderRegisterModules
APIGetAllowedParams
APIAfterExecute
APIGetParamDescription
APIGetDescription
UnitTestsList
GetBetaFeaturePreferences

Translate the MobileFrontend extension if it is available at translatewiki.net

Check usage and version matrix; code metrics
Bugs: list open list all report

The MobileFrontend extension provides a mobile-friendly view.

Installation[edit | edit source]

  • If using Vagrant, install with vagrant enable-role mobilefrontend && vagrant provision
Manual Installation
  • Download and extract the file(s) in a directory called MobileFrontend in your extensions/ folder. If you're a developer and this extension is in a Git repository, then instead you should clone the repository using:
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/MobileFrontend.git
  • Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/MobileFrontend/MobileFrontend.php";
$wgMFAutodetectMobileView = true;

Prerequisites[edit | edit source]

  • Although MediaWiki doesn't require it, PHP must have mbstring support for this extension to work (bug 60174).
  • The newest version of MobileFrontend requires the extension Mantle.

Configuration settings[edit | edit source]

The following variables can be defined in LocalSettings.php after calling require_once "$IP/extensions/MobileFrontend/MobileFrontend.php";. Note that for a simple site adding $wgMFAutodetectMobileView = true; might be all you need to make it Just Work™.

Setting name Default value Description
$wgMFDefaultSkinClass 'SkinMinerva' The default skin for MobileFrontend; defaults to SkinMinerva
$wgMFUseCentralAuthToken false Allow editing (uploading) to external CentralAuth-enabled wikis where the user might not be logged in.
$wgMFPhotoUploadEndpoint '' URL of MediaWiki API entry point to which upload images. If it's an empty string, upload locally.
$wgMFUploadMinEdits 0 Specify how many edits a user need to use mobile upload.
$wgMFNearbyEndpoint '' An optional alternative API to query for nearby pages, e.g. https://en.m.wikipedia.org/w/api.php. If set forces nearby to operate in JSONP mode.
$wgMFContentNamespace NS_MAIN The content namespace(s) that Special:Nearby and Special:Random should use. Should be one or more of NS_* constants, pipe-separated.
$wgMFPhotoUploadWiki null ID/database name of the wiki with uploaded images. If null, use local database.
$wgMobileFrontendLogo false, default no logo URL to the logo used in the mobile view. Should be 35 × 22 px.

Example: "{$wgScriptPath}/mf-logo.png" for the file mf-logo.png in your wiki's root folder.

$wgMobileUrlTemplate '' Template used to transcode regular URLs into mobile URLs (optional, and probably an overkill for low-traffic sites). 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
$wgMobileFrontendFormatCookieExpiry null 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.
$wgMFRemovableClasses array(

// These rules will be used for all transformations
'base' => array(),
// HTML view
'HTML' => 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.
$wgMFNoindexPages true Set to false to allow search engines to index your mobile pages. So far, Google seems to mix mobile and non-mobile pages in its search results, creating confusion.
$wgMFStopRedirectCookieHost null Set the domain of the stopMobileRedirect cookie.
If this value is not set, it will default to the top domain of the host name (eg en.wikipedia.org = .wikipedia.org). If you want to set this to a top domain (to cover all subdomains), be sure to include the preceding '.' (eg .wikipedia.org NOT wikipedia.org).
$wgMFEnableDesktopResources Whether or not to load desktop-specific ResourceLoader resources. Current usecase is for deciding whether or not to load JS for unsetting the stopMobileRedirect cookie.
$wgMFTrademarkSitename false Whether to append ™ to the sitename in page footer, or ® to the sitename for alt text in footer if using a custom copyright logo. Defaults off to avoid being confusing. You can also edit the MediaWiki:Mobile-frontend-footer-sitename interface message directly.
$wgDeviceDetectionClass 'DeviceDetection' Name of the class used for mobile device detection, must be inherited from IDeviceDetector
$wgMFNearby false Whether geodata related functionality should be enabled, such as Special:Nearby. Requires GeoData extension.
$wgMFNearbyRange 10000 The range in meters that should be searched to find nearby pages on Special:Nearby (defaults to 10km).
$wgMFMinCachedPageSize 64 * 1024 Pages with smaller parsed HTML size are not cached. Set to 0 to cache everything or to some large value to disable caching completely.
$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.

If this option is set to true file cache must be disabled by setting $wgUseFileCache to false (otherwise autodetection won't be reliable due to cached copies being shown).

$wgMFEnableSiteNotice false Controls whether site notices should be shown.
$wgMFShowMobileViewToTablets false Controls whether tablets should be shown the mobile site. Works only if $wgMFAutodetectMobileView is true.
$wgMFPhotoUploadAppendToDesc '' (wiki)text to append to photo description during photo upload.
$wgMFEnableXAnalyticsLogging false Whether or not to enable the use of the X-Analytics HTTP response header. This header is used for analytics purposes; see Analytics/Kraken/Data Formats/X-Analytics.
$wgMFAnonymousEditing false Whether to respect $wgGroupPermissions or not: if set to false, disables editing for unregistered users. No major bugs with anonymous editing are currently known: you are encouraged to set the setting to true and report problems.
$wgMFLeadPhotoUploadCssSelector 'img, .navbox' A CSS selector which is used by mf-photo.js to test whether to prompt the user photo uploads on the current page. When the selector matches no elements the photo uploader will show.
Warning Warning: This is an advanced config variable so use caution in editing.
$wgMFEnableCssAnimations true Enable CSS animations in all browsers that support them
$wgMFNoMobileCategory false Database key (=page title with underscores instead of spaces etc.) of the category which members will never display mobile view
$wgMFNoMobilePages array() Prefixed names of pages that will never display mobile view
$wgMFAjaxUploadProgressSupport true Temporary boolean variable to enable/disable progress bars in the photo uploader
$wgMFDeviceWidthTablet 768 Minimum available screen width (in pixels) at which a device can be considered a tablet/desktop
$wgMFDeviceWidthMobileSmall 280 Devices with available screen of this value and less will have some styles adapted for improved reading on small screens.
$wgMFKeepGoing false Whether or not to use the KeepGoing feature.
$wgMFTidyMobileViewSections true Controls whether API action=mobileview should have every HTML section tidied for invalid markup
$wgMFMobileHeader 'X-WAP' Requests containing header with this name will be considered as coming from mobile devices. The default value is for backwards compatibility. Set to false to explicitly disable this way of detection.
$wgMFEnableMinervaBetaFeature false Controls whether the "Minerva as a desktop skin" beta feature is enabled
$wgMFEnableNearbyPagesBetaFeature false Controls whether the "Nearby pages" beta feature is enabled
$wgMFCollapseSectionsByDefault true Controls whether to collapse sections by default.
Leave at default true for "encyclopedia style", where the section 0 lead text will always be visible and subsequent sections may be collapsed by default.
Set to false for "dictionary style", sections are not collapsed.
$wgMFAppPackageId false ID of the App to deep link to replacing the browser. Set false to have no such link. See https://developers.google.com/app-indexing/webmasters/details
$wgMFAppScheme 'http' Scheme to use for the deep link. Per default, 'http' is used.
$wgMFPageActions array( 'edit', 'talk', 'upload', 'watch' ) Controls, which page action show and which not. Allowed: edit, talk, upload, watch

Configuring mobile browser auto detection[edit | edit source]

See /Configuring browser auto-detection

Configuring the main page[edit | edit source]

By default, the Main Page on the mobile site is the same page as on desktop. To show an optimized version of your Main page to your mobile users you can disable the desktop Main page simply by following these two rules to add mobile specific content:

  • A selector that is prefixed with mf- will be added to the mobile main page for any project. Any title attributes set on these elements will be promoted into a heading before the section. A title attribute is optional.
  • Any element with the class 'nomobile' will not show on mobile.

For example:

<div id="mf-blog" title="Wikimedia Blog">Hello</div>

would create a section named Wikimedia Blog with the text 'Hello'.

After you saved your Main page, on mobile devices you will see only the sections you added following this rules.

Additional tweaks[edit | edit source]

Get the most out of MobileFrontend by adding these other optional dependencies:

Quick how to[edit | edit source]

Add <div id="mf-home"> at the top of the wikitext and add </div> at the bottom. Refresh the mobile site. Now you can either adjust your styling to be mobile friendly or you can hide parts of the homepage by adding class="nomobile" to the elements you do not want to show.

A more complete set of instructions can be found here.

More information[edit | edit source]

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 query string: 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

If you would like to force your wiki to always display in mobile view, add the following to your LocalSettings.php:

MobileContext::singleton()->setForceMobileView( true );

API[edit | edit source]

Extended action=parse[edit | edit source]

Warning Warning: mobileformat parameter calling style have changed and current usage will be deprecated. See https://lists.wikimedia.org/pipermail/mediawiki-api/2013-October/003131.html for details.

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

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

Migrated to TextExtracts

Using the mobile view[edit | edit source]

WMF sites[edit | edit source]

On Wikimedia Foundation-run sites, 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 sites[edit | edit source]

For non-WMF sites, 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.

See also[edit | edit source]