2019-07-22 20:58:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Minerva\Menu\Main;
|
|
|
|
|
|
|
|
use FatalError;
|
|
|
|
use Hooks;
|
|
|
|
use MediaWiki\Minerva\Menu\Definitions;
|
|
|
|
use MediaWiki\Minerva\Menu\Group;
|
2020-01-26 19:26:31 +00:00
|
|
|
use MWException;
|
2019-07-22 20:58:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Group generators shared between menu builders.
|
|
|
|
*
|
|
|
|
* @package MediaWiki\Minerva\Menu\Main
|
|
|
|
*/
|
|
|
|
final class BuilderUtil {
|
2020-06-25 21:06:46 +00:00
|
|
|
/**
|
|
|
|
* Prepares donate group if available
|
|
|
|
* @param Definitions $definitions A menu items definitions set
|
2022-01-13 00:38:16 +00:00
|
|
|
* @param bool $includeDonateLink whether to include it or not.
|
|
|
|
* @return Group
|
2020-06-25 21:06:46 +00:00
|
|
|
* @throws FatalError
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2022-01-13 00:38:16 +00:00
|
|
|
public static function getDonateGroup( Definitions $definitions, $includeDonateLink ): Group {
|
2020-06-25 21:06:46 +00:00
|
|
|
$group = new Group( 'p-donation' );
|
2022-01-13 00:38:16 +00:00
|
|
|
if ( $includeDonateLink ) {
|
|
|
|
$definitions->insertDonateItem( $group );
|
|
|
|
}
|
|
|
|
return $group;
|
2020-06-25 21:06:46 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 20:58:34 +00:00
|
|
|
/**
|
|
|
|
* Prepares a list of links that have the purpose of discovery in the main navigation menu
|
|
|
|
* @param Definitions $definitions A menu items definitions set
|
|
|
|
* @return Group
|
|
|
|
* @throws FatalError
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
public static function getDiscoveryTools( Definitions $definitions ): Group {
|
2019-10-23 18:30:55 +00:00
|
|
|
$group = new Group( 'p-navigation' );
|
2019-07-22 20:58:34 +00:00
|
|
|
|
|
|
|
$definitions->insertHomeItem( $group );
|
|
|
|
$definitions->insertRandomItem( $group );
|
|
|
|
$definitions->insertNearbyIfSupported( $group );
|
|
|
|
|
|
|
|
// Allow other extensions to add or override tools
|
|
|
|
Hooks::run( 'MobileMenu', [ 'discovery', &$group ] );
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Like <code>SkinMinerva#getDiscoveryTools</code> and <code>#getPersonalTools</code>, create
|
|
|
|
* a group of configuration-related menu items. Currently, only the Settings menu item is in the
|
|
|
|
* group.
|
|
|
|
* @param Definitions $definitions A menu items definitions set
|
|
|
|
* @param bool $showMobileOptions Show MobileOptions instead of Preferences
|
|
|
|
* @return Group
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
public static function getConfigurationTools(
|
|
|
|
Definitions $definitions, $showMobileOptions
|
|
|
|
): Group {
|
2019-10-23 18:30:55 +00:00
|
|
|
$group = new Group( 'pt-preferences' );
|
2019-07-22 20:58:34 +00:00
|
|
|
|
|
|
|
$showMobileOptions ?
|
|
|
|
$definitions->insertMobileOptionsItem( $group ) :
|
|
|
|
$definitions->insertPreferencesItem( $group );
|
|
|
|
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of sitelinks to add into the main menu footer.
|
|
|
|
* @param Definitions $definitions A menu items definitions set
|
|
|
|
* @return Group Collection of site links
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
public static function getSiteLinks( Definitions $definitions ): Group {
|
2019-10-23 18:30:55 +00:00
|
|
|
$group = new Group( 'p-minerva-sitelinks' );
|
2019-07-22 20:58:34 +00:00
|
|
|
|
|
|
|
$definitions->insertAboutItem( $group );
|
|
|
|
$definitions->insertDisclaimersItem( $group );
|
|
|
|
// Allow other extensions to add or override tools
|
|
|
|
Hooks::run( 'MobileMenu', [ 'sitelinks', &$group ] );
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
}
|