2021-09-09 22:13:48 +00:00
|
|
|
<?php
|
|
|
|
|
2022-05-23 07:32:40 +00:00
|
|
|
namespace MediaWiki\Skins\Vector;
|
2022-02-06 22:43:56 +00:00
|
|
|
|
2022-10-27 16:11:32 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentSearchBox;
|
2023-06-30 21:49:17 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentVariants;
|
2023-01-07 00:51:14 +00:00
|
|
|
use SkinMustache;
|
|
|
|
use SkinTemplate;
|
2022-10-27 16:11:32 +00:00
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
/**
|
|
|
|
* @ingroup Skins
|
|
|
|
* @package Vector
|
|
|
|
* @internal
|
|
|
|
*/
|
2023-01-07 00:51:14 +00:00
|
|
|
class SkinVectorLegacy extends SkinMustache {
|
2022-10-27 23:52:23 +00:00
|
|
|
/** @var int */
|
|
|
|
private const MENU_TYPE_DEFAULT = 0;
|
|
|
|
/** @var int */
|
|
|
|
private const MENU_TYPE_TABS = 1;
|
|
|
|
/** @var int */
|
|
|
|
private const MENU_TYPE_DROPDOWN = 2;
|
|
|
|
private const MENU_TYPE_PORTAL = 3;
|
|
|
|
|
2022-04-01 15:53:03 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2023-01-07 00:51:14 +00:00
|
|
|
protected function runOnSkinTemplateNavigationHooks( SkinTemplate $skin, &$content_navigation ) {
|
|
|
|
parent::runOnSkinTemplateNavigationHooks( $skin, $content_navigation );
|
|
|
|
Hooks::onSkinTemplateNavigation( $skin, $content_navigation );
|
2022-04-01 15:53:03 +00:00
|
|
|
}
|
2022-10-27 16:17:09 +00:00
|
|
|
|
2022-10-27 23:52:23 +00:00
|
|
|
/**
|
|
|
|
* Performs updates to all portlets.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function decoratePortletsData( array $data ) {
|
|
|
|
foreach ( $data['data-portlets'] as $key => $pData ) {
|
|
|
|
$data['data-portlets'][$key] = $this->decoratePortletData(
|
|
|
|
$key,
|
|
|
|
$pData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$mainMenuData = $data['data-portlets-sidebar'];
|
|
|
|
$mainMenuData['data-portlets-first'] = $this->decoratePortletData(
|
|
|
|
'navigation', $mainMenuData['data-portlets-first']
|
|
|
|
);
|
|
|
|
$rest = $mainMenuData['array-portlets-rest'];
|
|
|
|
foreach ( $rest as $key => $pData ) {
|
|
|
|
$rest[$key] = $this->decoratePortletData(
|
|
|
|
$pData['id'], $pData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$mainMenuData['array-portlets-rest'] = $rest;
|
|
|
|
$data['data-portlets-main-menu'] = $mainMenuData;
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs the following updates to portlet data:
|
|
|
|
* - Adds concept of menu types
|
|
|
|
* - Marks the selected variant in the variant portlet
|
|
|
|
* - modifies tooltips of personal and user-menu portlets
|
|
|
|
* @param string $key
|
|
|
|
* @param array $portletData
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function decoratePortletData(
|
|
|
|
string $key,
|
|
|
|
array $portletData
|
|
|
|
): array {
|
|
|
|
$isIconDropdown = false;
|
|
|
|
switch ( $key ) {
|
|
|
|
case 'data-user-menu':
|
|
|
|
$type = self::MENU_TYPE_DROPDOWN;
|
|
|
|
$isIconDropdown = true;
|
|
|
|
break;
|
|
|
|
case 'data-actions':
|
|
|
|
case 'data-variants':
|
|
|
|
case 'data-sticky-header-toc':
|
|
|
|
$type = self::MENU_TYPE_DROPDOWN;
|
|
|
|
break;
|
|
|
|
case 'data-views':
|
|
|
|
case 'data-associated-pages':
|
|
|
|
case 'data-namespaces':
|
|
|
|
$type = self::MENU_TYPE_TABS;
|
|
|
|
break;
|
|
|
|
case 'data-notifications':
|
|
|
|
case 'data-personal':
|
|
|
|
case 'data-user-page':
|
|
|
|
case 'data-vector-user-menu-overflow':
|
|
|
|
$type = self::MENU_TYPE_DEFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$type = self::MENU_TYPE_PORTAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-03 15:13:20 +00:00
|
|
|
if ( $key === 'data-personal' ) {
|
2022-10-27 23:52:23 +00:00
|
|
|
// Set tooltip to empty string for the personal menu for both logged-in and logged-out users
|
|
|
|
// to avoid showing the tooltip for legacy version.
|
|
|
|
$portletData['html-tooltip'] = '';
|
|
|
|
$portletData['class'] .= ' vector-user-menu-legacy';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special casing for Variant to change label to selected.
|
|
|
|
// Hopefully we can revisit and possibly remove this code when the language switcher is moved.
|
|
|
|
if ( $key === 'data-variants' ) {
|
2023-06-30 21:49:17 +00:00
|
|
|
$variant = new VectorComponentVariants(
|
2023-01-07 01:08:39 +00:00
|
|
|
$portletData,
|
|
|
|
$this->getTitle()->getPageLanguage(),
|
|
|
|
$this->msg( 'vector-language-variant-switcher-label' )
|
|
|
|
);
|
2023-06-30 21:49:17 +00:00
|
|
|
$portletData[ 'label' ] = $variant->getTemplateData()[ 'data-variants-dropdown' ][ 'label' ];
|
2022-10-27 23:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$portletData = $this->updatePortletClasses(
|
|
|
|
$portletData,
|
|
|
|
$type
|
|
|
|
);
|
|
|
|
|
|
|
|
return $portletData + [
|
2023-01-10 18:41:49 +00:00
|
|
|
'is-dropdown' => $type === self::MENU_TYPE_DROPDOWN,
|
2022-10-27 23:52:23 +00:00
|
|
|
'is-portal' => $type === self::MENU_TYPE_PORTAL,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for applying Vector menu classes to portlets
|
|
|
|
*
|
|
|
|
* @param array $portletData returned by SkinMustache to decorate
|
|
|
|
* @param int $type representing one of the menu types (see MENU_TYPE_* constants)
|
|
|
|
* @return array modified version of portletData input
|
|
|
|
*/
|
|
|
|
private function updatePortletClasses(
|
|
|
|
array $portletData,
|
|
|
|
int $type = self::MENU_TYPE_DEFAULT
|
|
|
|
) {
|
|
|
|
$extraClasses = [
|
|
|
|
self::MENU_TYPE_DROPDOWN => 'vector-menu-dropdown',
|
2022-11-03 15:13:20 +00:00
|
|
|
self::MENU_TYPE_TABS => 'vector-menu-tabs vector-menu-tabs-legacy',
|
2022-10-27 23:52:23 +00:00
|
|
|
self::MENU_TYPE_PORTAL => 'vector-menu-portal portal',
|
|
|
|
self::MENU_TYPE_DEFAULT => '',
|
|
|
|
];
|
|
|
|
$portletData['class'] .= ' ' . $extraClasses[$type];
|
|
|
|
|
|
|
|
if ( !isset( $portletData['heading-class'] ) ) {
|
|
|
|
$portletData['heading-class'] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$portletData['class'] = trim( $portletData['class'] );
|
|
|
|
$portletData['heading-class'] = trim( $portletData['heading-class'] );
|
|
|
|
return $portletData;
|
|
|
|
}
|
|
|
|
|
2022-10-27 16:17:09 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
2022-10-27 23:52:23 +00:00
|
|
|
$parentData = $this->decoratePortletsData( parent::getTemplateData() );
|
2022-10-27 16:17:09 +00:00
|
|
|
|
2022-10-27 16:11:32 +00:00
|
|
|
$components = [
|
|
|
|
'data-search-box' => new VectorComponentSearchBox(
|
2022-11-03 15:13:20 +00:00
|
|
|
$parentData['data-search-box'],
|
|
|
|
false,
|
|
|
|
// is primary mode of search
|
|
|
|
true,
|
|
|
|
'searchform',
|
|
|
|
true,
|
2022-10-27 16:11:32 +00:00
|
|
|
$this->getConfig(),
|
|
|
|
Constants::SEARCH_BOX_INPUT_LOCATION_DEFAULT,
|
|
|
|
$this->getContext()
|
|
|
|
),
|
|
|
|
];
|
|
|
|
foreach ( $components as $key => $component ) {
|
|
|
|
$parentData[$key] = $component->getTemplateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
// SkinVector sometimes serves new Vector as part of removing the
|
|
|
|
// skin version user preference. To avoid T302461 we need to unset it here.
|
|
|
|
// This shouldn't be run on SkinVector22.
|
|
|
|
unset( $parentData['data-toc'] );
|
|
|
|
return $parentData;
|
2022-10-27 16:17:09 +00:00
|
|
|
}
|
2021-09-09 22:13:48 +00:00
|
|
|
}
|