Extension:MobileDetect
リリースの状態: 不明 |
|
|---|---|
| 実装 | タグ |
| 説明 | Detects mobile devices and allows to control the content visible with <nomobile> and <mobileonly> tags, parser functions and CSS classes. |
| 作者 | Matthew Tran (Archivoltトーク) |
| メンテナー | Sophivorus |
| 最新バージョン | 2.4 (2024-08-25) |
| MediaWiki | 1.35+ |
| ライセンス | GNU 一般公衆利用許諾書 3.0 |
| ダウンロード | |
<nomobile>, <mobileonly>, #nomobile, #mobileonly |
|
| translatewiki.net で翻訳を利用できる場合は、MobileDetect 拡張機能の翻訳にご協力ください | |
| 問題点 | 未解決のタスク · バグを報告 |
The MobileDetect extension detects mobile devices using PHP's HTTP_USER_AGENT.
Due to the nature of the extension, it should be very compatible with both new and old versions of MediaWiki.
The extension introduces a function called wfMobileDetect(), which returns true when a mobile device is detected, and false otherwise.
It also introduces <nomobile> and <mobileonly> tags, parser functions and CSS classes which allow users to control which content is displayed only in mobile browsers, and which content is displayed only in desktop browsers.
インストール
- ダウンロードして、ファイルを
extensions/フォルダー内のMobileDetectという名前のディレクトリ内に配置します。
開発者とコード寄稿者は、上記の代わりに以下を使用してGitからインストールします:cd extensions/ git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/MobileDetect
- 以下のコードを LocalSettings.php ファイルの末尾に追加します:
wfLoadExtension( 'MobileDetect' );
完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。
MediaWiki 1.38以前を稼働させている利用者へ:
上記の手順では、wfLoadExtension()を使用してこの拡張機能をインストールする新しい方法を記載しています。
この拡張機能をこれらの過去のバージョン (MediaWiki 1.38以前) にインストールする必要がある場合は、wfLoadExtension( 'MobileDetect' );の代わりに以下を使用する必要があります:
require_once "$IP/extensions/MobileDetect/MobileDetect.php";
使用法
wfMobileDetect()
If you would like to set a default theme depending on a visitor's browser, you can add this to your LocalSettings.php:
wfLoadExtension( 'MobileDetect' );
$mobile = wfMobileDetect();
if ( $mobile ) {
$wgDefaultSkin = "chick"; # If mobile
} else {
$wgDefaultSkin = "vector"; # If not mobile
}
With this code, if the visitor's browser shows a user agent from a mobile browser, the default theme will be chick instead of vector.
If instead the browser shows a user agent from a desktop/full browser, the default theme will be vector instead of chick.
If you would like a certain extension to be excluded from loading on mobile browsers, you can add this to your LocalSettings.php:
wfLoadExtension( 'MobileDetect' );
$mobile = wfMobileDetect();
if ( ! $mobile ) {
wfLoadExtension( 'ConfirmEdit' ); # Only load if desktop browser
}
With this code, the reCAPTCHA extension would only load on desktop/full browsers.
<nomobile> and <mobileonly> tags
The MobileDetect extension also introduces the <nomobile> and <mobileonly> tags, which allow users to control which content is displayed in mobile browsers, and which in desktop/full browsers.
Whatever is wrapped between <mobileonly> tags will only be displayed in mobile browsers, and whatever is wrapped between <nomobile> tags will only be displayed in desktop/full browsers.
So for example:
<mobileonly>This will not be displayed in desktop/full browsers, only in mobile browsers</mobileonly>
<nomobile>This will not be displayed in mobile browsers, only in desktop/full browsers</nomobile>
The naming and behaviour of the <mobileonly> and <nomobile> tags follows that of the <includeonly> and <noinclude> tags.
This fork will render all multi-line content correctly.
#nomobile and #mobileonly parser functions
The MobileDetect extension also introduces the #nomobile and #mobileonly parser functions, which work exactly like the <nomobile> and <mobileonly> tags, with the difference that their content gets parsed so they can contain stuff like {{{1}}} and be used in templates.
However, they don't render all multi-line content correctly, so use them mostly for inline content.
This fork will render all multi-line content correctly.
nomobile and mobileonly classes
Alternatively, it is also possible to use the CSS classes directly:
{| class="wikitable nomobile"
|-
| (Some wikitable stuff.)
|}
関連項目
| この拡張機能は以下のウィキ ファーム/ウィキ ホスト/パッケージに含まれています: これは正式な一覧ではありません。 一部のウィキ ファーム/ウィキ ホスト/パッケージは、ここに記載されていなくてもこの拡張機能を含んでいる場合があります。 必ずご利用のウィキ ファーム、ウィキ ホスト、バンドルで確認してください。 |
- Extensions with invalid status/ja
- Tag extensions/ja
- GPL licensed extensions/ja
- Extensions in Wikimedia version control/ja
- ParserFirstCallInit extensions/ja
- BeforePageDisplay extensions/ja
- All extensions/ja
- Extensions still supporting pre-registration versions
- Extensions included in Miraheze/ja
- Extensions included in WikiForge/ja
- Mobile/ja
