mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-17 04:39:29 +00:00
ed4b45f44a
This avoids the RuntimeException in old Vector, and means we can safely enable this on the beta cluster Note, for any users that are in migration mode e.g. skin is set to 'vector' and the skin version is set to 2 they will not see a table of contents in the sidebar or article. This won't be a problem in production provided T299104 is resolved before we enable. Change-Id: I942a1cb933e7364600fe1af7491aca20546545e5
90 lines
2 KiB
PHP
90 lines
2 KiB
PHP
<?php
|
|
|
|
use Vector\Constants;
|
|
use Vector\VectorServices;
|
|
|
|
/**
|
|
* @ingroup Skins
|
|
* @package Vector
|
|
* @internal
|
|
*/
|
|
class SkinVector22 extends SkinVector {
|
|
/**
|
|
* @inheritDoc
|
|
* Updates the constructor to conditionally disable table of contents in article body.
|
|
*/
|
|
public function __construct( $options = [] ) {
|
|
$options += [
|
|
'template' => self::getTemplateOption(),
|
|
'scripts' => self::getScriptsOption(),
|
|
'styles' => self::getStylesOption(),
|
|
];
|
|
|
|
$options['toc'] = !$this->isTableOfContentsVisibleInSidebar();
|
|
parent::__construct( $options );
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* 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 [
|
|
'skins.vector.user',
|
|
'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',
|
|
'skins.vector.user.styles',
|
|
'skins.vector.icons',
|
|
'mediawiki.ui.icon',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getTemplateData(): array {
|
|
$data = parent::getTemplateData();
|
|
if ( !$this->isTableOfContentsVisibleInSidebar() ) {
|
|
unset( $data['data-toc'] );
|
|
}
|
|
return $data;
|
|
}
|
|
}
|