When a user clicks on the Mobile link at the bottom of a page, a cookie is set mf_useformat
. This extension doesn't currently check for the presence of that cookie. I have created Phabricator task T373268 to deal with this, and have attached Patch 1065831 to the task to fix this. I have tested on an external wiki and the patch is working well.
Extension talk:MobileDetect
Merged, thanks!
could you please provide an example on the extension page like the one for the tags? I get raw code on my phone when using #mobileonly with nested templates, but it does work with #nomobile.
Thanks in advance!
I did a fork of this extension
and a test wiki with examples:
- Account: Guest, PW: WikiForMen
Version 2.1 of this extension converted <mobileonly>stuff</mobileonly>
into something like <div>stuff</div>
.
Version 2.2 of this extension converted <mobileonly>stuff</mobileonly>
into something like <span>stuff</span>
.
In my fork (version 3.0) it works as I think it should.
See the corresponding examples. (Pay special attention to test 6.)--WikiForMen (talk) 19:15, 26 December 2022 (UTC)
Thanks! With the 3.0 there are no parser functions installed, but the tags are working for me. Thank you again!
In the fork (version 3.0) parser functions ARE installed but work in a different way. ;-)
- Version 2.1
- The parser functions convert
<mobileonly>stuff</mobileonly>
into something like<div class="mobileonly">stuff</div>
, which becomes<div style="display: none;">stuff</div>
.<nomobile>stuff</nomobile>
into something like<div class="nomobile">stuff</div>
, which becomes<div style="">stuff</div>
.
- and vice versa.
- Version 2.2
- The parser functions convert
<mobileonly>stuff</mobileonly>
into something like<span class="mobileonly">stuff</span>
, which becomes<span style="display: none;">stuff</span>
.<nomobile>stuff</nomobile>
into something like<span class="nomobile">stuff</span>
, which becomes<span style="">stuff</span>
.
- and vice versa.
- Version 3.0 (fork)
- The parser functions removes from
<mobileonly>mobile stuff</mobileonly>
the tag AND the "mobile stuff":.
<nomobile>desktop stuff</nomobile>
only the tag and shows the "desktop stuff":desktop stuff
.
- and vice versa:
<mobileonly>mobile stuff</mobileonly>
only the tag and shows the "mobile stuff":mobile stuff
.<nomobile>desktop stuff</nomobile>
the tag AND the "desktop stuff":.
And in my humble opinion, the parser functions have to work this way and not with the css "gimmiks" of the traditional extension versions.--WikiForMen (talk) 00:41, 27 December 2022 (UTC)
I was trying to use this extension on my wiki (MW1.35) in a template to display different Main Page according to the device, but it seems not working.
I created Template:MP :
<nomobile>{{{1}}}<nomobile> <mobileonly>{{{2}}}</mobileonly>
When i use {{Template:MP|Main page for Desktop|Main page for Mobile}} it renders variables as plain text, and does not replace the content.
Hi, I just introduced equivalent #nomobile and #mobileonly parser functions that should work on templates. Please download the latest version 2.4 and let me know of any issues!
In your extension, the above example does NOT work. Please see test 6. --WikiForMen (talk) 19:51, 26 December 2022 (UTC)
You can not do simple things like
I'm working with my “<mobileonly>mobile device</mobileonly><nomobile>desktop</nomobile>” the hole day long.
because it will be expanded as
I'm working with my “<div style="">mobile device</div><div style="display: none;">desktop</div>” the hole day long.
so the <div>
tag will break the paragraph. :-(
- "I'm working with my “mobile device” the hole day long."
I changed divs for spans in version 2.3+
Spans should be able to do all divs did before but without this issue you point out.
I have only commented on the most obvious.
I see only a few use cases where it is a matter of showing and hiding some text passages. When I was investigating this extension a few years ago, I was looking for a solution to support different layouts for desktop and mobile devices. I envisaged a three to four column layout for desktop, while it should be only one column for mobile devices.
Below is a simple example to illustrate the idea. It does not work with the 2.x extension. With the version in my fork, however, the example works.
- Remark
- On desktops it should show four colums, on mobile devices one column.
; You see this on a <nomobile>desktop</nomobile><mobileonly>mobile device</mobileonly>
<table class="wikitable" width="100%">
<tr>
<td width="<nomobile>25</nomobile><mobileonly>100</mobileonly>%">1. CELL</td>
<mobileonly></tr><tr></mobileonly>
<td width="<nomobile>25</nomobile><mobileonly>100</mobileonly>%">2. CELL</td>
<mobileonly></tr><tr></mobileonly>
<td width="<nomobile>25</nomobile><mobileonly>100</mobileonly>%">3. CELL</td>
<mobileonly></tr><tr></mobileonly>
<td width="<nomobile>25</nomobile><mobileonly>100</mobileonly>%">4. CELL</td>
</tr><tr>
<td>5. CELL</td>
<mobileonly></tr><tr></mobileonly>
<td>6. CELL</td>
<mobileonly></tr><tr></mobileonly>
<td>7. CELL</td>
<mobileonly></tr><tr></mobileonly>
<td>8. CELL</td>
</tr>
</table>
<div style="width:<nomobile>24.5</nomobile><mobileonly>100</mobileonly>%; border:1px solid green; float:left;">1. cell</div>
<div style="width:<nomobile>24.5</nomobile><mobileonly>100</mobileonly>%; border:1px solid green; float:left;">2. cell</div>
<div style="width:<nomobile>24.5</nomobile><mobileonly>100</mobileonly>%; border:1px solid green; float:left;">3. cell</div>
<div style="width:<nomobile>24.5</nomobile><mobileonly>100</mobileonly>%; border:1px solid green; float:left;">4. cell</div>
<div style="width:<nomobile>24.5</nomobile><mobileonly>100</mobileonly>%; border:1px solid green; float:left;">5. cell</div>
<div style="width:<nomobile>24.5</nomobile><mobileonly>100</mobileonly>%; border:1px solid green; float:left;">6. cell</div>
<div style="width:<nomobile>24.5</nomobile><mobileonly>100</mobileonly>%; border:1px solid green; float:left;">7. cell</div>
<div style="width:<nomobile>24.5</nomobile><mobileonly>100</mobileonly>%; border:1px solid green; float:left;">8. cell</div>
<br style="clear:both" />
; This will someone see on a <nomobile>mobile device</nomobile><mobileonly>desktop</mobileonly>
<table class="wikitable" width="100%">
<tr>
<td width="<nomobile>100</nomobile><mobileonly>25</mobileonly>%">1. CELL</td>
<nomobile></tr><tr></nomobile>
<td width="<nomobile>100</nomobile><mobileonly>25</mobileonly>%">2. CELL</td>
<nomobile></tr><tr></nomobile>
<td width="<nomobile>100</nomobile><mobileonly>25</mobileonly>%">3. CELL</td>
<nomobile></tr><tr></nomobile>
<td width="<nomobile>100</nomobile><mobileonly>25</mobileonly>%">4. CELL</td>
</tr><tr>
<td>5. CELL</td>
<nomobile></tr><tr></nomobile>
<td>6. CELL</td>
<nomobile></tr><tr></nomobile>
<td>7. CELL</td>
<nomobile></tr><tr></nomobile>
<td>8. CELL</td>
</tr>
</table>
<div style="width:<nomobile>100</nomobile><mobileonly>24.5</mobileonly>%; border:1px solid green; float:left;">1. cell</div>
<div style="width:<nomobile>100</nomobile><mobileonly>24.5</mobileonly>%; border:1px solid green; float:left;">2. cell</div>
<div style="width:<nomobile>100</nomobile><mobileonly>24.5</mobileonly>%; border:1px solid green; float:left;">3. cell</div>
<div style="width:<nomobile>100</nomobile><mobileonly>24.5</mobileonly>%; border:1px solid green; float:left;">4. cell</div>
<div style="width:<nomobile>100</nomobile><mobileonly>24.5</mobileonly>%; border:1px solid green; float:left;">5. cell</div>
<div style="width:<nomobile>100</nomobile><mobileonly>24.5</mobileonly>%; border:1px solid green; float:left;">6. cell</div>
<div style="width:<nomobile>100</nomobile><mobileonly>24.5</mobileonly>%; border:1px solid green; float:left;">7. cell</div>
<div style="width:<nomobile>100</nomobile><mobileonly>24.5</mobileonly>%; border:1px solid green; float:left;">8. cell</div>
<br style="clear:both" />
Could you link to your fork so I can learn from it?
"Learn from it"?
The hack I did in my fork I published here, see chapter "Version 3.0".--WikiForMen (talk) 14:04, 4 October 2022 (UTC)
I have created a special version of the extension to be able to test different scenarios simultaneously. For this purpose, I have created a test page on which several tasks are created. I hope this helps you. See here! --WikiForMen (talk) 12:38, 4 October 2022 (UTC)
I have added markers in nested structures for more testing... --WikiForMen (talk) 13:59, 4 October 2022 (UTC)
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.
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!
Why the Release Status remains "beta"?!??
There are only two options to work with desktop/mobile devices in Mediawiki as of 1.37.
Either use tags <span class="nomobile">hide this</span> or <div class="nomobile">hide this</div> for desktop. And similarly <span class="mobileonly">hide this</span> or <div class="mobileonly">hide this</div> for mobile devices. This will work in templates but the code will only be hidden, still downloaded completely to both desktop and mobile including any (huge) images.
Or use the extension:MobileDetect which is still compatible with 1.37 but it has been in Beta status for four years which means it can become Unmaintained in the future. It will not work in templates only in the pages but only the mobile/desktop part will be downloaded.
Your choice: between rock and the hard place. MobileFrontend has been around for 8 years, magic word indicating mobile access could have been part of the core.
Hello, Sophivorus, I wonder why this works not out in this test page ? https://fr.wikipedia.org/wiki/Utilisateur:Bouzinac#Test_mobiles
Does this extension work only for those that activated the specific code ?
Hi! As you can see from https://fr.wikipedia.org/wiki/Sp%C3%A9cial:Version, this extension is not activated on the French Wikipedia, nor any Wikimedia project for that matter.