Extension:MobileFrontend/MobileMenu

From MediaWiki.org
Jump to navigation Jump to search
MobileMenu
Available from version master (Gerrit change 260948)
Allows other extensions to add or override items of the mobile menu (hamburger menu) and some other toolbars.
Define function:
public static function onMobileMenu( $name, \MobileFrontend\MenuBuilder &$menu ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"MobileMenu": "MyExtensionHooks::onMobileMenu"
	}
}

For MediaWiki ≤1.25:

$wgHooks['MobileMenu'][] = 'MyExtensionHooks::onMobileMenu';
Called from:File(s): in the MinervaNeue skin (previously, in the MobileFrontend extension)

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:MobileMenu extensions.

Allows other extensions to add or override items of the mobile menu (hamburger menu).

Details[edit]

  • $name: The toolbar or menu section name which $menu represents. Currently the hook will be called with the following names (note that some of these will be missing when not applicable, not allowed etc):
    • discovery: top section of the hamburger menu; by default contains Home, Random, and Nearby if the relevant extension is installed
    • personal: second section of the hamburger menu, when AMC is not enabled; by default Login/Logout, Watchlist, Contributions
    • sitetools: second section of the hamburger menu, when AMC is enabled; by default Recent changes, Special pages, Community portal
    • sitelinks: small links at the bottom of the hamburger menu, by default About and Disclaimers (note there is no way to alter or expand the part of the menu between this and sitetools, which contains the link to settings)
    • user separate toolbar accessible next to notifications, only when AMC is enabled; by default User page, Talk, Sandbox, Watchlist, Contributions, Login/Logout
    • pageactions.toolbar common page tools, on top of the content; by default Language, Watch, History, Edit
    • pageactions.overflow less common page tools (accessible with a dropdown next to the common ones, only when AMC is enabled); by default Page information, Permanent link, What links here, Wikidata item, Cite page, Download PDF
  • &$menu: Group object

Example[edit]

Add this to LocalSettings.php to add a link to the file upload page at the bottom of the contribution tools section of the mobile menu:

$wgHooks['MobileMenu'][] = function ( $name, \MobileFrontend\MenuBuilder &$menu ) {
    if ( $name !== 'personal' && $name !== 'sitetools' ) {
        return;
    }
    $menu->insert( 'Upload' )
        ->addComponent(
            $this->msg( 'mobile-frontend-upload-button' )->escaped(),
            SpecialPage::getTitleFor( 'Upload' )->getLocalUrl() . '#/upload',
            MobileUI::iconClass( 'mf-upload-invert', 'before' ),
            [
                'id' => 'uploadButton',
                'data-event-name' => 'upload',
            ]
        );