Extension:MobileDetect/cs

Category:GPL licensed extensions/cs
Příručka k rozšířením MediaWiki
MobileDetect
Stav rozšíření: neznáméCategory:Extensions with invalid status/cs
Implementace Značka Category:Tag extensions/cs
Popis Detekuje mobilní zařízení a umožňuje ovládat viditelný obsah pomocí tagů <nomobile> a <mobileonly>, parserových funkcí a CSS tříd.
Autoři Matthew Tran (Archivoltdiskuse)
Správci Sophivorus
Nejnovější verze 2.4 (2024-08-25)
MediaWiki 1.35+Category:Extensions with manual MediaWiki version
Licence GNU General Public License 3.0
Stáhnout Category:Extensions in Wikimedia version control/cs
<nomobile>, <mobileonly>, #nomobile, #mobileonly
Čtvrtletní stahování 25 (Ranked 71st)
Přeložte rozšíření MobileDetect, používá-li lokalizaci z translatewiki.net
Problémy Otevřené úkoly · Nahlásit chybu
Category:All extensions/cs

Rozšíření MobileDetect detekuje mobilní zařízení pomocí rozšíření HTTP_USER_AGENT v PHP. Vzhledem k povaze rozšíření by mělo být velmi dobře kompatibilní s novými i starými verzemi 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.

Instalace

  • Stáhněte soubor/y a vložte je do adresáře pojmenovaného MobileDetect ve vaší složce extensions/.
    Vývojáři a přispěvatelé kódu by si místo toho měli nainstalovat rozšíření from Git pomocí:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/MobileDetect
  • Na konec vašeho souboru LocalSettings.php přidejte následující kód:
    wfLoadExtension( 'MobileDetect' );
    
  • Yes Dokončeno – Přejděte na stránku Special:Version vaší wiki a zkontrolujte, zda bylo rozšíření úspěšně nainstalováno. Category:Extensions still supporting pre-registration versions

Pro ty, kteří používají MediaWiki 1.38 a starší:

Výše uvedené instrukce se týkají instalace přes wfLoadExtension(), což je novější způsob instalace rozšíření. Pokud potřebujete toto rozšíření nainstalovat na starší verzi (MediaWiki 1.38 či starší), musíte místo wfLoadExtension( 'MobileDetect' ); použít:

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

Použití

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.

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

Category:Mobile/cs
Category:All extensions/cs Category:BeforePageDisplay extensions/cs Category:Extensions in Wikimedia version control/cs Category:Extensions included in Miraheze/cs Category:Extensions included in WikiForge/cs Category:Extensions still supporting pre-registration versions Category:Extensions with invalid status/cs Category:Extensions with manual MediaWiki version Category:GPL licensed extensions/cs Category:Mobile/cs Category:ParserFirstCallInit extensions/cs Category:Tag extensions/cs