mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-15 18:29:50 +00:00
0a4f5b6126
Add new user menu. The changes required include: - Break up AuthMenuEntry into reusable components. They're now simple, independent, static functions in AuthUtil that are easy to reason about and compose. There's lots of verbose code because of the builder and director patterns. That is, most of the code is for building the thing we actually want to build instead of just building it. It's easy to write but no fun to read--even simple configurations are extremely verbose expressions that must be threaded through the system. These builders are also single purpose and unlikely to be reusable unlike a URI builder, for example. As objects, they're not especially composable either. - Similarly, break up Menu/DefaultBuilder into BuilderUtil and ban inheritance. Inheritance has not worked well on the frontend of MobileFrontend. I don't think it's going to work well here. E.g., I could have made changes to the base class' getPersonalTools() method such that the client passes a parameter for the advanced config or maybe I just override it in the subclass. In either case, I think it makes the whole hierarchy nuanced and harder to reason about for something that should be simple. - Add ProfileMenuEntry and LogOutMenuEntry for the user menu. - Rename insertLogInOutMenuItem() to insertAuthMenuItem() which matches the entry name, AuthMenuEntry. - Extension:SandboxLink is needed to display the sandbox link in the user menu. - Performance note: the toolbar is now processed in MinervaTemplate, which corresponds to removing the buildPersonalUrls() override. - To mimic the design of main menu, the following steps would be necessary: 1. Create a user/Default and user/Advanced user menu builder and also a user/IBuilder interface. 2. Create a user/Director. 3. Create a service entry for Minerva.Menu.UserDirector in ServiceWiring. The Director is actually powerless and doesn't get to make any decisions--the appropriate builder is passed in from ServiceWiring which checks the mode. 4. Access the service in SkinMinerva to set a userMenuHTML data member on the Minerva QuickTemplate. 5. In MinervaTemplate, access the userMenuHTML QuickTemplate member and do the usual song and dance of inflating a Mustache template. This patch does everything except add a service, which was agreed to be unnecessary, so that logic is now in SkinMinerva. - Wrap the existing echo user notifications button and new user menu button in a nav element. This seems like a semantic improvement. - The existing styling and logic for the search bar and search overlay are pretty messy and delicate. Changes made to that LESS endeavored to be surgical. There's lots of room for improvement in the toolbar but it's out of scope. - Rename logout icon to logOut. Bug: T214540 Change-Id: Ib517864fcf4e4d611e05525a6358ee6662fe4e05
101 lines
2.6 KiB
PHP
101 lines
2.6 KiB
PHP
<?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\User;
|
|
|
|
use IContextSource;
|
|
use MediaWiki\Minerva\Menu\Definitions;
|
|
use MediaWiki\Minerva\Menu\Entries\ProfileMenuEntry;
|
|
use MediaWiki\Minerva\Menu\Entries\SingleMenuEntry;
|
|
use MediaWiki\Minerva\Menu\Group;
|
|
use User;
|
|
|
|
/**
|
|
* Logged-in, advanced Mobile Contributions user menu config generator.
|
|
*/
|
|
final class AdvancedUserMenuBuilder implements IUserMenuBuilder {
|
|
/**
|
|
* @var IContextSource
|
|
*/
|
|
private $context;
|
|
|
|
/**
|
|
* @var User
|
|
*/
|
|
private $user;
|
|
|
|
/**
|
|
* @var Definitions
|
|
*/
|
|
private $definitions;
|
|
|
|
/**
|
|
* @var array|null
|
|
*/
|
|
private $sandbox;
|
|
|
|
/**
|
|
* @param IContextSource $context
|
|
* @param User $user
|
|
* @param Definitions $definitions A menu items definitions set
|
|
* @param array|null $sandbox
|
|
*/
|
|
public function __construct(
|
|
IContextSource $context, User $user, Definitions $definitions, $sandbox
|
|
) {
|
|
$this->context = $context;
|
|
$this->user = $user;
|
|
$this->definitions = $definitions;
|
|
$this->sandbox = $sandbox;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @return Group
|
|
*/
|
|
public function getGroup(): Group {
|
|
$group = new Group();
|
|
$group->insertEntry( new ProfileMenuEntry( $this->user ) );
|
|
$group->insertEntry( new SingleMenuEntry(
|
|
'userTalk',
|
|
$this->context->msg( 'mobile-frontend-user-page-talk' )->escaped(),
|
|
$this->user->getUserPage()->getTalkPage()->getLocalURL(),
|
|
true,
|
|
null,
|
|
'before',
|
|
'wikimedia-ui-userTalk-base20'
|
|
) );
|
|
if ( $this->sandbox ) {
|
|
$group->insertEntry( new SingleMenuEntry(
|
|
'userSandbox',
|
|
$this->sandbox['text'],
|
|
$this->sandbox['href']
|
|
) );
|
|
}
|
|
$this->definitions->insertWatchlistMenuItem( $group );
|
|
$this->definitions->insertContributionsMenuItem( $group );
|
|
if ( $this->user->isAnon() ) {
|
|
$this->definitions->insertLogInMenuItem( $group );
|
|
} else {
|
|
$this->definitions->insertLogOutMenuItem( $group );
|
|
}
|
|
return $group;
|
|
}
|
|
}
|