Add hook to override SkinOptions, and allow overriding tabs output

Bug: T222835
Change-Id: I0d390eadbd0a8de7f328360df5c60d9fb2225db1
This commit is contained in:
Kosta Harlan 2019-05-31 13:14:48 -04:00
parent dc729b0a66
commit 1e87c62191
3 changed files with 30 additions and 4 deletions

View file

@ -234,9 +234,12 @@ class MinervaHooks {
SkinOptions::OPTION_OVERFLOW_SUBMENU => $featureManager->isFeatureAvailableForCurrentUser( SkinOptions::OPTION_OVERFLOW_SUBMENU => $featureManager->isFeatureAvailableForCurrentUser(
self::FEATURE_OVERFLOW_PAGE_ACTIONS self::FEATURE_OVERFLOW_PAGE_ACTIONS
), ),
SkinOptions::OPTION_TABS_ON_SPECIALS => false,
] ); ] );
Hooks::run( 'SkinMinervaOptionsInit', [ $skin, $skinOptions ] );
} }
} }
/** /**
* ResourceLoaderGetConfigVars hook handler. * ResourceLoaderGetConfigVars hook handler.
* Used for setting JS variables which are pulled in dynamically with RL * Used for setting JS variables which are pulled in dynamically with RL

View file

@ -35,6 +35,7 @@ final class SkinOptions {
const OPTIONS_TALK_AT_TOP = 'talkAtTop'; const OPTIONS_TALK_AT_TOP = 'talkAtTop';
const OPTIONS_HISTORY_PAGE_ACTIONS = 'historyInPageActions'; const OPTIONS_HISTORY_PAGE_ACTIONS = 'historyInPageActions';
const OPTION_OVERFLOW_SUBMENU = 'overflowSubmenu'; const OPTION_OVERFLOW_SUBMENU = 'overflowSubmenu';
const OPTION_TABS_ON_SPECIALS = 'tabsOnSpecials';
/** @var array skin specific options */ /** @var array skin specific options */
private $skinOptions = [ private $skinOptions = [

View file

@ -229,9 +229,7 @@ class MinervaTemplate extends BaseTemplate {
$internalBanner = $data[ 'internalBanner' ]; $internalBanner = $data[ 'internalBanner' ];
$preBodyHtml = isset( $data['prebodyhtml'] ) ? $data['prebodyhtml'] : ''; $preBodyHtml = isset( $data['prebodyhtml'] ) ? $data['prebodyhtml'] : '';
$hasHeadingHolder = $internalBanner || $preBodyHtml || isset( $data['page_actions'] ); $hasHeadingHolder = $internalBanner || $preBodyHtml || isset( $data['page_actions'] );
$hasPageActions = !$this->isSpecialPage && !$this->isMainPage && $hasPageActions = $this->hasPageActions( $data['skin']->getContext() );
Action::getActionName( RequestContext::getMain() ) === 'view';
$hasTalkTabs = $hasPageActions && !$this->isMainPageTalk;
// prepare template data // prepare template data
$templateData = [ $templateData = [
@ -268,7 +266,8 @@ class MinervaTemplate extends BaseTemplate {
'secondaryactionshtml' => $this->getSecondaryActionsHtml(), 'secondaryactionshtml' => $this->getSecondaryActionsHtml(),
'footer' => $this->getFooterTemplateData( $data ), 'footer' => $this->getFooterTemplateData( $data ),
'isBeta' => $skinOptions->get( SkinOptions::OPTIONS_MOBILE_BETA ), 'isBeta' => $skinOptions->get( SkinOptions::OPTIONS_MOBILE_BETA ),
'tabs' => $hasTalkTabs && $skinOptions->get( SkinOptions::OPTIONS_TALK_AT_TOP ) ? [ 'tabs' => $this->showTalkTabs( $hasPageActions, $skinOptions ) &&
$skinOptions->get( SkinOptions::OPTIONS_TALK_AT_TOP ) ? [
'items' => array_values( $data['content_navigation']['namespaces'] ), 'items' => array_values( $data['content_navigation']['namespaces'] ),
] : false, ] : false,
]; ];
@ -280,4 +279,27 @@ class MinervaTemplate extends BaseTemplate {
</html> </html>
<?php <?php
} }
/**
* @param IContextSource $context
* @return bool
*/
private function hasPageActions( IContextSource $context ) {
return !$this->isSpecialPage && !$this->isMainPage &&
Action::getActionName( $context ) === 'view';
}
/**
* @param bool $hasPageActions
* @param SkinOptions $skinOptions
* @return bool
*/
private function showTalkTabs( $hasPageActions, SkinOptions $skinOptions ) {
$hasTalkTabs = $hasPageActions && !$this->isMainPageTalk;
if ( !$hasTalkTabs && $this->isSpecialPage &&
$skinOptions->get( SkinOptions::OPTION_TABS_ON_SPECIALS ) ) {
$hasTalkTabs = true;
}
return $hasTalkTabs;
}
} }