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;
|
|
|
|
use MediaWiki\Minerva\Menu\Group;
|
2019-06-24 17:59:11 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Entries\LanguageSelectorEntry;
|
|
|
|
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
|
2019-05-23 22:34:10 +00:00
|
|
|
use MediaWiki\Minerva\SkinUserPageHelper;
|
|
|
|
use MessageLocalizer;
|
|
|
|
use MinervaUI;
|
|
|
|
use MWException;
|
2019-06-24 17:59:11 +00:00
|
|
|
use Title;
|
2019-05-23 22:34:10 +00:00
|
|
|
use SpecialPage;
|
|
|
|
use User;
|
|
|
|
|
|
|
|
class UserNamespaceOverflowBuilder implements IOverflowBuilder {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var MessageLocalizer
|
|
|
|
*/
|
|
|
|
private $messageLocalizer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var User|null
|
|
|
|
*/
|
|
|
|
private $pageUser;
|
|
|
|
|
2019-06-24 17:59:11 +00:00
|
|
|
/**
|
|
|
|
* @var Title
|
|
|
|
*/
|
|
|
|
private $title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IMinervaPagePermissions
|
|
|
|
*/
|
|
|
|
private $permissions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $doesPageHaveLanguages;
|
|
|
|
|
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
|
|
|
|
* @param SkinUserPageHelper $userPageHelper
|
2019-06-24 17:59:11 +00:00
|
|
|
* @param IMinervaPagePermissions $permissions
|
|
|
|
* @param bool $doesPageHaveLanguages
|
2019-05-23 22:34:10 +00:00
|
|
|
*/
|
2019-06-24 17:59:11 +00:00
|
|
|
public function __construct(
|
|
|
|
Title $title,
|
|
|
|
MessageLocalizer $msgLocalizer,
|
|
|
|
SkinUserPageHelper $userPageHelper,
|
|
|
|
IMinervaPagePermissions $permissions,
|
|
|
|
$doesPageHaveLanguages
|
|
|
|
) {
|
|
|
|
$this->title = $title;
|
2019-05-23 22:34:10 +00:00
|
|
|
$this->messageLocalizer = $msgLocalizer;
|
|
|
|
$this->pageUser = $userPageHelper->getPageUser();
|
2019-06-24 17:59:11 +00:00
|
|
|
$this->permissions = $permissions;
|
|
|
|
$this->doesPageHaveLanguages = $doesPageHaveLanguages;
|
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-05-23 22:34:10 +00:00
|
|
|
$group = new Group();
|
2019-06-24 17:59:11 +00:00
|
|
|
if ( $this->permissions->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) ) {
|
|
|
|
$group->insertEntry( new LanguageSelectorEntry( $this->title,
|
|
|
|
$this->doesPageHaveLanguages, $this->messageLocalizer,
|
|
|
|
MinervaUI::iconClass( 'language-switcher-base20', 'before',
|
|
|
|
'minerva-page-actions-language-switcher toggle-list-item__anchor--menu' ),
|
|
|
|
'minerva-page-actions-language-switcher'
|
|
|
|
) );
|
|
|
|
}
|
2019-06-14 16:57:26 +00:00
|
|
|
$group->insertEntry( $this->build(
|
2019-05-23 22:34:10 +00:00
|
|
|
'uploads', 'upload', SpecialPage::getTitleFor( 'Uploads', $this->pageUser )->getLocalURL()
|
|
|
|
) );
|
|
|
|
|
|
|
|
$possibleEntries = array_filter( [
|
2019-06-14 16:57:26 +00:00
|
|
|
$this->buildFromToolbox( 'user-rights', 'userAvatar', 'userrights', $toolbox ),
|
|
|
|
$this->buildFromToolbox( 'logs', 'listBullet', 'log', $toolbox ),
|
|
|
|
$this->buildFromToolbox( 'info', 'info', 'info', $toolbox ),
|
|
|
|
$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
|
|
|
|
* @param string $icon Wikimedia UI icon 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-05-23 22:34:10 +00:00
|
|
|
* @return PageActionMenuEntry|null
|
|
|
|
*/
|
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
|
|
|
|
* @param string $icon Wikimedia UI icon name.
|
|
|
|
* @param string|null $href
|
|
|
|
* @return PageActionMenuEntry|null
|
|
|
|
*/
|
2019-06-14 16:57:26 +00:00
|
|
|
private function build( $name, $icon, $href ) {
|
2019-05-23 22:34:10 +00:00
|
|
|
return $href ?
|
|
|
|
new PageActionMenuEntry(
|
|
|
|
'page-actions-overflow-' . $name,
|
|
|
|
$href,
|
2019-06-24 17:59:11 +00:00
|
|
|
MinervaUI::iconClass( '', 'before',
|
|
|
|
'wikimedia-ui-' . $icon . '-base20 toggle-list-item__anchor--menu'
|
2019-06-20 19:17:50 +00:00
|
|
|
),
|
2019-05-23 22:34:10 +00:00
|
|
|
$this->messageLocalizer->msg( 'minerva-page-actions-' . $name )
|
|
|
|
) : null;
|
|
|
|
}
|
|
|
|
}
|