mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-17 11:13:34 +00:00
dd5753c023
empty() should only be used to suppress errors When the type of the variable is array, a falsy check is the same (checks for null, false and empty array) Found by a new phan plugin (T234237) Change-Id: If24015795219f6ff4f155c0d667472dc52a04d43
98 lines
2.7 KiB
PHP
98 lines
2.7 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 MediaWiki\Html\TemplateParser;
|
|
use MessageLocalizer;
|
|
|
|
/**
|
|
* Director responsible for building the user menu.
|
|
*/
|
|
final class UserMenuDirector {
|
|
/**
|
|
* @var IUserMenuBuilder
|
|
*/
|
|
private $builder;
|
|
|
|
/**
|
|
* @var MessageLocalizer
|
|
*/
|
|
private $localizer;
|
|
|
|
/**
|
|
* @param IUserMenuBuilder $builder
|
|
* @param MessageLocalizer $localizer
|
|
*/
|
|
public function __construct( IUserMenuBuilder $builder, MessageLocalizer $localizer ) {
|
|
$this->builder = $builder;
|
|
$this->localizer = $localizer;
|
|
}
|
|
|
|
/**
|
|
* Build the menu data array that can be passed to views/javascript
|
|
* @param array $personalTools Personal tools list generated by Skin::buildPersonalUrls
|
|
* @return string|null
|
|
*/
|
|
public function renderMenuData( array $personalTools ) {
|
|
$group = $this->builder->getGroup( $personalTools );
|
|
$entries = $group->getEntries();
|
|
|
|
$templateParser = new TemplateParser( __DIR__ . '/../../Skins' );
|
|
$toggleID = 'minerva-user-menu-toggle';
|
|
$checkboxID = 'minerva-user-menu-checkbox';
|
|
return !$entries
|
|
? null
|
|
: $templateParser->processTemplate( 'ToggleList', [
|
|
'class' => 'minerva-user-menu',
|
|
'checkboxID' => $checkboxID,
|
|
'toggleID' => $toggleID, // See skin.mustache too.
|
|
'data-btn' => [
|
|
'tag-name' => 'label',
|
|
'data-icon' => [
|
|
'icon' => 'userAvatarOutline',
|
|
],
|
|
'classes' => 'toggle-list__toggle',
|
|
'array-attributes' => [
|
|
[
|
|
'key' => 'id',
|
|
'value' => $toggleID,
|
|
],
|
|
[
|
|
'key' => 'for',
|
|
'value' => $checkboxID,
|
|
],
|
|
[
|
|
'key' => 'aria-hidden',
|
|
'value' => 'true'
|
|
],
|
|
[
|
|
'key' => 'data-event-name',
|
|
'value' => 'ui.usermenu',
|
|
],
|
|
],
|
|
'label' => $this->localizer->msg( 'minerva-user-menu-button' )->escaped(),
|
|
],
|
|
'listID' => $group->getId(),
|
|
'listClass' => 'minerva-user-menu-list toggle-list__list--drop-down', // See ToggleList/*.less.
|
|
'items' => $entries
|
|
] );
|
|
}
|
|
}
|