GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Main page
  • Get MediaWiki
  • Get extensions
  • Tech blog
  • Contribute
  • User help
  • FAQ
  • Technical manual
  • Support desk
  • Communication
  • Developer portal
  • Code statistics
  • Community portal
  • Recent changes

This view

  • Original page
  • New address

GeezerVison is showing www.mediawiki.org — Extension:MobileDetect - MediaWiki

MediaWiki extensions manual
MobileDetect
Release status: stable
Implementation Tag
Description Detects mobile devices and allows to control the content visible with ‎<nomobile> and ‎<mobileonly> tags, parser functions and CSS classes.
Author(s) Matthew Tran (Archivolttalk)
Maintainer(s) Sophivorus
Latest version 2.4 (2024-08-25)
MediaWiki 1.35+
Tags
‎<nomobile>, ‎<mobileonly>, #nomobile, #mobileonly
Hooks used
  • ParserFirstCallInit
  • BeforePageDisplay
Licence GNU General Public License 3.0
Download
Download extension
Git [?]:
  • Browse repository (Phabricator · GitHub)
  • Gerrit code review
  • Git commit log
  • Download source tarball
Translate the MobileDetect extension if it is available at translatewiki.net
Issues Open tasks · Report a bug

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.

Installation

  • Download and move the extracted MobileDetect folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:
    cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/MobileDetect
    
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'MobileDetect' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage

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' ); // for normal activation
// Make the global function accessible:
require_once "$IP/extensions/MobileDetect/src/Hooks.php";
require_once "$IP/extensions/MobileDetect/lib/MobileDetect.php";
// Continue as normal:
$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, 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' );
require_once "$IP/extensions/MobileDetect/src/Hooks.php";
require_once "$IP/extensions/MobileDetect/lib/MobileDetect.php";
$mobile = wfMobileDetect();
if ( ! $mobile ) {
    wfLoadExtension( 'ConfirmEdit' ); # Only load if desktop browser
}

With this code, the reCAPTCHA extension would only load on desktop 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 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 browsers. So for example:

<mobileonly>This will not be displayed in desktop browsers, only in mobile browsers</mobileonly>
<nomobile>This will not be displayed in mobile browsers, only in desktop browsers</nomobile>

The naming and behaviour of the ‎<mobileonly> and ‎<nomobile> tags follows that of the ‎<includeonly> and ‎<noinclude> tags.

The original extension don't render all multi-line content correctly.

This fork will render all multi-line content correctly.

Testpage for MobileDetect

#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.

The original extension don't render all multi-line content correctly.

This fork will render all multi-line content correctly.

Testpage for MobileDetect
Example for Template

nomobile and mobileonly classes

Alternatively, it is also possible to use the CSS classes directly:

{| class="wikitable nomobile"
|- 
| (Some wikitable stuff.)
|}

See also

  • Extension:MobileFrontend
This extension is included in the following wiki farms/hosts and/or packages:
  • Miraheze
Retrieved from "https://www.mediawiki.org/w/index.php?title=Extension:MobileDetect&oldid=8709476"
Categories:
  • Stable extensions
  • Tag extensions
  • ParserFirstCallInit extensions
  • BeforePageDisplay extensions
  • GPL licensed extensions
  • Extensions in Wikimedia version control
  • All extensions
  • Extensions included in Miraheze
  • Mobile
Hidden categories:
  • Extensions without an image
  • Extensions without a compatibility policy
  • Extensions with manual MediaWiki version
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.