Extension:MobileFrontend

From MediaWiki.org
Jump to: navigation, search

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎日本語 • ‎한국어 • ‎occitan • ‎polski • ‎русский • ‎sicilianu • ‎Tiếng Việt • ‎中文
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
MobileFrontend

Release status:Extension status stable

MediaWiki-Vagrant MobileFrontend Extension.png
ImplementationTemplate:Extension#type User interface, Hook
DescriptionTemplate:Extension#description Provides a mobile-friendly view
Author(s)Template:Extension#username
MediaWikiTemplate:Extension#mediawiki 1.27.0+
PHPTemplate:Extension#php 5.5.9+
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download
README
ExampleTemplate:Extension#example m.mediawiki.org
Hooks usedTemplate:Extension#hook
APIGetAllowedParamsManual:Hooks/APIGetAllowedParams
APIAfterExecuteManual:Hooks/APIAfterExecute
APIGetParamDescriptionManual:Hooks/APIGetParamDescription
APIGetDescriptionManual:Hooks/APIGetDescription
RequestContextCreateSkinManual:Hooks/RequestContextCreateSkin
MediaWikiPerformActionManual:Hooks/MediaWikiPerformAction
OutputPageBeforeHTMLManual:Hooks/OutputPageBeforeHTML
SkinAfterBottomScriptsManual:Hooks/SkinAfterBottomScripts
SkinTemplateOutputPageBeforeExecManual:Hooks/SkinTemplateOutputPageBeforeExec
BeforePageRedirectManual:Hooks/BeforePageRedirect
DiffViewHeaderManual:Hooks/DiffViewHeader
ResourceLoaderTestModulesManual:Hooks/ResourceLoaderTestModules
GetCacheVaryCookiesManual:Hooks/GetCacheVaryCookies
TestCanonicalRedirectManual:Hooks/TestCanonicalRedirect
ResourceLoaderGetConfigVarsManual:Hooks/ResourceLoaderGetConfigVars
SpecialPage_initListManual:Hooks/SpecialPage_initList
ListDefinedTagsManual:Hooks/ListDefinedTags
ChangeTagsListActiveManual:Hooks/ChangeTagsListActive
RecentChange_saveManual:Hooks/RecentChange_save
AbuseFilter-generateUserVars
AbuseFilter-builder
SpecialPageBeforeExecuteManual:Hooks/SpecialPageBeforeExecute
UserLoginCompleteManual:Hooks/UserLoginComplete
BeforePageDisplayManual:Hooks/BeforePageDisplay
CustomEditorManual:Hooks/CustomEditor
GetPreferencesManual:Hooks/GetPreferences
GetBetaFeaturePreferencesManual:Hooks/GetBetaFeaturePreferences
Gadgets::allowLegacy
CentralAuthLoginRedirectData
CentralAuthSilentLoginRedirect
ResourceLoaderRegisterModulesManual:Hooks/ResourceLoaderRegisterModules
EventLoggingRegisterSchemasManual:Hooks/EventLoggingRegisterSchemas
OutputPageParserOutputManual:Hooks/OutputPageParserOutput
HTMLFileCache::useFileCache
LoginFormValidErrorMessagesManual:Hooks/LoginFormValidErrorMessages
ResourceLoaderGetLessVarsManual:Hooks/ResourceLoaderGetLessVars
ThumbnailBeforeProduceHTMLManual:Hooks/ThumbnailBeforeProduceHTML
PageRenderingHashManual:Hooks/PageRenderingHash
AfterBuildFeedLinksManual:Hooks/AfterBuildFeedLinks
MakeGlobalVariablesScriptManual:Hooks/MakeGlobalVariablesScript
TitleSquidURLsManual:Hooks/TitleSquidURLs
MediaWikiServicesManual:Hooks/MediaWikiServices
Hooks providedTemplate:Extension#newhook
SkinMinervaDefaultModulesExtension:MobileFrontend/SkinMinervaDefaultModules
MobileLicenseLinkExtension:MobileFrontend/MobileLicenseLink
MobileSiteOutputPageBeforeExecExtension:MobileFrontend/MobileSiteOutputPageBeforeExec
MobileSpecialPageStylesExtension:MobileFrontend/MobileSpecialPageStyles
MobileFrontendBeforeDOMExtension:MobileFrontend/MobileFrontendBeforeDOM
MinervaPreRenderExtension:MobileFrontend/MinervaPreRender
MobileMenuExtension:MobileFrontend/MobileMenu
BeforeSpecialMobileDiffDisplayExtension:MobileFrontend/BeforeSpecialMobileDiffDisplay
EnterMobileModeExtension:MobileFrontend/EnterMobileMode
GetMobileUrlExtension:MobileFrontend/GetMobileUrl
BeforePageDisplayMobileExtension:MobileFrontend/BeforePageDisplayMobile
SpecialWatchlistQueryExtension:MobileFrontend/SpecialWatchlistQuery
SpecialMobileEditWatchlist::imagesExtension:MobileFrontend/SpecialMobileEditWatchlist::images

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

Check usage and version matrix.

IssuesPhabricator

Open tasks · Report a bug

The MobileFrontend extension:

This page is designed for end users who want to install it on their development instance. If you are keen to help us build it and improve it we encourage you to get involved.


Prerequisites[edit source]

  • Although MediaWiki doesn't require it, PHP must have mbstring support for this extension to work (task T62174).
  • Release for MediaWiki ≤ 1.24 of MobileFrontend requires the extension Mantle.

