2019-04-08 17:08:57 +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;
|
|
|
|
use User;
|
2019-04-08 17:08:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to build default (available for everyone by default) main menu
|
|
|
|
*/
|
2019-08-02 09:00:18 +00:00
|
|
|
final class DefaultMainMenuBuilder implements IMainMenuBuilder {
|
2019-04-08 17:08:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $showMobileOptions;
|
|
|
|
|
2020-06-25 21:06:46 +00:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $showDonateLink;
|
|
|
|
|
2019-04-08 17:08:57 +00:00
|
|
|
/**
|
|
|
|
* Currently logged in user
|
|
|
|
* @var User
|
|
|
|
*/
|
2019-07-22 20:58:34 +00:00
|
|
|
private $user;
|
2019-04-08 17:08:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Definitions
|
|
|
|
*/
|
2019-07-22 20:58:34 +00:00
|
|
|
private $definitions;
|
2019-04-08 17:08:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the Default Main Menu builder
|
|
|
|
*
|
|
|
|
* @param bool $showMobileOptions Show MobileOptions instead of Preferences
|
2020-06-25 21:06:46 +00:00
|
|
|
* @param bool $showDonateLink whether to show the donate link
|
2019-04-08 17:08:57 +00:00
|
|
|
* @param User $user The current user
|
|
|
|
* @param Definitions $definitions A menu items definitions set
|
|
|
|
*/
|
2020-06-25 21:06:46 +00:00
|
|
|
public function __construct( $showMobileOptions, $showDonateLink, User $user, Definitions $definitions ) {
|
2019-04-08 17:08:57 +00:00
|
|
|
$this->showMobileOptions = $showMobileOptions;
|
2020-06-25 21:06:46 +00:00
|
|
|
$this->showDonateLink = $showDonateLink;
|
2019-04-08 17:08:57 +00:00
|
|
|
$this->user = $user;
|
|
|
|
$this->definitions = $definitions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-22 20:58:34 +00:00
|
|
|
* @inheritDoc
|
2019-04-08 17:08:57 +00:00
|
|
|
* @throws FatalError
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2019-06-21 16:52:22 +00:00
|
|
|
public function getGroups(): array {
|
2020-06-25 21:06:46 +00:00
|
|
|
$donate = $this->showDonateLink ?
|
|
|
|
BuilderUtil::getDonateGroup( $this->definitions ) : null;
|
|
|
|
|
|
|
|
$groups = [
|
2019-07-22 20:58:34 +00:00
|
|
|
BuilderUtil::getDiscoveryTools( $this->definitions ),
|
2019-04-08 17:08:57 +00:00
|
|
|
$this->getPersonalTools(),
|
2019-07-22 20:58:34 +00:00
|
|
|
BuilderUtil::getConfigurationTools( $this->definitions, $this->showMobileOptions ),
|
2019-04-08 17:08:57 +00:00
|
|
|
];
|
2020-06-25 21:06:46 +00:00
|
|
|
if ( $donate ) {
|
|
|
|
$groups[] = $donate;
|
|
|
|
}
|
|
|
|
return $groups;
|
2019-04-08 17:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-22 20:58:34 +00:00
|
|
|
* @inheritDoc
|
2019-04-08 17:08:57 +00:00
|
|
|
* @throws MWException
|
|
|
|
*/
|
2019-07-22 20:58:34 +00:00
|
|
|
public function getSiteLinks(): Group {
|
|
|
|
return BuilderUtil::getSiteLinks( $this->definitions );
|
2019-04-08 17:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the personal tools menu item group.
|
|
|
|
*
|
|
|
|
* ... by adding the Watchlist, Settings, and Log{in,out} menu items in the given order.
|
|
|
|
*
|
|
|
|
* @return Group
|
|
|
|
* @throws FatalError
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2019-07-22 20:58:34 +00:00
|
|
|
private function getPersonalTools(): Group {
|
2019-10-23 18:30:55 +00:00
|
|
|
$group = new Group( 'p-personal' );
|
2019-04-08 17:08:57 +00:00
|
|
|
|
2019-07-22 20:58:34 +00:00
|
|
|
$this->definitions->insertAuthMenuItem( $group );
|
2019-04-08 17:08:57 +00:00
|
|
|
|
|
|
|
if ( $this->user->isLoggedIn() ) {
|
|
|
|
$this->definitions->insertWatchlistMenuItem( $group );
|
|
|
|
$this->definitions->insertContributionsMenuItem( $group );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow other extensions to add or override tools
|
|
|
|
Hooks::run( 'MobileMenu', [ 'personal', &$group ] );
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
}
|