扩展:移动前端

This page is a translated version of the page Extension:MobileFrontend and the translation is 63% complete.
Other languages:
Deutsch • ‎English • ‎Tiếng Việt • ‎Türkçe • ‎español • ‎français • ‎polski • ‎português • ‎português do Brasil • ‎svenska • ‎русский • ‎中文 • ‎日本語 • ‎한국어

移动前端(MobileFrontend)扩展:


MediaWiki擴充功能手冊
OOjs UI icon advanced.svg
MobileFrontend
发布状态: 稳定版
MediaWiki-Vagrant MobileFrontend Extension.png
实现 用户界面, 钩子
描述 提供对移动端友好的视图
作者
最新版本 2.3.0
兼容性方针 发行分支
MediaWiki 1.33+[1]
PHP 5.5.9+
许可协议 GNU通用公眾授權條款2.0或更新版本
下载
README
例子 m.mediawiki.org
  • $wgMFSearchGenerator
  • $wgMFStopRedirectCookieHost
  • $wgMFShowMobileViewToTablets
  • $wgMFStripResponsiveImages
  • $wgMFLazyLoadImages
  • $wgMFRSSFeedLink
  • $wgMFNamespacesWithLeadParagraphs
  • $wgMFAmcOutreachMinEditCount
  • $wgMFEnableMobilePreferences
  • $wgMFMobileFormatterOptions
  • $wgMFRemovableClasses
  • $wgMFContentProviderTryLocalContentFirst
  • $wgMFShowFirstParagraphBeforeInfobox
  • $wgMFMinCachedPageSize
  • $wgMFContentProviderClass
  • $wgMFVaryOnUA
  • $wgMFLogWrappedInfoboxes
  • $wgMFDisplayWikibaseDescriptions
  • $wgMFAlwaysUseContentProvider
  • $wgMFStopMobileRedirectCookieSecureValue
  • $wgMFNoMobilePages
  • $wgMFSchemaEditAttemptStepOversample
  • $wgMFEnableJSConsoleRecruitment
  • $wgMobileFrontendFormatCookieExpiry
  • $wgMFAmcOutreach
  • $wgMFResponsiveImageWhitelist
  • $wgMFLazyLoadSkipSmallImages
  • $wgMFSearchAPIParams
  • $wgMFContentProviderScriptPath
  • $wgMFAdvancedMobileContributions
  • $wgMFEnableXAnalyticsLogging
  • $wgMFUseDesktopSpecialHistoryPage
  • $wgMFWatchlistEditCountThreshold
  • $wgMFSiteStylesRenderBlocking
  • $wgMFMcsContentProviderBaseUri
  • $wgDefaultMobileSkin
  • $wgMobileUrlTemplate
  • $wgMFCollapseSectionsByDefault
  • $wgMFManifestBackgroundColor
  • $wgMFEnableFontChanger
  • $wgMFManifestThemeColor
  • $wgMFEnableManifest
  • $wgMFSchemaSearchSampleRate
  • $wgMFNoMobileCategory
  • $wgMFNearby
  • $wgMFEnableWikidataDescriptions
  • $wgMFUseWikibase
  • $wgMFSpecialPageTaglines
  • $wgMFNearbyRange
  • $wgMFNamespacesWithoutCollapsibleSections
  • $wgMFBetaFeedbackLink
  • $wgMFDefaultEditor
  • $wgMFEnableBeta
  • $wgMFNoindexPages
  • $wgMFUseDesktopSpecialWatchlistPage
  • $wgMFAutodetectMobileView
  • $wgMFQueryPropModules
  • $wgMFMwApiContentProviderBaseUri
  • $wgMFTrackBlockNotices
  • $wgMFMobileFormatterNamespaceBlacklist
  • $wgMFMobileHeader
翻譯MobileFrontend擴充功能如在translatewiki.net可用
检查使用和版本矩阵。
问题 尚未完成的工作 · 回報錯誤

本页是为了想要在开发端安装此扩展的用户撰写的。如果你乐于帮助我们改进,我们欢迎您参与改进

先决条件

在安装移动前端之前,如果您大量使用了模板和/或行内样式(style属性),您需要检查您的内容以确认是否对移动版友好。 TemplateStyles 扩展可以用于给内容排版,以便让内容在移动版和桌面版都有较好的渲染效果。移动前端并不会自动为您修复这些内容!

尤其请注意,您可能需要检查您的主页。 請參閱移動首頁格式

安装

  • 如果使用Vagrant ,请通过vagrant roles enable mobilefrontend --provision安装
手动安装

配置附近

