2019-05-23 22:34:10 +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\PageActions;
|
|
|
|
|
|
|
|
use Hooks;
|
2019-07-09 16:10:31 +00:00
|
|
|
use MediaWiki\Minerva\LanguagesHelper;
|
2019-11-07 21:46:55 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Entries\IMenuEntry;
|
2020-01-26 19:26:31 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Entries\LanguageSelectorEntry;
|
2019-11-07 21:46:55 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Entries\SingleMenuEntry;
|
2019-05-23 22:34:10 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Group;
|
2019-06-24 17:59:11 +00:00
|
|
|
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
|
2019-05-23 22:34:10 +00:00
|
|
|
use MessageLocalizer;
|
|
|
|
use MinervaUI;
|
|
|
|
use MWException;
|
2019-06-24 17:59:11 +00:00
|
|
|
use Title;
|
2019-05-23 22:34:10 +00:00
|
|
|
|
|
|
|
class UserNamespaceOverflowBuilder implements IOverflowBuilder {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var MessageLocalizer
|
|
|
|
*/
|
|
|
|
private $messageLocalizer;
|
|
|
|
|
2019-06-24 17:59:11 +00:00
|
|
|
/**
|
|
|
|
* @var Title
|
|
|
|
*/
|
|
|
|
private $title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IMinervaPagePermissions
|
|
|
|
*/
|
|
|
|
private $permissions;
|
|
|
|
|
|
|
|
/**
|
2019-07-09 16:10:31 +00:00
|
|
|
* @var LanguagesHelper
|
2019-06-24 17:59:11 +00:00
|
|
|
*/
|
2019-07-09 16:10:31 +00:00
|
|
|
private $languagesHelper;
|
2019-06-24 17:59:11 +00:00
|
|
|
|
2019-05-23 22:34:10 +00:00
|
|
|
/**
|
|
|
|
* Initialize the overflow menu visible on the User namespace
|
2019-06-24 17:59:11 +00:00
|
|
|
* @param Title $title
|
2019-05-23 22:34:10 +00:00
|
|
|
* @param MessageLocalizer $msgLocalizer
|
2019-06-24 17:59:11 +00:00
|
|
|
* @param IMinervaPagePermissions $permissions
|
2019-07-09 16:10:31 +00:00
|
|
|
* @param LanguagesHelper $languagesHelper
|
2019-05-23 22:34:10 +00:00
|
|
|
*/
|
2019-06-24 17:59:11 +00:00
|
|
|
public function __construct(
|
|
|
|
Title $title,
|
|
|
|
MessageLocalizer $msgLocalizer,
|
|
|
|
IMinervaPagePermissions $permissions,
|
2019-07-09 16:10:31 +00:00
|
|
|
LanguagesHelper $languagesHelper
|
2019-06-24 17:59:11 +00:00
|
|
|
) {
|
|
|
|
$this->title = $title;
|
2019-05-23 22:34:10 +00:00
|
|
|
$this->messageLocalizer = $msgLocalizer;
|
2019-06-24 17:59:11 +00:00
|
|
|
$this->permissions = $permissions;
|
2019-07-09 16:10:31 +00:00
|
|
|
$this->languagesHelper = $languagesHelper;
|
2019-05-23 22:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2019-06-21 16:52:22 +00:00
|
|
|
public function getGroup( array $toolbox ): Group {
|
2019-10-23 18:30:55 +00:00
|
|
|
$group = new Group( 'p-tb' );
|
2019-06-24 17:59:11 +00:00
|
|
|
if ( $this->permissions->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) ) {
|
2019-07-09 16:10:31 +00:00
|
|
|
$group->insertEntry( new LanguageSelectorEntry(
|
|
|
|
$this->title,
|
|
|
|
$this->languagesHelper->doesTitleHasLanguagesOrVariants( $this->title ),
|
|
|
|
$this->messageLocalizer,
|
2020-04-01 23:25:04 +00:00
|
|
|
MinervaUI::iconClass( 'language-base20', 'before',
|
|
|
|
'minerva-page-actions-language-switcher', 'wikimedia' ),
|
2019-06-24 17:59:11 +00:00
|
|
|
'minerva-page-actions-language-switcher'
|
|
|
|
) );
|
|
|
|
}
|
2019-05-23 22:34:10 +00:00
|
|
|
|
|
|
|
$possibleEntries = array_filter( [
|
2019-09-05 10:10:58 +00:00
|
|
|
$this->buildFromToolbox( 'user-groups', 'userGroup', 'userrights', $toolbox ),
|
2019-06-14 16:57:26 +00:00
|
|
|
$this->buildFromToolbox( 'logs', 'listBullet', 'log', $toolbox ),
|
2019-08-29 14:52:32 +00:00
|
|
|
$this->buildFromToolbox( 'info', 'infoFilled', 'info', $toolbox ),
|
2019-06-14 16:57:26 +00:00
|
|
|
$this->buildFromToolbox( 'permalink', 'link', 'permalink', $toolbox ),
|
|
|
|
$this->buildFromToolbox( 'backlinks', 'articleRedirect', 'whatlinkshere', $toolbox )
|
2019-05-23 22:34:10 +00:00
|
|
|
] );
|
|
|
|
|
|
|
|
foreach ( $possibleEntries as $menuEntry ) {
|
|
|
|
$group->insertEntry( $menuEntry );
|
|
|
|
}
|
|
|
|
Hooks::run( 'MobileMenu', [ 'pageactions.overflow', &$group ] );
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-06-14 16:57:26 +00:00
|
|
|
* Build entry based on the $toolbox element
|
|
|
|
*
|
2019-05-23 22:34:10 +00:00
|
|
|
* @param string $name
|
[UI] [new] add user menu
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
2019-06-25 20:12:58 +00:00
|
|
|
* @param string $icon Icon CSS class name.
|
2019-06-14 16:57:26 +00:00
|
|
|
* @param string $toolboxIdx
|
|
|
|
* @param array $toolbox An array of common toolbox items from the sidebar menu
|
2019-11-07 21:46:55 +00:00
|
|
|
* @return IMenuEntry|null
|
2019-05-23 22:34:10 +00:00
|
|
|
*/
|
2019-06-14 16:57:26 +00:00
|
|
|
private function buildFromToolbox( $name, $icon, $toolboxIdx, array $toolbox ) {
|
|
|
|
return $this->build( $name, $icon, $toolbox[$toolboxIdx]['href'] ?? null );
|
2019-05-23 22:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-06-14 16:57:26 +00:00
|
|
|
* Build single Menu entry
|
|
|
|
*
|
2019-05-23 22:34:10 +00:00
|
|
|
* @param string $name
|
2020-04-29 21:49:59 +00:00
|
|
|
* @param string $icon WikimediaUI icon name.
|
2019-05-23 22:34:10 +00:00
|
|
|
* @param string|null $href
|
2019-11-07 21:46:55 +00:00
|
|
|
* @return IMenuEntry|null
|
2019-05-23 22:34:10 +00:00
|
|
|
*/
|
2019-06-14 16:57:26 +00:00
|
|
|
private function build( $name, $icon, $href ) {
|
2019-05-23 22:34:10 +00:00
|
|
|
return $href ?
|
2019-11-07 21:46:55 +00:00
|
|
|
SingleMenuEntry::create(
|
2019-05-23 22:34:10 +00:00
|
|
|
'page-actions-overflow-' . $name,
|
2020-01-24 06:23:39 +00:00
|
|
|
$this->messageLocalizer->msg( 'minerva-page-actions-' . $name )->text(),
|
2020-04-01 23:25:04 +00:00
|
|
|
$href
|
|
|
|
)->setIcon( $icon, 'before' )
|
2019-11-07 21:46:55 +00:00
|
|
|
->trackClicks( $name ) : null;
|
2019-05-23 22:34:10 +00:00
|
|
|
}
|
|
|
|
}
|