mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 07:43:47 +00:00
Merge "Move table of contents code to SkinVector22"
This commit is contained in:
commit
a47f14658c
|
@ -154,18 +154,6 @@ class SkinVector extends SkinMustache {
|
|||
*/
|
||||
private const OPT_OUT_LINK_TRACKING_CODE = 'vctw1';
|
||||
|
||||
/**
|
||||
* Updates the constructor to conditionally disable table of contents in article
|
||||
* body.
|
||||
* Note, the constructor can only check feature flags that do not vary on whether the
|
||||
* user is logged in e.g. features with the 'default' key set.
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct( array $options ) {
|
||||
$options['toc'] = !$this->isTableOfContentsVisibleInSidebar();
|
||||
parent::__construct( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $icon the name of the icon without wikimedia- prefix.
|
||||
* @return string
|
||||
|
@ -455,12 +443,6 @@ class SkinVector extends SkinMustache {
|
|||
public function generateHTML() {
|
||||
if ( $this->isLegacy() ) {
|
||||
$this->options['template'] = SkinVectorLegacy::getTemplateOption();
|
||||
if ( $this->isTableOfContentsVisibleInSidebar() ) {
|
||||
throw new RuntimeException(
|
||||
'The table of contents flag cannot safely be applied without ' .
|
||||
'breaking legacy Vector. Please fix T291098 before applying.'
|
||||
);
|
||||
}
|
||||
}
|
||||
return parent::generateHTML();
|
||||
}
|
||||
|
@ -565,21 +547,6 @@ class SkinVector extends SkinMustache {
|
|||
$shouldShowOnMainPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@ -642,10 +609,6 @@ class SkinVector extends SkinMustache {
|
|||
'data-toc' => $this->getTocData( $parentData['data-toc'] ?? [] )
|
||||
] );
|
||||
|
||||
if ( !$this->isTableOfContentsVisibleInSidebar() ) {
|
||||
unset( $commonSkinData['data-toc'] );
|
||||
}
|
||||
|
||||
if ( $skin->getUser()->isRegistered() ) {
|
||||
$migrationMode = $this->getConfig()->get( 'VectorSkinMigrationMode' );
|
||||
$query = $migrationMode ? 'useskin=vector&' : '';
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<?php
|
||||
|
||||
use Vector\Constants;
|
||||
use Vector\VectorServices;
|
||||
|
||||
/**
|
||||
* @ingroup Skins
|
||||
* @package Vector
|
||||
|
@ -7,6 +11,7 @@
|
|||
class SkinVector22 extends SkinVector {
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Updates the constructor to conditionally disable table of contents in article body.
|
||||
*/
|
||||
public function __construct( $options = [] ) {
|
||||
$options += [
|
||||
|
@ -14,9 +19,26 @@ class SkinVector22 extends SkinVector {
|
|||
'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.
|
||||
*
|
||||
|
@ -53,4 +75,15 @@ class SkinVector22 extends SkinVector {
|
|||
'mediawiki.ui.icon',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplateData(): array {
|
||||
$data = parent::getTemplateData();
|
||||
if ( !$this->isTableOfContentsVisibleInSidebar() ) {
|
||||
unset( $data['data-toc'] );
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue