Main menu should link to EditWatchlist by default for users that haven't edited

This moves poorly documented logic from MobileFrontend to Minerva.

Bug: T362338
Change-Id: I7d73044ad26b089c7225a4a5be6772398946b9f8
This commit is contained in:
Jon Robson 2024-04-16 15:52:55 -07:00 committed by Jdlrobson
parent 83c0b7d907
commit 530b7fd900

View file

@ -23,7 +23,8 @@ namespace MediaWiki\Minerva\Menu\Main;
use MediaWiki\Minerva\Menu\Definitions;
use MediaWiki\Minerva\Menu\Entries\SingleMenuEntry;
use MediaWiki\Minerva\Menu\Group;
use MediaWiki\User\UserIdentity;
use MediaWiki\Title\Title;
use MediaWiki\User\User;
use MediaWiki\User\UserIdentityUtils;
/**
@ -43,7 +44,7 @@ final class DefaultMainMenuBuilder implements IMainMenuBuilder {
/**
* Currently logged in user
* @var UserIdentity
* @var User
*/
private $user;
@ -59,14 +60,14 @@ final class DefaultMainMenuBuilder implements IMainMenuBuilder {
*
* @param bool $showMobileOptions Show MobileOptions instead of Preferences
* @param bool $showDonateLink whether to show the donate link
* @param UserIdentity $user The current user
* @param User $user The current user
* @param Definitions $definitions A menu items definitions set
* @param UserIdentityUtils $userIdentityUtils
*/
public function __construct(
$showMobileOptions,
$showDonateLink,
UserIdentity $user,
User $user,
Definitions $definitions,
UserIdentityUtils $userIdentityUtils
) {
@ -143,6 +144,12 @@ final class DefaultMainMenuBuilder implements IMainMenuBuilder {
$excludeKeyList[] = 'mycontris';
}
foreach ( $personalTools as $key => $item ) {
// 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();
}
$href = $item['href'] ?? null;
if ( $href && !in_array( $key, $excludeKeyList ) ) {
// Substitute preference if $showMobileOptions is set.