2021-09-09 22:13:48 +00:00
|
|
|
<?php
|
2022-02-19 00:53:42 +00:00
|
|
|
|
2022-05-23 07:32:40 +00:00
|
|
|
namespace MediaWiki\Skins\Vector;
|
2022-02-19 00:53:42 +00:00
|
|
|
|
2023-01-07 00:51:14 +00:00
|
|
|
use ExtensionRegistry;
|
2024-06-14 10:29:40 +00:00
|
|
|
use MediaWiki\Languages\LanguageConverterFactory;
|
2022-10-27 16:09:12 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-04-12 03:27:34 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentAppearance;
|
2023-01-30 14:55:10 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentButton;
|
2022-12-07 01:05:22 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentDropdown;
|
2022-12-16 18:03:07 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentLanguageDropdown;
|
2022-10-27 23:52:23 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentMainMenu;
|
2022-12-02 18:09:52 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentPageTools;
|
2023-01-06 01:21:22 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentPinnableContainer;
|
2022-10-27 16:11:32 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentSearchBox;
|
2022-12-07 00:42:31 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentStickyHeader;
|
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentTableOfContents;
|
2023-01-06 01:45:38 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentUserLinks;
|
2023-06-30 21:49:17 +00:00
|
|
|
use MediaWiki\Skins\Vector\Components\VectorComponentVariants;
|
2024-03-05 20:21:10 +00:00
|
|
|
use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager;
|
|
|
|
use MediaWiki\Skins\Vector\FeatureManagement\FeatureManagerFactory;
|
2023-01-07 00:51:14 +00:00
|
|
|
use RuntimeException;
|
|
|
|
use SkinMustache;
|
|
|
|
use SkinTemplate;
|
2022-10-27 16:09:12 +00:00
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
/**
|
|
|
|
* @ingroup Skins
|
|
|
|
* @package Vector
|
|
|
|
* @internal
|
|
|
|
*/
|
2023-01-07 00:51:14 +00:00
|
|
|
class SkinVector22 extends SkinMustache {
|
2022-07-11 15:10:26 +00:00
|
|
|
private const STICKY_HEADER_ENABLED_CLASS = 'vector-sticky-header-enabled';
|
2023-01-07 00:51:14 +00:00
|
|
|
/** @var null|array for caching purposes */
|
|
|
|
private $languages;
|
|
|
|
|
2024-06-14 10:29:40 +00:00
|
|
|
private LanguageConverterFactory $languageConverterFactory;
|
2024-03-05 20:21:10 +00:00
|
|
|
private FeatureManagerFactory $featureManagerFactory;
|
|
|
|
private ?FeatureManager $featureManager = null;
|
|
|
|
|
|
|
|
public function __construct(
|
2024-06-14 10:29:40 +00:00
|
|
|
LanguageConverterFactory $languageConverterFactory,
|
2024-03-05 20:21:10 +00:00
|
|
|
FeatureManagerFactory $featureManagerFactory,
|
|
|
|
array $options
|
|
|
|
) {
|
|
|
|
parent::__construct( $options );
|
2024-06-14 10:29:40 +00:00
|
|
|
$this->languageConverterFactory = $languageConverterFactory;
|
2024-03-05 20:21:10 +00:00
|
|
|
// Cannot use the context in the constructor, setContext is called after construction
|
|
|
|
$this->featureManagerFactory = $featureManagerFactory;
|
|
|
|
}
|
|
|
|
|
2023-01-07 00:51:14 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
protected function runOnSkinTemplateNavigationHooks( SkinTemplate $skin, &$content_navigation ) {
|
|
|
|
parent::runOnSkinTemplateNavigationHooks( $skin, $content_navigation );
|
|
|
|
Hooks::onSkinTemplateNavigation( $skin, $content_navigation );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function isResponsive() {
|
|
|
|
// Check it's enabled by user preference and configuration
|
|
|
|
$responsive = parent::isResponsive() && $this->getConfig()->get( 'VectorResponsive' );
|
|
|
|
// For historic reasons, the viewport is added when Vector is loaded on the mobile
|
|
|
|
// domain. This is only possible for 3rd parties or by useskin parameter as there is
|
|
|
|
// no preference for changing mobile skin. Only need to check if $responsive is falsey.
|
|
|
|
if ( !$responsive && ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) {
|
|
|
|
$mobFrontContext = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' );
|
|
|
|
if ( $mobFrontContext->shouldDisplayMobileView() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $responsive;
|
|
|
|
}
|
|
|
|
|
2023-09-28 19:41:34 +00:00
|
|
|
/**
|
|
|
|
* Whether or not toc data is available
|
|
|
|
*
|
2023-11-22 13:08:29 +00:00
|
|
|
* @param array $parentData Template data
|
2023-09-28 19:41:34 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2023-11-22 13:08:29 +00:00
|
|
|
private function isTocAvailable( array $parentData ): bool {
|
2023-10-22 14:50:22 +00:00
|
|
|
return !empty( $parentData['data-toc'][ 'array-sections' ] );
|
2023-09-28 19:41:34 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 00:51:14 +00:00
|
|
|
/**
|
|
|
|
* This should be upstreamed to the Skin class in core once the logic is finalized.
|
|
|
|
* Returns false if the page is a special page without any languages, or if an action
|
|
|
|
* other than view is being used.
|
2023-02-23 11:21:59 +00:00
|
|
|
*
|
2023-01-07 00:51:14 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function canHaveLanguages(): bool {
|
2024-01-11 21:57:41 +00:00
|
|
|
$action = $this->getActionName();
|
2023-02-07 18:57:30 +00:00
|
|
|
|
|
|
|
// FIXME: This logic should be moved into the ULS extension or core given the button is hidden,
|
|
|
|
// it should not be rendered, short term fix for T328996.
|
|
|
|
if ( $action === 'history' ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-01-07 00:51:14 +00:00
|
|
|
$title = $this->getTitle();
|
|
|
|
// Defensive programming - if a special page has added languages explicitly, best to show it.
|
2024-01-11 21:57:41 +00:00
|
|
|
if ( $title && $title->isSpecialPage() && $this->getLanguagesCached() === [] ) {
|
2023-01-07 00:51:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-30 14:55:10 +00:00
|
|
|
/**
|
|
|
|
* Remove the add topic button from data-views if present
|
|
|
|
*
|
|
|
|
* @param array &$parentData Template data
|
|
|
|
* @return bool An add topic button was removed
|
|
|
|
*/
|
|
|
|
private function removeAddTopicButton( array &$parentData ): bool {
|
|
|
|
$views = $parentData['data-portlets']['data-views']['array-items'];
|
|
|
|
$hasAddTopicButton = false;
|
|
|
|
$html = '';
|
|
|
|
foreach ( $views as $i => $view ) {
|
|
|
|
if ( $view['id'] === 'ca-addsection' ) {
|
2024-01-11 21:57:41 +00:00
|
|
|
array_splice( $views, $i, 1 );
|
|
|
|
$hasAddTopicButton = true;
|
|
|
|
continue;
|
2023-01-30 14:55:10 +00:00
|
|
|
}
|
|
|
|
$html .= $view['html-item'];
|
|
|
|
}
|
|
|
|
$parentData['data-portlets']['data-views']['array-items'] = $views;
|
|
|
|
$parentData['data-portlets']['data-views']['html-items'] = $html;
|
|
|
|
return $hasAddTopicButton;
|
|
|
|
}
|
|
|
|
|
2024-03-05 20:21:10 +00:00
|
|
|
private function getFeatureManager(): FeatureManager {
|
|
|
|
if ( $this->featureManager === null ) {
|
|
|
|
$this->featureManager = $this->featureManagerFactory->createFeatureManager( $this->getContext() );
|
|
|
|
}
|
|
|
|
return $this->featureManager;
|
|
|
|
}
|
|
|
|
|
2023-01-07 00:51:14 +00:00
|
|
|
/**
|
|
|
|
* @param string $location Either 'top' or 'bottom' is accepted.
|
|
|
|
* @return bool
|
|
|
|
*/
|
2023-02-23 11:21:59 +00:00
|
|
|
protected function isLanguagesInContentAt( string $location ): bool {
|
2023-01-07 00:51:14 +00:00
|
|
|
if ( !$this->canHaveLanguages() ) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-03-05 20:21:10 +00:00
|
|
|
$featureManager = $this->getFeatureManager();
|
2023-01-07 00:51:14 +00:00
|
|
|
$inContent = $featureManager->isFeatureEnabled(
|
|
|
|
Constants::FEATURE_LANGUAGE_IN_HEADER
|
|
|
|
);
|
2024-01-11 21:57:41 +00:00
|
|
|
$title = $this->getTitle();
|
|
|
|
$isMainPage = $title ? $title->isMainPage() : false;
|
2023-01-07 00:51:14 +00:00
|
|
|
|
|
|
|
switch ( $location ) {
|
|
|
|
case 'top':
|
|
|
|
return $isMainPage ? $inContent && $featureManager->isFeatureEnabled(
|
|
|
|
Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER
|
|
|
|
) : $inContent;
|
|
|
|
case 'bottom':
|
|
|
|
return $inContent && $isMainPage && !$featureManager->isFeatureEnabled(
|
|
|
|
Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
throw new RuntimeException( 'unknown language button location' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the languages are out of the sidebar and in the content either at
|
|
|
|
* the top or the bottom.
|
2023-02-23 11:21:59 +00:00
|
|
|
*
|
2023-01-07 00:51:14 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2023-02-23 11:21:59 +00:00
|
|
|
final protected function isLanguagesInContent(): bool {
|
2023-01-07 00:51:14 +00:00
|
|
|
return $this->isLanguagesInContentAt( 'top' ) || $this->isLanguagesInContentAt( 'bottom' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls getLanguages with caching.
|
2023-02-23 11:21:59 +00:00
|
|
|
*
|
2023-01-07 00:51:14 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getLanguagesCached(): array {
|
|
|
|
if ( $this->languages === null ) {
|
|
|
|
$this->languages = $this->getLanguages();
|
|
|
|
}
|
|
|
|
return $this->languages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether ULS is enabled
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
final protected function isULSExtensionEnabled(): bool {
|
|
|
|
return ExtensionRegistry::getInstance()->isLoaded( 'UniversalLanguageSelector' );
|
|
|
|
}
|
2022-03-17 23:02:39 +00:00
|
|
|
|
2023-10-12 14:30:24 +00:00
|
|
|
/**
|
|
|
|
* Check whether Visual Editor Tab Position is first
|
|
|
|
*
|
|
|
|
* @param array $dataViews
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
final protected function isVisualEditorTabPositionFirst( $dataViews ): bool {
|
|
|
|
$names = [ 've-edit', 'edit' ];
|
|
|
|
// find if under key 'name' 've-edit' or 'edit' is the before item in the array
|
|
|
|
for ( $i = 0; $i < count( $dataViews[ 'array-items' ] ); $i++ ) {
|
|
|
|
if ( in_array( $dataViews[ 'array-items' ][ $i ][ 'name' ], $names ) ) {
|
|
|
|
return $dataViews[ 'array-items' ][ $i ][ 'name' ] === $names[ 0 ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-27 21:18:53 +00:00
|
|
|
/**
|
|
|
|
* Show the ULS button if it's modern Vector, languages in header is enabled,
|
2023-03-21 13:27:27 +00:00
|
|
|
* the ULS extension is enabled, and we are on a subect page. Hide it otherwise.
|
2022-10-27 21:18:53 +00:00
|
|
|
* There is no point in showing the language button if ULS extension is unavailable
|
|
|
|
* as there is no ways to add languages without it.
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function shouldHideLanguages(): bool {
|
2023-03-21 13:27:27 +00:00
|
|
|
$title = $this->getTitle();
|
|
|
|
$isSubjectPage = $title && $title->exists() && !$title->isTalkPage();
|
|
|
|
return !$this->isLanguagesInContent() || !$this->isULSExtensionEnabled() || !$isSubjectPage;
|
2022-10-27 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
2022-04-27 19:32:19 +00:00
|
|
|
/**
|
|
|
|
* Merges the `view-overflow` menu into the `action` menu.
|
|
|
|
* This ensures that the previous state of the menu e.g. emptyPortlet class
|
|
|
|
* is preserved.
|
2023-02-23 11:21:59 +00:00
|
|
|
*
|
2022-04-27 19:32:19 +00:00
|
|
|
* @param array $data
|
|
|
|
* @return array
|
|
|
|
*/
|
2023-02-23 11:21:59 +00:00
|
|
|
private function mergeViewOverflowIntoActions( array $data ): array {
|
2022-04-27 19:32:19 +00:00
|
|
|
$portlets = $data['data-portlets'];
|
|
|
|
$actions = $portlets['data-actions'];
|
|
|
|
$overflow = $portlets['data-views-overflow'];
|
2022-04-29 18:16:08 +00:00
|
|
|
// if the views overflow menu is not empty, then signal that the more menu despite
|
|
|
|
// being initially empty now has collapsible items.
|
|
|
|
if ( !$overflow['is-empty'] ) {
|
|
|
|
$data['data-portlets']['data-actions']['class'] .= ' vector-has-collapsible-items';
|
|
|
|
}
|
2022-04-27 19:32:19 +00:00
|
|
|
$data['data-portlets']['data-actions']['html-items'] = $overflow['html-items'] . $actions['html-items'];
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-07-11 15:10:26 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getHtmlElementAttributes() {
|
|
|
|
$original = parent::getHtmlElementAttributes();
|
2024-03-05 20:21:10 +00:00
|
|
|
$featureManager = $this->getFeatureManager();
|
2022-10-21 18:37:26 +00:00
|
|
|
$original['class'] .= ' ' . implode( ' ', $featureManager->getFeatureBodyClass() );
|
2022-07-11 15:10:26 +00:00
|
|
|
|
2024-01-11 21:57:41 +00:00
|
|
|
if ( $featureManager->isFeatureEnabled( Constants::FEATURE_STICKY_HEADER ) ) {
|
2022-07-11 15:10:26 +00:00
|
|
|
// T290518: Add scroll padding to root element when the sticky header is
|
|
|
|
// enabled. This class needs to be server rendered instead of added from
|
|
|
|
// JS in order to correctly handle situations where the sticky header
|
|
|
|
// isn't visible yet but we still need scroll padding applied (e.g. when
|
|
|
|
// the user navigates to a page with a hash fragment in the URI). For this
|
|
|
|
// reason, we can't rely on the `vector-sticky-header-visible` class as it
|
|
|
|
// is added too late.
|
|
|
|
//
|
|
|
|
// Please note that this class applies scroll padding which does not work
|
|
|
|
// when applied to the body tag in Chrome, Safari, and Firefox (and
|
|
|
|
// possibly others). It must instead be applied to the html tag.
|
|
|
|
$original['class'] = implode( ' ', [ $original['class'] ?? '', self::STICKY_HEADER_ENABLED_CLASS ] );
|
|
|
|
}
|
2022-10-21 18:37:26 +00:00
|
|
|
$original['class'] = trim( $original['class'] );
|
2022-07-11 15:10:26 +00:00
|
|
|
|
|
|
|
return $original;
|
|
|
|
}
|
|
|
|
|
2023-01-05 20:02:40 +00:00
|
|
|
/**
|
|
|
|
* Pulls the page tools menu out of $sidebar into $pageToolsMenu
|
|
|
|
*
|
|
|
|
* @param array &$sidebar
|
|
|
|
* @param array &$pageToolsMenu
|
|
|
|
*/
|
2023-02-23 11:21:59 +00:00
|
|
|
private static function extractPageToolsFromSidebar( array &$sidebar, array &$pageToolsMenu ) {
|
2023-01-05 20:02:40 +00:00
|
|
|
$restPortlets = $sidebar[ 'array-portlets-rest' ] ?? [];
|
|
|
|
$toolboxMenuIndex = array_search(
|
|
|
|
VectorComponentPageTools::TOOLBOX_ID,
|
|
|
|
array_column(
|
|
|
|
$restPortlets,
|
|
|
|
'id'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( $toolboxMenuIndex !== false ) {
|
|
|
|
// Splice removes the toolbox menu from the $restPortlets array
|
|
|
|
// and current returns the first value of array_splice, i.e. the $toolbox menu data.
|
|
|
|
$pageToolsMenu = array_splice( $restPortlets, $toolboxMenuIndex );
|
|
|
|
$sidebar['array-portlets-rest'] = $restPortlets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-07 00:51:14 +00:00
|
|
|
/**
|
|
|
|
* Get the ULS button label, accounting for the number of available
|
|
|
|
* languages.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
final protected function getULSLabels(): array {
|
|
|
|
$numLanguages = count( $this->getLanguagesCached() );
|
|
|
|
|
|
|
|
if ( $numLanguages === 0 ) {
|
|
|
|
return [
|
|
|
|
'label' => $this->msg( 'vector-no-language-button-label' )->text(),
|
|
|
|
'aria-label' => $this->msg( 'vector-no-language-button-aria-label' )->text()
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
return [
|
2023-06-06 17:14:15 +00:00
|
|
|
'label' => $this->msg( 'vector-language-button-label' )->numParams( $numLanguages )->text(),
|
|
|
|
'aria-label' => $this->msg( 'vector-language-button-aria-label' )->numParams( $numLanguages )->text()
|
2023-01-07 00:51:14 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-19 00:53:42 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
2022-04-01 15:53:03 +00:00
|
|
|
$parentData = parent::getTemplateData();
|
2022-04-27 19:32:19 +00:00
|
|
|
$parentData = $this->mergeViewOverflowIntoActions( $parentData );
|
2023-01-06 01:45:38 +00:00
|
|
|
$portlets = $parentData['data-portlets'];
|
2022-04-27 19:32:19 +00:00
|
|
|
|
2023-06-30 21:49:17 +00:00
|
|
|
$langData = $portlets['data-languages'] ?? null;
|
2022-12-13 20:28:22 +00:00
|
|
|
$config = $this->getConfig();
|
2024-03-05 20:21:10 +00:00
|
|
|
$featureManager = $this->getFeatureManager();
|
2022-12-13 20:28:22 +00:00
|
|
|
|
2022-12-02 18:09:52 +00:00
|
|
|
$sidebar = $parentData[ 'data-portlets-sidebar' ];
|
2023-01-05 20:02:40 +00:00
|
|
|
$pageToolsMenu = [];
|
2023-03-27 20:29:34 +00:00
|
|
|
self::extractPageToolsFromSidebar( $sidebar, $pageToolsMenu );
|
2022-12-13 20:28:22 +00:00
|
|
|
|
2023-02-24 13:48:29 +00:00
|
|
|
$hasAddTopicButton = $config->get( 'VectorPromoteAddTopic' ) &&
|
|
|
|
$this->removeAddTopicButton( $parentData );
|
2023-01-30 14:55:10 +00:00
|
|
|
|
2022-12-16 18:03:07 +00:00
|
|
|
$langButtonClass = $langData['class'] ?? '';
|
|
|
|
$ulsLabels = $this->getULSLabels();
|
2023-01-06 01:45:38 +00:00
|
|
|
$user = $this->getUser();
|
2023-01-07 00:51:14 +00:00
|
|
|
$localizer = $this->getContext();
|
2024-01-11 21:57:41 +00:00
|
|
|
$title = $this->getTitle();
|
2023-01-12 21:40:14 +00:00
|
|
|
|
2023-01-12 21:44:54 +00:00
|
|
|
// If the table of contents has no items, we won't output it.
|
|
|
|
// empty array is interpreted by Mustache as falsey.
|
2023-09-28 19:41:34 +00:00
|
|
|
$tocComponents = [];
|
2023-11-22 13:08:29 +00:00
|
|
|
if ( $this->isTocAvailable( $parentData ) ) {
|
2023-07-05 12:47:27 +00:00
|
|
|
// @phan-suppress-next-line SecurityCheck-XSS
|
2023-01-12 21:40:14 +00:00
|
|
|
$dataToc = new VectorComponentTableOfContents(
|
|
|
|
$parentData['data-toc'],
|
|
|
|
$localizer,
|
2024-01-11 21:57:41 +00:00
|
|
|
$config,
|
|
|
|
$featureManager
|
2023-01-12 21:40:14 +00:00
|
|
|
);
|
2024-01-11 21:57:41 +00:00
|
|
|
$isPinned = $dataToc->isPinned();
|
2023-01-12 21:40:14 +00:00
|
|
|
$tocComponents = [
|
|
|
|
'data-toc' => $dataToc,
|
|
|
|
'data-toc-pinnable-container' => new VectorComponentPinnableContainer(
|
|
|
|
VectorComponentTableOfContents::ID,
|
2024-01-11 21:57:41 +00:00
|
|
|
$isPinned
|
2023-01-12 21:40:14 +00:00
|
|
|
),
|
|
|
|
'data-page-titlebar-toc-dropdown' => new VectorComponentDropdown(
|
|
|
|
'vector-page-titlebar-toc',
|
2023-02-15 20:23:01 +00:00
|
|
|
// label
|
|
|
|
$this->msg( 'vector-toc-collapsible-button-label' ),
|
2023-01-12 21:40:14 +00:00
|
|
|
// class
|
2023-04-27 20:39:40 +00:00
|
|
|
'vector-page-titlebar-toc vector-button-flush-left',
|
2023-01-12 21:40:14 +00:00
|
|
|
// icon
|
|
|
|
'listBullet',
|
|
|
|
),
|
|
|
|
'data-page-titlebar-toc-pinnable-container' => new VectorComponentPinnableContainer(
|
|
|
|
'vector-page-titlebar-toc',
|
2024-01-11 21:57:41 +00:00
|
|
|
$isPinned
|
2023-01-12 21:40:14 +00:00
|
|
|
),
|
|
|
|
'data-sticky-header-toc-dropdown' => new VectorComponentDropdown(
|
|
|
|
'vector-sticky-header-toc',
|
2023-02-15 20:23:01 +00:00
|
|
|
// label
|
|
|
|
$this->msg( 'vector-toc-collapsible-button-label' ),
|
|
|
|
// class
|
2023-04-27 20:39:40 +00:00
|
|
|
'mw-portlet mw-portlet-sticky-header-toc vector-sticky-header-toc vector-button-flush-left',
|
2023-02-15 20:23:01 +00:00
|
|
|
// icon
|
2023-01-12 21:40:14 +00:00
|
|
|
'listBullet'
|
|
|
|
),
|
|
|
|
'data-sticky-header-toc-pinnable-container' => new VectorComponentPinnableContainer(
|
|
|
|
'vector-sticky-header-toc',
|
2024-01-11 21:57:41 +00:00
|
|
|
$isPinned
|
2023-01-12 21:40:14 +00:00
|
|
|
),
|
|
|
|
];
|
2023-09-28 19:41:34 +00:00
|
|
|
$this->getOutput()->addHtmlClasses( 'vector-toc-available' );
|
|
|
|
} else {
|
|
|
|
$this->getOutput()->addHtmlClasses( 'vector-toc-not-available' );
|
2023-01-12 21:40:14 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 00:35:07 +00:00
|
|
|
$isRegistered = $user->isRegistered();
|
|
|
|
$userPage = $isRegistered ? $this->buildPersonalPageItem() : [];
|
2024-04-12 03:27:34 +00:00
|
|
|
$isAppearanceEnabled = $featureManager->isFeatureEnabled(
|
|
|
|
Constants::FEATURE_APPEARANCE,
|
2023-11-16 00:42:11 +00:00
|
|
|
);
|
2023-11-21 17:01:04 +00:00
|
|
|
|
2023-01-12 21:40:14 +00:00
|
|
|
$components = $tocComponents + [
|
2023-01-30 14:55:10 +00:00
|
|
|
'data-add-topic-button' => $hasAddTopicButton ? new VectorComponentButton(
|
|
|
|
$this->msg( [ 'vector-2022-action-addsection', 'skin-action-addsection' ] )->text(),
|
2023-04-24 21:36:45 +00:00
|
|
|
'speechBubbleAdd-progressive',
|
2023-01-30 14:55:10 +00:00
|
|
|
'ca-addsection',
|
2023-04-24 21:36:45 +00:00
|
|
|
'',
|
|
|
|
[ 'data-event-name' => 'addsection-header' ],
|
|
|
|
'quiet',
|
|
|
|
'progressive',
|
|
|
|
false,
|
2024-01-11 21:57:41 +00:00
|
|
|
$title->getLocalURL( [ 'action' => 'edit', 'section' => 'new' ] )
|
2023-01-30 14:55:10 +00:00
|
|
|
) : null,
|
2023-06-30 21:49:17 +00:00
|
|
|
'data-variants' => new VectorComponentVariants(
|
2024-06-14 10:29:40 +00:00
|
|
|
$this->languageConverterFactory,
|
2023-06-30 21:49:17 +00:00
|
|
|
$portlets['data-variants'],
|
2024-01-11 21:57:41 +00:00
|
|
|
$title->getPageLanguage(),
|
2023-01-07 01:08:39 +00:00
|
|
|
$this->msg( 'vector-language-variant-switcher-label' )
|
|
|
|
),
|
2023-01-06 01:45:38 +00:00
|
|
|
'data-vector-user-links' => new VectorComponentUserLinks(
|
2023-01-07 00:51:14 +00:00
|
|
|
$localizer,
|
2023-01-06 01:45:38 +00:00
|
|
|
$user,
|
2023-02-01 23:38:44 +00:00
|
|
|
$portlets,
|
2023-02-03 00:35:07 +00:00
|
|
|
$this->getOptions()['link'],
|
2023-11-21 17:01:04 +00:00
|
|
|
$userPage[ 'icon' ] ?? ''
|
2023-01-06 01:45:38 +00:00
|
|
|
),
|
2023-04-25 16:53:19 +00:00
|
|
|
'data-lang-dropdown' => $langData ? new VectorComponentLanguageDropdown(
|
2022-12-16 18:03:07 +00:00
|
|
|
$ulsLabels['label'],
|
|
|
|
$ulsLabels['aria-label'],
|
2023-03-06 18:29:26 +00:00
|
|
|
$langButtonClass,
|
2022-12-16 18:03:07 +00:00
|
|
|
count( $this->getLanguagesCached() ),
|
|
|
|
$langData['html-items'] ?? '',
|
|
|
|
$langData['html-before-portal'] ?? '',
|
2022-12-19 15:57:48 +00:00
|
|
|
$langData['html-after-portal'] ?? '',
|
2024-01-11 21:57:41 +00:00
|
|
|
$title
|
2022-12-16 18:03:07 +00:00
|
|
|
) : null,
|
2023-01-05 20:02:40 +00:00
|
|
|
'data-search-box' => new VectorComponentSearchBox(
|
|
|
|
$parentData['data-search-box'],
|
|
|
|
true,
|
|
|
|
// is primary mode of search
|
|
|
|
true,
|
|
|
|
'searchform',
|
|
|
|
true,
|
|
|
|
$config,
|
|
|
|
Constants::SEARCH_BOX_INPUT_LOCATION_MOVED,
|
2023-01-07 00:51:14 +00:00
|
|
|
$localizer
|
2023-01-05 20:02:40 +00:00
|
|
|
),
|
|
|
|
'data-main-menu' => new VectorComponentMainMenu(
|
|
|
|
$sidebar,
|
2023-06-30 21:49:17 +00:00
|
|
|
$portlets['data-languages'] ?? [],
|
2023-01-07 00:51:14 +00:00
|
|
|
$localizer,
|
2024-01-11 21:57:41 +00:00
|
|
|
$user,
|
|
|
|
$featureManager,
|
2023-01-05 20:02:40 +00:00
|
|
|
$this,
|
|
|
|
),
|
|
|
|
'data-main-menu-dropdown' => new VectorComponentDropdown(
|
|
|
|
VectorComponentMainMenu::ID . '-dropdown',
|
|
|
|
$this->msg( VectorComponentMainMenu::ID . '-label' )->text(),
|
2023-04-27 20:39:40 +00:00
|
|
|
VectorComponentMainMenu::ID . '-dropdown' . ' vector-button-flush-left vector-button-flush-right',
|
2023-01-05 20:02:40 +00:00
|
|
|
'menu'
|
|
|
|
),
|
2023-03-27 20:29:34 +00:00
|
|
|
'data-page-tools' => new VectorComponentPageTools(
|
2023-06-30 21:49:17 +00:00
|
|
|
array_merge( [ $portlets['data-actions'] ?? [] ], $pageToolsMenu ),
|
2023-01-07 00:51:14 +00:00
|
|
|
$localizer,
|
2023-01-05 20:02:40 +00:00
|
|
|
$featureManager
|
2023-03-27 20:29:34 +00:00
|
|
|
),
|
|
|
|
'data-page-tools-dropdown' => new VectorComponentDropdown(
|
2023-01-05 20:02:40 +00:00
|
|
|
VectorComponentPageTools::ID . '-dropdown',
|
|
|
|
$this->msg( 'toolbox' )->text(),
|
|
|
|
VectorComponentPageTools::ID . '-dropdown',
|
2023-03-27 20:29:34 +00:00
|
|
|
),
|
2024-04-12 03:27:34 +00:00
|
|
|
'data-appearance' => $isAppearanceEnabled ?
|
|
|
|
new VectorComponentAppearance( $localizer, $featureManager ) : null,
|
|
|
|
'data-appearance-dropdown' => $isAppearanceEnabled ? new VectorComponentDropdown(
|
|
|
|
'vector-appearance-dropdown',
|
|
|
|
$this->msg( 'vector-appearance-label' )->text(),
|
2023-11-21 17:01:04 +00:00
|
|
|
'',
|
|
|
|
// @todo: Use new theme icon (T351142)
|
2023-11-23 10:19:44 +00:00
|
|
|
'appearance'
|
2023-11-21 17:01:04 +00:00
|
|
|
) : null,
|
2023-01-07 00:51:14 +00:00
|
|
|
'data-vector-sticky-header' => $featureManager->isFeatureEnabled(
|
|
|
|
Constants::FEATURE_STICKY_HEADER
|
|
|
|
) ? new VectorComponentStickyHeader(
|
|
|
|
$localizer,
|
|
|
|
new VectorComponentSearchBox(
|
|
|
|
$parentData['data-search-box'],
|
|
|
|
// Collapse inside search box is disabled.
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
'vector-sticky-search-form',
|
|
|
|
false,
|
|
|
|
$config,
|
|
|
|
Constants::SEARCH_BOX_INPUT_LOCATION_MOVED,
|
|
|
|
$localizer
|
|
|
|
),
|
|
|
|
// Show sticky ULS if the ULS extension is enabled and the ULS in header is not hidden
|
|
|
|
$this->isULSExtensionEnabled() && !$this->shouldHideLanguages() ?
|
2023-04-25 16:53:19 +00:00
|
|
|
new VectorComponentButton(
|
|
|
|
$ulsLabels[ 'label' ],
|
|
|
|
'wikimedia-language',
|
|
|
|
'p-lang-btn-sticky-header',
|
|
|
|
'mw-interlanguage-selector',
|
|
|
|
[
|
|
|
|
'tabindex' => '-1',
|
|
|
|
'data-event-name' => 'ui.dropdown-p-lang-btn-sticky-header'
|
|
|
|
],
|
|
|
|
'quiet',
|
|
|
|
) : null,
|
2023-10-12 14:30:24 +00:00
|
|
|
$this->isVisualEditorTabPositionFirst( $portlets[ 'data-views' ] )
|
2023-04-25 16:53:19 +00:00
|
|
|
) : null,
|
2023-09-14 15:36:54 +00:00
|
|
|
'data-vector-settings-button' => $featureManager->isFeatureEnabled(
|
2024-04-12 03:27:34 +00:00
|
|
|
Constants::FEATURE_APPEARANCE,
|
2023-09-14 15:36:54 +00:00
|
|
|
) ? null : new VectorComponentButton(
|
2023-04-25 16:53:19 +00:00
|
|
|
$this->msg( 'vector-limited-width-toggle' ),
|
2023-05-02 18:31:34 +00:00
|
|
|
$featureManager->isFeatureEnabled(
|
|
|
|
Constants::FEATURE_LIMITED_WIDTH
|
|
|
|
) ? 'fullScreen' : 'exitFullscreen',
|
2024-05-28 16:03:52 +00:00
|
|
|
null,
|
2023-05-02 18:31:34 +00:00
|
|
|
'vector-limited-width-toggle',
|
2023-04-25 16:53:19 +00:00
|
|
|
[],
|
|
|
|
'normal',
|
|
|
|
'default',
|
|
|
|
true
|
|
|
|
)
|
2022-10-27 19:36:08 +00:00
|
|
|
];
|
2023-11-21 17:01:04 +00:00
|
|
|
|
2022-10-27 19:36:08 +00:00
|
|
|
foreach ( $components as $key => $component ) {
|
|
|
|
// Array of components or null values.
|
|
|
|
if ( $component ) {
|
|
|
|
$parentData[$key] = $component->getTemplateData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 20:13:58 +00:00
|
|
|
return array_merge( $parentData, [
|
2022-10-27 21:18:53 +00:00
|
|
|
'is-language-in-content' => $this->isLanguagesInContent(),
|
2023-01-30 14:55:10 +00:00
|
|
|
'has-buttons-in-content-top' => $this->isLanguagesInContentAt( 'top' ) || $hasAddTopicButton,
|
2022-10-27 21:18:53 +00:00
|
|
|
'is-language-in-content-bottom' => $this->isLanguagesInContentAt( 'bottom' ),
|
2022-07-25 20:13:58 +00:00
|
|
|
// Cast empty string to null
|
2023-04-12 20:36:55 +00:00
|
|
|
'html-subtitle' => $parentData['html-subtitle'] === '' ? null : $parentData['html-subtitle'],
|
2022-07-25 20:13:58 +00:00
|
|
|
] );
|
2022-02-19 00:53:42 +00:00
|
|
|
}
|
2021-09-09 22:13:48 +00:00
|
|
|
}
|