Jump to content

Extension:IfMobile

From mediawiki.org
This page is a translated version of the page Extension:IfMobile and the translation is 22% complete.
MediaWiki 拡張機能マニュアル
IfMobile
リリースの状態: 安定
実装 タグ
説明 Detects mobile devices and allows to control HTML and template arguments specific for mobile devices and desktops.
作者 Stano Lacko
メンテナー Stano Lacko
最新バージョン 0.2.1 (2025-02-17)
MediaWiki 1.39+
#ifmobile
ライセンス 「修正」三条項 BSD ライセンス
ダウンロード

The IfMobile extension detects mobile devices using PHP's HTTP_USER_AGENT.

The extension introduces a function called wfMobileDetect(), which returns true when a mobile device is detected, and false otherwise. The extention introduces parser function #ifmobile which allow users to control HTML content (attributes' values) and Template arguments for mobile devices and desktop devices. It creates also separated cache for mobile and desktop devices. It is very helpful, when it is very complicated to made two outputs one for mobile, one for desktop and show proper output on visitors device. IfMobile check visitor device and shows output with specific html styles, table colspan/rowspan, etc depends on device type.

インストール

  • ダウンロードして、ファイルをextensions/フォルダー内のIfMobileという名前のディレクトリ内に配置します。
  • 以下のコードを LocalSettings.php ファイルの末尾に追加します:
    wfLoadExtension( 'IfMobile' );
    
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

使用法

#ifmobile and #mobileonly parser functions

The IfMobile extension introduces the #ifmobile parser function.

Different HTML attribute for mobile and desktop

<div style="background-color:{{#ifmobile:color for mobile devices|color for desktop devices}}">Content</div>

This solution not need to create content twice as in MobileDetect extension. Because both types of devices received different HTML output (mobile with different color as desktop).

Different Template arguments for mobile and desktop

Main advantage is to control arguments send to templates and also arguments in templates themself.

{{Feature|name=City|variant=image|size={{#ifmobile:x20px|x15px}}|text=In city with blahblahblah}}

Different content for mobile and desktop

When need to create different content (similar to MobileDetect).

<div>{{#ifmobile:Content only for mobiles|Content only for desktop}}</div>

Content sent only to desktop

This solution decrease HTML file sent to mobile devices, because it not contains hidden desktop content as in MobileDevice extension.

<div>{{#ifmobile:|Content only for desktop}}</div>

関連項目