Topic on Extension talk:MobileDetect

Summary by Sophivorus

Documentation is for the latest (master) version. Older versions use mobiledetect() and require_once.

Cojoilustrado (talkcontribs)

Grea extension. Seriously.

But I had a problem after upgrading to 1.38.2 from 1.37.x. This just didn't work when I used this code provided in the instructions.


wfLoadExtension( 'MobileDetect' );

$mobile = wfMobileDetect();

if ( $mobile ) {

$wgDefaultSkin = "chick"; # If mobile

} else {

$wgDefaultSkin = "vector"; # If not mobile

}


But when I use the beta code I was using before the upgrade...


$mobile = mobiledetect();

if ( $mobile === true ) {

$wgDefaultSkin = "chick"; # If mobile

} else {

$wgDefaultSkin = "vector"; # If not mobile

}


...it works.


I also have to use

require_once "$IP/extensions/MobileDetect/MobileDetect.php";

because

wfLoadExtension( 'MobileFrontend' );

breaks the site.


What am I doing wrong?

I'm using version 2.1 (b50b1d0), which is the one that downloads for 1.38.

Sophivorus (talkcontribs)

Hi! I think the problem is that the documentation at Extension:MobileDetect is for the latest (2.4) version. In previous versions, the function was called mobiledetect() and the extension had to be loaded via require_once. You can keep your 2.1 version and use it with mobiledetect and require_once, or you can download the latest (master) version and use it with wfMobileDetect() and wfLoadExtension() (it should work fine with your 1.38 or 1.37 installations). Cheers!