Before installing MobileFrontend, if you make heavy use of templates and/or inline styles (the style attribute) you should review your content to see whether it is mobile friendly. The TemplateStyles extension can be used to style content so that it renders nicely on mobile and desktop. MobileFrontend will not magically fix this for you!

In particular, you may want to review your landing page (main page). See Mobile homepage formatting.

Installation[edit source]

Manual installation

  • Download and place the file(s) in a directory called MobileFrontend in your extensions/ folder.

Setup Nearby[edit source]

MobileFrontend provides the Special:Nearby page with a little configuration. To get this to work a few optional steps are required:

  • Due to browser security you will need to be running a secure site over SSL - it is not possible to request a users location over http
  • Install GeoData
  • Run update.php
  • in LocalSettings.php add $wgMFNearby = true;
  • Add data to your articles to one or more pages {{#coordinates:37.786971|-122.399677|primary}} see the documentation for GeoData for syntax details

Alternatively you can use an alien MediaWiki instance for Nearby with the following 2 lines in your LocalSettings. The nearby endpoint will be used to find related content to a given location.

$wgMFNearbyEndpoint = 'https://en.m.wikipedia.org/w/api.php';
$wgMFNearby = true;

Setup a skin[edit source]

MobileFrontend provides you with a mobile formatted website to go alongside your existing desktop website. You can skin it however you want.

 // Choose one of those:
 $wgMFDefaultSkinClass = 'SkinMinerva'; // use Minerva skin
 $wgMFDefaultSkinClass = 'SkinVector'; // use Vector skin
 $wgMFDefaultSkinClass = 'SkinTimeless'; // use Timeless skin

The following skins are compatible with MobileFrontend:


Configuration settings[edit source]

See Extension:MobileFrontend/Configuration

Additional tweaks[edit source]

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

Local customisations[edit source]

CSS styling[edit source]

To apply CSS to your mobile theme, edit MediaWiki:Mobile.css, the counterpart of MediaWiki:Common.css.

More information[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 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 );

Legacy features of MobileFrontend[edit source]

MobileFrontend has traditionally been a very large extension. Many features have either surpassed their requirements or will do at some future date. These are listed below.

API[edit source]

APIs are provided by the MobileFrontend extension, but long term we expect to deprecate them in favour of Mobile Content Service. Use these APIs at your own risk. They may disappear (although we will give you sufficient notice when they do)!


Extended action=parse[edit source]

action=parse accepts extra parameters:

mobileformat=
Return rendered page HTML in a mobile format 1.23+. Prior to MediaWiki 1.23, you could specify mobileformat=html to output HTML for modern phones or mobileformat=wml to output WML for dumb phones (see mailing list messagefor details).
noimages
Disable images in mobile output.
mainpage
Apply mobile main page transformations.

Example:

action=mobileview[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:

Same request for XML:

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

prop=extracts[edit source]

Migrated to Extension:TextExtractsExtension:TextExtracts

For developers/sysadmins[edit source]

Testing with articles on a foreign wiki (live data)[edit source]

MobileFrontend can now be configured locally to render articles from other MediaWiki instances. This can help you debug problems locally instead of importing articles which may have dependencies on various templates and Wikibase identifiers from production to your local instance. This is not recommended for production usage.

The code below will turn your local MediaWiki mobile site into a Wikivoyage viewer:

$wgMFContentProviderClass = 'MobileFrontend\ContentProviders\MwApiContentProvider';
$wgMFMwApiContentProviderBaseUri = 'https://en.m.wikivoyage.org/w/api.php';

This is particularly useful for testing different mobile skins using the wgMFDefaultSkinClass config option.

Using the mobile view[edit source]

WMF sites[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 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.

Starting from the snapshot version 1.28, the default $wgMFMobileHeader was changed from X-WAP to X-Subdomain. You could either set $wgMFMobileHeader = 'X-WAP'; or modify your cache (Varnish) header setting. As long as them match.

FAQ[edit source]

The following questions frequently appear on our talk page. Please check this list before posting about them on the talk page or use the existing talk topic, if available, to receive clarifications.

Q: How do I customise the main menu of the Minerva skin?[edit source]

A: This is tracked in phabricator but you can see Topic:Tiggc18fvd3stmsf has an interim solution.

Q: How do I add HTML to the Minerva skin, for example to add ads or additional script tags?'[edit source]

A: You can do this by editing the template file for the skin (currently include/skins/minerva.mustache). See this discussion for details.

Q: The extension I am using doesn't seem to work on MobileFrontend. Why?[edit source]

A: It's likely the extension is old and needs to add compatibility to MobileFrontend. Please contact the developer of the extension and point them to ResourceLoader/Writing a MobileFrontend friendly ResourceLoader module. Please do not post to the talk page, as in this case it would be better to file a bug on Phabricator.org (you can login using your MediaWiki.org username) for a quicker response.

Q: I upgraded MobileFrontend and now I'm getting a fatal exception![edit source]

A: You are probably using incompatible versions of MobileFrontend and MediaWiki. In most cases, we can't help you here. Try upgrading MobileFrontend or MediaWiki to resolve your issue.

A2: A skin was split off by the developers. Quickly put a skin back on.


For Extension Developers[edit source]

By default resource modules in extensions will not be loaded in mobile view. Should a module need to be loaded while in mobile view this guide on writing MobileFrontend friendly modules will be of help.

See also[edit source]