2021-09-09 22:13:48 +00:00
|
|
|
<?php
|
2022-02-19 00:53:42 +00:00
|
|
|
|
2022-02-06 22:43:56 +00:00
|
|
|
namespace Vector;
|
2022-02-19 00:53:42 +00:00
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
/**
|
|
|
|
* @ingroup Skins
|
|
|
|
* @package Vector
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
class SkinVector22 extends SkinVector {
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
2022-02-19 00:53:42 +00:00
|
|
|
* Updates the constructor to conditionally disable table of contents in article body.
|
2021-09-09 22:13:48 +00:00
|
|
|
*/
|
|
|
|
public function __construct( $options = [] ) {
|
|
|
|
$options += [
|
|
|
|
'template' => self::getTemplateOption(),
|
|
|
|
'scripts' => self::getScriptsOption(),
|
|
|
|
'styles' => self::getStylesOption(),
|
|
|
|
];
|
2022-02-19 00:53:42 +00:00
|
|
|
|
|
|
|
$options['toc'] = !$this->isTableOfContentsVisibleInSidebar();
|
2021-09-09 22:13:48 +00:00
|
|
|
parent::__construct( $options );
|
|
|
|
}
|
|
|
|
|
2022-02-19 00:53:42 +00:00
|
|
|
/**
|
|
|
|
* Determines if the Table of Contents should be visible.
|
|
|
|
* TOC is visible on main namespaces except for the Main Page
|
|
|
|
* when the feature flag is on.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isTableOfContentsVisibleInSidebar(): bool {
|
|
|
|
$featureManager = VectorServices::getFeatureManager();
|
|
|
|
$title = $this->getTitle();
|
|
|
|
$isMainNS = $title ? $title->inNamespaces( 0 ) : false;
|
|
|
|
$isMainPage = $title ? $title->isMainPage() : false;
|
|
|
|
return $featureManager->isFeatureEnabled( Constants::FEATURE_TABLE_OF_CONTENTS ) && $isMainNS && !$isMainPage;
|
|
|
|
}
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
/**
|
|
|
|
* Temporary static function while we deprecate SkinVector class.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getTemplateOption() {
|
|
|
|
return 'skin';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Temporary static function while we deprecate SkinVector class.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getScriptsOption() {
|
|
|
|
return [
|
2021-12-14 21:59:16 +00:00
|
|
|
'skins.vector.user',
|
2021-09-09 22:13:48 +00:00
|
|
|
'skins.vector.js',
|
|
|
|
'skins.vector.es6',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Temporary static function while we deprecate SkinVector class.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getStylesOption() {
|
|
|
|
return [
|
|
|
|
'mediawiki.ui.button',
|
|
|
|
'skins.vector.styles',
|
2021-12-14 21:59:16 +00:00
|
|
|
'skins.vector.user.styles',
|
2021-09-09 22:13:48 +00:00
|
|
|
'skins.vector.icons',
|
|
|
|
'mediawiki.ui.icon',
|
|
|
|
];
|
|
|
|
}
|
2022-02-19 00:53:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
|
|
|
$data = parent::getTemplateData();
|
|
|
|
if ( !$this->isTableOfContentsVisibleInSidebar() ) {
|
|
|
|
unset( $data['data-toc'] );
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2021-09-09 22:13:48 +00:00
|
|
|
}
|