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 MediaWiki\Minerva\Menu\Definitions;
|
2022-01-13 00:38:16 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Entries\SingleMenuEntry;
|
2019-04-08 17:08:57 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Group;
|
2024-04-16 22:52:55 +00:00
|
|
|
use MediaWiki\Title\Title;
|
|
|
|
use MediaWiki\User\User;
|
2024-02-27 14:48:47 +00:00
|
|
|
use MediaWiki\User\UserIdentityUtils;
|
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
|
|
|
|
2024-03-28 19:15:41 +00:00
|
|
|
private bool $showMobileOptions;
|
|
|
|
private bool $showDonateLink;
|
|
|
|
private User $user;
|
|
|
|
private Definitions $definitions;
|
2024-02-27 14:48:47 +00:00
|
|
|
private UserIdentityUtils $userIdentityUtils;
|
|
|
|
|
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
|
2024-04-16 22:52:55 +00:00
|
|
|
* @param User $user The current user
|
2019-04-08 17:08:57 +00:00
|
|
|
* @param Definitions $definitions A menu items definitions set
|
2024-02-27 14:48:47 +00:00
|
|
|
* @param UserIdentityUtils $userIdentityUtils
|
2019-04-08 17:08:57 +00:00
|
|
|
*/
|
2024-02-27 14:48:47 +00:00
|
|
|
public function __construct(
|
|
|
|
$showMobileOptions,
|
|
|
|
$showDonateLink,
|
2024-04-16 22:52:55 +00:00
|
|
|
User $user,
|
2024-02-27 14:48:47 +00:00
|
|
|
Definitions $definitions,
|
|
|
|
UserIdentityUtils $userIdentityUtils
|
|
|
|
) {
|
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;
|
2024-02-27 14:48:47 +00:00
|
|
|
$this->userIdentityUtils = $userIdentityUtils;
|
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
|
|
|
*/
|
2022-01-18 23:36:30 +00:00
|
|
|
public function getDiscoveryGroup( array $navigationTools ): Group {
|
|
|
|
return BuilderUtil::getDiscoveryTools( $this->definitions, $navigationTools );
|
2022-01-13 00:38:16 +00:00
|
|
|
}
|
2021-11-03 17:09:33 +00:00
|
|
|
|
2022-01-13 00:38:16 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getDonateGroup(): Group {
|
|
|
|
return BuilderUtil::getDonateGroup( $this->definitions, $this->showDonateLink );
|
|
|
|
}
|
2021-11-03 17:09:33 +00:00
|
|
|
|
2022-01-13 00:38:16 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getInteractionToolsGroup(): Group {
|
|
|
|
return new Group( 'p-interaction' );
|
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
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2022-05-12 17:58:08 +00:00
|
|
|
/**
|
|
|
|
* Builds the anonymous settings group.
|
|
|
|
*
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getSettingsGroup(): Group {
|
|
|
|
$group = new Group( 'pt-preferences' );
|
2023-06-20 16:18:13 +00:00
|
|
|
// Show settings group for anon and temp users
|
2024-02-27 14:48:47 +00:00
|
|
|
$isTemp = $this->userIdentityUtils->isTemp( $this->user );
|
2023-06-20 16:18:13 +00:00
|
|
|
if ( $this->showMobileOptions && ( !$this->user->isRegistered() || $isTemp ) ) {
|
2022-05-12 17:58:08 +00:00
|
|
|
$this->definitions->insertMobileOptionsItem( $group );
|
|
|
|
}
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
2022-01-13 00:38:16 +00:00
|
|
|
* @inheritDoc
|
2019-04-08 17:08:57 +00:00
|
|
|
*/
|
2022-01-13 00:38:16 +00:00
|
|
|
public function getPersonalToolsGroup( array $personalTools ): Group {
|
2019-10-23 18:30:55 +00:00
|
|
|
$group = new Group( 'p-personal' );
|
2023-06-10 00:09:57 +00:00
|
|
|
$excludeKeyList = [ 'betafeatures', 'mytalk', 'sandbox' ];
|
2023-05-25 15:59:04 +00:00
|
|
|
|
|
|
|
// For anonymous users exclude all links except login.
|
|
|
|
if ( !$this->user->isRegistered() ) {
|
|
|
|
$excludeKeyList = array_diff(
|
|
|
|
array_keys( $personalTools ),
|
2024-10-28 09:28:54 +00:00
|
|
|
[ 'login', 'login-private' ]
|
2023-05-25 15:59:04 +00:00
|
|
|
);
|
2022-01-13 00:38:16 +00:00
|
|
|
}
|
2024-10-28 09:28:54 +00:00
|
|
|
|
2024-02-27 14:48:47 +00:00
|
|
|
$isTemp = $this->userIdentityUtils->isTemp( $this->user );
|
2023-06-20 16:18:13 +00:00
|
|
|
if ( $isTemp ) {
|
|
|
|
$excludeKeyList[] = 'mycontris';
|
|
|
|
}
|
2023-05-25 15:59:04 +00:00
|
|
|
foreach ( $personalTools as $key => $item ) {
|
2024-04-16 22:52:55 +00:00
|
|
|
// Default to EditWatchlist if $user has no edits
|
|
|
|
// Many users use the watchlist like a favorites list without ever editing.
|
|
|
|
// [T88270].
|
|
|
|
if ( $key === 'watchlist' && $this->user->getEditCount() === 0 ) {
|
|
|
|
$item['href'] = Title::newFromText( 'Special:EditWatchlist' )->getLocalUrl();
|
|
|
|
}
|
2023-05-25 15:59:04 +00:00
|
|
|
$href = $item['href'] ?? null;
|
|
|
|
if ( $href && !in_array( $key, $excludeKeyList ) ) {
|
2022-01-13 00:38:16 +00:00
|
|
|
// Substitute preference if $showMobileOptions is set.
|
|
|
|
if ( $this->showMobileOptions && $key === 'preferences' ) {
|
|
|
|
$this->definitions->insertMobileOptionsItem( $group );
|
|
|
|
} else {
|
|
|
|
$icon = $item['icon'] ?? null;
|
|
|
|
$entry = SingleMenuEntry::create(
|
|
|
|
$key,
|
|
|
|
$item['text'],
|
2023-05-25 15:59:04 +00:00
|
|
|
$href,
|
2022-01-13 00:38:16 +00:00
|
|
|
$item['class'] ?? '',
|
|
|
|
$icon
|
|
|
|
);
|
|
|
|
|
2023-05-25 15:59:04 +00:00
|
|
|
$entry->trackClicks( $key );
|
2022-01-13 00:38:16 +00:00
|
|
|
$group->insertEntry( $entry );
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 17:08:57 +00:00
|
|
|
}
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
}
|