mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-27 17:10:19 +00:00
SkinVector22: Minor cleanup
- Remove unused override of getDefaultModules - Call getActionName() directly - Remove some use of empty() - Fix line indent - Call some functions only once - Write query parameter as array - Have all parent:: at function top Change-Id: I4c807b0a170eef0742586beb87b80eaade4bb4c5
This commit is contained in:
parent
8a0961c815
commit
62cf2e94c0
|
@ -56,22 +56,6 @@ class SkinVector22 extends SkinMustache {
|
|||
return $responsive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide styles required to present the server rendered page in this skin. Additional styles
|
||||
* may be loaded dynamically by the client.
|
||||
*
|
||||
* Any styles returned by this method are loaded on the critical rendering path as linked
|
||||
* stylesheets. I.e., they are required to load on the client before first paint.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaultModules(): array {
|
||||
$modules = parent::getDefaultModules();
|
||||
$featureManager = VectorServices::getFeatureManager();
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not toc data is available
|
||||
*
|
||||
|
@ -90,7 +74,7 @@ class SkinVector22 extends SkinMustache {
|
|||
* @return bool
|
||||
*/
|
||||
private function canHaveLanguages(): bool {
|
||||
$action = $this->getContext()->getActionName();
|
||||
$action = $this->getActionName();
|
||||
|
||||
// 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.
|
||||
|
@ -100,7 +84,7 @@ class SkinVector22 extends SkinMustache {
|
|||
|
||||
$title = $this->getTitle();
|
||||
// Defensive programming - if a special page has added languages explicitly, best to show it.
|
||||
if ( $title && $title->isSpecialPage() && empty( $this->getLanguagesCached() ) ) {
|
||||
if ( $title && $title->isSpecialPage() && $this->getLanguagesCached() === [] ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -118,9 +102,9 @@ class SkinVector22 extends SkinMustache {
|
|||
$html = '';
|
||||
foreach ( $views as $i => $view ) {
|
||||
if ( $view['id'] === 'ca-addsection' ) {
|
||||
array_splice( $views, $i, 1 );
|
||||
$hasAddTopicButton = true;
|
||||
continue;
|
||||
array_splice( $views, $i, 1 );
|
||||
$hasAddTopicButton = true;
|
||||
continue;
|
||||
}
|
||||
$html .= $view['html-item'];
|
||||
}
|
||||
|
@ -141,7 +125,8 @@ class SkinVector22 extends SkinMustache {
|
|||
$inContent = $featureManager->isFeatureEnabled(
|
||||
Constants::FEATURE_LANGUAGE_IN_HEADER
|
||||
);
|
||||
$isMainPage = $this->getTitle() ? $this->getTitle()->isMainPage() : false;
|
||||
$title = $this->getTitle();
|
||||
$isMainPage = $title ? $title->isMainPage() : false;
|
||||
|
||||
switch ( $location ) {
|
||||
case 'top':
|
||||
|
@ -225,8 +210,9 @@ class SkinVector22 extends SkinMustache {
|
|||
*/
|
||||
private function shouldLanguageAlertBeInSidebar(): bool {
|
||||
$featureManager = VectorServices::getFeatureManager();
|
||||
$isMainPage = $this->getTitle() ? $this->getTitle()->isMainPage() : false;
|
||||
$shouldShowOnMainPage = $isMainPage && !empty( $this->getLanguagesCached() ) &&
|
||||
$title = $this->getTitle();
|
||||
$isMainPage = $title ? $title->isMainPage() : false;
|
||||
$shouldShowOnMainPage = $isMainPage && $this->getLanguagesCached() !== [] &&
|
||||
$featureManager->isFeatureEnabled( Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER );
|
||||
return ( $this->isLanguagesInContentAt( 'top' ) && !$isMainPage && !$this->shouldHideLanguages() &&
|
||||
$featureManager->isFeatureEnabled( Constants::FEATURE_LANGUAGE_IN_HEADER ) ) ||
|
||||
|
@ -262,7 +248,7 @@ class SkinVector22 extends SkinMustache {
|
|||
$featureManager = VectorServices::getFeatureManager();
|
||||
$original['class'] .= ' ' . implode( ' ', $featureManager->getFeatureBodyClass() );
|
||||
|
||||
if ( VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_STICKY_HEADER ) ) {
|
||||
if ( $featureManager->isFeatureEnabled( Constants::FEATURE_STICKY_HEADER ) ) {
|
||||
// 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
|
||||
|
@ -331,13 +317,13 @@ class SkinVector22 extends SkinMustache {
|
|||
* @return array
|
||||
*/
|
||||
public function getTemplateData(): array {
|
||||
$featureManager = VectorServices::getFeatureManager();
|
||||
$parentData = parent::getTemplateData();
|
||||
$parentData = $this->mergeViewOverflowIntoActions( $parentData );
|
||||
$portlets = $parentData['data-portlets'];
|
||||
|
||||
$langData = $portlets['data-languages'] ?? null;
|
||||
$config = $this->getConfig();
|
||||
$featureManager = VectorServices::getFeatureManager();
|
||||
|
||||
$sidebar = $parentData[ 'data-portlets-sidebar' ];
|
||||
$pageToolsMenu = [];
|
||||
|
@ -350,6 +336,7 @@ class SkinVector22 extends SkinMustache {
|
|||
$ulsLabels = $this->getULSLabels();
|
||||
$user = $this->getUser();
|
||||
$localizer = $this->getContext();
|
||||
$title = $this->getTitle();
|
||||
|
||||
// If the table of contents has no items, we won't output it.
|
||||
// empty array is interpreted by Mustache as falsey.
|
||||
|
@ -359,14 +346,15 @@ class SkinVector22 extends SkinMustache {
|
|||
$dataToc = new VectorComponentTableOfContents(
|
||||
$parentData['data-toc'],
|
||||
$localizer,
|
||||
$this->getConfig(),
|
||||
VectorServices::getFeatureManager()
|
||||
$config,
|
||||
$featureManager
|
||||
);
|
||||
$isPinned = $dataToc->isPinned();
|
||||
$tocComponents = [
|
||||
'data-toc' => $dataToc,
|
||||
'data-toc-pinnable-container' => new VectorComponentPinnableContainer(
|
||||
VectorComponentTableOfContents::ID,
|
||||
$dataToc->isPinned()
|
||||
$isPinned
|
||||
),
|
||||
'data-page-titlebar-toc-dropdown' => new VectorComponentDropdown(
|
||||
'vector-page-titlebar-toc',
|
||||
|
@ -379,7 +367,7 @@ class SkinVector22 extends SkinMustache {
|
|||
),
|
||||
'data-page-titlebar-toc-pinnable-container' => new VectorComponentPinnableContainer(
|
||||
'vector-page-titlebar-toc',
|
||||
$dataToc->isPinned()
|
||||
$isPinned
|
||||
),
|
||||
'data-sticky-header-toc-dropdown' => new VectorComponentDropdown(
|
||||
'vector-sticky-header-toc',
|
||||
|
@ -392,7 +380,7 @@ class SkinVector22 extends SkinMustache {
|
|||
),
|
||||
'data-sticky-header-toc-pinnable-container' => new VectorComponentPinnableContainer(
|
||||
'vector-sticky-header-toc',
|
||||
$dataToc->isPinned()
|
||||
$isPinned
|
||||
),
|
||||
];
|
||||
$this->getOutput()->addHtmlClasses( 'vector-toc-available' );
|
||||
|
@ -416,11 +404,11 @@ class SkinVector22 extends SkinMustache {
|
|||
'quiet',
|
||||
'progressive',
|
||||
false,
|
||||
$this->getTitle()->getLocalURL( 'action=edit§ion=new' )
|
||||
$title->getLocalURL( [ 'action' => 'edit', 'section' => 'new' ] )
|
||||
) : null,
|
||||
'data-variants' => new VectorComponentVariants(
|
||||
$portlets['data-variants'],
|
||||
$this->getTitle()->getPageLanguage(),
|
||||
$title->getPageLanguage(),
|
||||
$this->msg( 'vector-language-variant-switcher-label' )
|
||||
),
|
||||
'data-vector-user-links' => new VectorComponentUserLinks(
|
||||
|
@ -438,7 +426,7 @@ class SkinVector22 extends SkinMustache {
|
|||
$langData['html-items'] ?? '',
|
||||
$langData['html-before-portal'] ?? '',
|
||||
$langData['html-after-portal'] ?? '',
|
||||
$this->getTitle()
|
||||
$title
|
||||
) : null,
|
||||
'data-search-box' => new VectorComponentSearchBox(
|
||||
$parentData['data-search-box'],
|
||||
|
@ -457,8 +445,8 @@ class SkinVector22 extends SkinMustache {
|
|||
count( $this->getLanguagesCached() ),
|
||||
$portlets['data-languages'] ?? [],
|
||||
$localizer,
|
||||
$this->getUser(),
|
||||
VectorServices::getFeatureManager(),
|
||||
$user,
|
||||
$featureManager,
|
||||
$this,
|
||||
),
|
||||
'data-main-menu-dropdown' => new VectorComponentDropdown(
|
||||
|
|
Loading…
Reference in a new issue