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 MessageLocalizer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Director responsible for building Page Actions menu.
|
|
|
|
* This class is stateless.
|
|
|
|
*/
|
|
|
|
final class PageActionsDirector {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ToolbarBuilder
|
|
|
|
*/
|
|
|
|
private $toolbarBuilder;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IOverflowBuilder
|
|
|
|
*/
|
|
|
|
private $overflowBuilder;
|
|
|
|
|
|
|
|
/**
|
2019-07-14 14:44:29 +00:00
|
|
|
* @var MessageLocalizer
|
2019-05-23 22:34:10 +00:00
|
|
|
*/
|
|
|
|
private $messageLocalizer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Director responsible for Page Actions menu building
|
|
|
|
*
|
2021-12-17 10:29:11 +00:00
|
|
|
* @param ToolbarBuilder $toolbarBuilder
|
2019-05-23 22:34:10 +00:00
|
|
|
* @param IOverflowBuilder $overflowBuilder The overflow menu builder
|
|
|
|
* @param MessageLocalizer $messageLocalizer Message localizer used to translate texts
|
|
|
|
*/
|
2019-07-09 16:10:31 +00:00
|
|
|
public function __construct(
|
|
|
|
ToolbarBuilder $toolbarBuilder,
|
|
|
|
IOverflowBuilder $overflowBuilder,
|
|
|
|
MessageLocalizer $messageLocalizer
|
|
|
|
) {
|
2019-05-23 22:34:10 +00:00
|
|
|
$this->toolbarBuilder = $toolbarBuilder;
|
|
|
|
$this->overflowBuilder = $overflowBuilder;
|
|
|
|
$this->messageLocalizer = $messageLocalizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the menu data array that can be passed to views/javascript
|
2019-06-14 16:57:26 +00:00
|
|
|
* @param array $toolbox An array of common toolbox items from the sidebar menu
|
2021-03-09 19:43:14 +00:00
|
|
|
* @param array $actions An array of actions usually bucketed under the more menu
|
2019-05-23 22:34:10 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2021-03-09 19:43:14 +00:00
|
|
|
public function buildMenu( array $toolbox, array $actions ): array {
|
2019-07-09 16:10:31 +00:00
|
|
|
$toolbar = $this->toolbarBuilder->getGroup();
|
2021-03-09 19:43:14 +00:00
|
|
|
$overflowMenu = $this->overflowBuilder->getGroup( $toolbox, $actions );
|
2019-05-23 22:34:10 +00:00
|
|
|
|
|
|
|
$menu = [
|
|
|
|
'toolbar' => $toolbar->getEntries()
|
|
|
|
];
|
|
|
|
if ( $overflowMenu->hasEntries() ) {
|
2021-10-19 18:45:43 +00:00
|
|
|
// See includes/Skins/ToggleList.
|
2023-08-08 23:33:28 +00:00
|
|
|
$toggleID = 'page-actions-overflow-toggle';
|
|
|
|
$checkboxID = 'page-actions-overflow-checkbox';
|
2019-05-23 22:34:10 +00:00
|
|
|
$menu[ 'overflowMenu' ] = [
|
|
|
|
'item-id' => 'page-actions-overflow',
|
2023-08-08 23:33:28 +00:00
|
|
|
'checkboxID' => $checkboxID,
|
|
|
|
'toggleID' => $toggleID,
|
|
|
|
'data-btn' => [
|
|
|
|
'tag-name' => 'label',
|
|
|
|
'data-icon' => [
|
|
|
|
'icon' => 'minerva-ellipsis',
|
|
|
|
],
|
|
|
|
'classes' => 'toggle-list__toggle mw-ui-icon-with-label-desktop',
|
|
|
|
'array-attributes' => [
|
|
|
|
[
|
|
|
|
'key' => 'id',
|
|
|
|
'value' => $toggleID,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'for',
|
|
|
|
'value' => $checkboxID,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'aria-hidden',
|
|
|
|
'value' => 'true'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'data-event-name',
|
|
|
|
'value' => 'ui.overflowmenu',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
// class = toggle-list__toggle {{toggleClass}}
|
|
|
|
// data-event-name="{{analyticsEventName}}">
|
|
|
|
'label' => $this->messageLocalizer->msg( 'minerva-page-actions-overflow' ),
|
|
|
|
],
|
2019-10-23 18:30:55 +00:00
|
|
|
'listID' => $overflowMenu->getId(),
|
2019-06-20 19:17:50 +00:00
|
|
|
'listClass' => 'page-actions-overflow-list toggle-list__list--drop-down',
|
|
|
|
'items' => $overflowMenu->getEntries()
|
2019-05-23 22:34:10 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
return $menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|