移动前端提供了“Special:附近”页面,这需要一些配置。为了使其工作,需要一些可选的步骤:

  1. 由于浏览器的安全配置,您需要在使用SSL的安全站点上运行:无法通过HTTP请求用户位置。
  2. 安装GeoData扩展
  3. 运行update.php
  4. 在LocalSettings.php中加入$wgMFNearby = true;
  5. 确定文章的坐标点:
    1. 使用coordinates解析器函数来向您的文章中加入位置数据,例如{{#coordinates:37.786971|-122.399677|primary}}。 关于语法细节,参见GeoData 文档。
    2. 作为替代,您也可以为Nearby使用一个独立的MediaWiki安装,这需要在您的LocalSettings.php中设置$wgMFNearbyEndpoint。 例如,$wgMFNearbyEndpoint = 'https://en.m.wikipedia.org/w/api.php';会使用英文维基百科文章的坐标。 附近的端点将用于查找与给定位置相关的内容。

设置皮肤

移动前端提供给您适合移动版格式的网站,这与已存在的桌面版网站可以共存。您可以任意设置其皮肤。

 // Choose one of these and add chosen code to bottom of LocalSettings.php file:
 wfLoadSkin( 'MinervaNeue' );
 $wgMFDefaultSkinClass = 'SkinMinerva'; // use Minerva skin (You need to download and install it separately, otherwise you'll get an exception)
 wfLoadSkin( 'Vector' );
 $wgMFDefaultSkinClass = 'SkinVector'; // use Vector skin
 wfLoadSkin( 'Timeless' );
 $wgMFDefaultSkinClass = 'SkinTimeless'; // use Timeless skin

以下皮肤可以在移动前端使用:

  • Skin:Minerva Neue(稳定,对于维基媒体基金会的wiki是默认值)
  • Skin:Vector(默认的桌面版皮肤,对于移动版提供了实验性的响应模式)
  • Skin:Timeless(实验性皮肤)

配置设置

参见扩展:移动前端/配置

额外调整

Get the most out of MobileFrontend by adding these optional compatible extensions:

本地设置

CSS 样式

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

MobileFrontend does not load the global MediaWiki:Common.css, neither does it load any of the user stylesheets.

更多信息

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 URL query string: ?useformat=mobile. For example: https://en.wikipedia.org/wiki/Chuck_Schuldiner?useformat=mobile

If you would like to view the mobile version of a page without enabling the extension across the entire site you can append the string too the url on that page, too.

移动前端的过时功能

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

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)!

MobileView API

扩充 action=parse

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.

示例:

meta=siteinfo

The domain of the mobile version of the site (which might or might not be the same as the normal domain) is available under the mobileserver key of the general siteinfo information.

对于开发者/系统管理员

设置

您可能需要运行npm install并安装composer来运行预调试挂钩,这取决于您对扩展的配置。

使用外语维基上的文章进行测试(实时数据)

MobileFrontend can now be configured locally to render articles from other MediaWiki instances.

[2] 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.

使用移动外观

基金会网站

On Wikimedia Foundation-run sites, we use Varnish caching servers to check the user agent of your device.

非基金会网站

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 they match.

常见问题

以下问题经常在讨论页中被提出。 在您提出新话题前,请检查以下列表或检查已有的话题(如果存在的话),以答疑解惑。

Q:我应该如何自定义Minerva皮肤的主菜单?

A:这在phabricator上有记载,您可以在Topic:Tiggc18fvd3stmsf找到临时的解决方案。

Q:我应该如何在Minerva皮肤中加入HTML,例如添加广告或额外的script标签?

A:您可以通过编辑皮肤的模板文件来达到此目的(目前位于include/skins/minerva.mustache)。参见此讨论以获取更多细节。

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

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 (you can login using your MediaWiki.org username) for a quicker response.

Q: I upgraded MobileFrontend and now I'm getting a fatal exception!

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.

Q: After upgrading MediaWiki I'm getting an exception wgMFDefaultSkinClass is not setup correctly.

A: MobileFrontend currently assumes you have the 皮肤:Minerva Neue skin installed.

If you don't you'll need to install this or configure your mobile skin per instructions above.

对于扩展开发者

默认情况下,扩展中的资源模块将不会在移动视图中加载。

如果一个模块需要在移动版页面中载入,这份关于撰写对移动前端友好的模块的指南很有帮助。

参见

参考资料

  1. :Fatal error: Uncaught ExtensionDependencyError: MobileFrontend is not compatible with the current MediaWiki core (version 1.32.2), it requires: >= 1.33.0.
  2. See this YouTube demo video