From 95abf6b9af8b9e7976a064e12b1505c422627c30 Mon Sep 17 00:00:00 2001 From: bwang Date: Wed, 20 Oct 2021 11:40:25 -0500 Subject: [PATCH] Remove MinervaTemplate::getSecondaryActions Bug: T291875 Change-Id: Iefff2007c561adfd5886f9c0521341b3922e7653 --- includes/Skins/MinervaTemplate.php | 46 ------------------------------ includes/Skins/SkinMinerva.php | 24 ++++++++++------ includes/Skins/skin.mustache | 13 ++++++++- 3 files changed, 28 insertions(+), 55 deletions(-) diff --git a/includes/Skins/MinervaTemplate.php b/includes/Skins/MinervaTemplate.php index fe5f8fa3d..5b48a450e 100644 --- a/includes/Skins/MinervaTemplate.php +++ b/includes/Skins/MinervaTemplate.php @@ -65,51 +65,6 @@ class MinervaTemplate extends BaseTemplate { return ''; } - /** - * @return bool - */ - protected function isFallbackEditor() { - $action = $this->getSkin()->getRequest()->getVal( 'action' ); - return $action === 'edit'; - } - - /** - * Get page secondary actions - * @return array - */ - protected function getSecondaryActions() { - if ( $this->isFallbackEditor() ) { - return []; - } - - return $this->data['secondary_actions']; - } - - /** - * Get HTML representing secondary page actions like language selector - * @return string - */ - protected function getSecondaryActionsHtml() { - $baseClass = MinervaUI::buttonClass( '', 'button' ); - /** @var SkinMinerva $skin */ - $skin = $this->getSkin(); - $html = ''; - // no secondary actions on the user page - if ( $skin instanceof SkinMinerva && !$skin->getUserPageHelper()->isUserPage() ) { - foreach ( $this->getSecondaryActions() as $el ) { - if ( isset( $el['attributes']['class'] ) ) { - $el['attributes']['class'] .= ' ' . $baseClass; - } else { - $el['attributes']['class'] = $baseClass; - } - // @phan-suppress-next-line PhanTypeMismatchArgument - $html .= Html::element( 'a', $el['attributes'], $el['label'] ); - } - } - - return $html; - } - /** * Gets the main menu HTML. * @param array $data Data used to build the page @@ -139,7 +94,6 @@ class MinervaTemplate extends BaseTemplate { 'headinghtml' => $data['headinghtml'] ?? '', 'postheadinghtml' => $data['postheadinghtml'] ?? '', 'userMenuHTML' => $data['userMenuHTML'], - 'secondaryactionshtml' => $this->getSecondaryActionsHtml(), 'html-minerva-lastmodified' => $this->getHistoryLinkHtml( $data ), // Note mobile-license is only available on the mobile skin. It is outputted as part of diff --git a/includes/Skins/SkinMinerva.php b/includes/Skins/SkinMinerva.php index 7936bf563..8768eaf95 100644 --- a/includes/Skins/SkinMinerva.php +++ b/includes/Skins/SkinMinerva.php @@ -31,8 +31,8 @@ use MediaWiki\Minerva\Skins\SkinUserPageHelper; * @ingroup Skins */ class SkinMinerva extends SkinMustache { - /** @var array|null Cached array of content navigation URLs */ - private $contentNavigationUrls = null; + /** @var array Cached array of content navigation URLs */ + private $contentNavigationUrls = []; /** @var array|null cached array of page action URLs */ private $pageActionsMenu = null; @@ -75,6 +75,13 @@ class SkinMinerva extends SkinMustache { Action::getActionName( $this->getContext() ) === 'view'; } + /** + * @return bool + */ + private function hasSecondaryActions() { + return !$this->getUserPageHelper()->isUserPage(); + } + /** * @return bool */ @@ -127,6 +134,7 @@ class SkinMinerva extends SkinMustache { 'data-minerva-tabs' => $this->getTabsData(), 'html-minerva-page-actions' => $this->getPageActionsHtml(), 'html-minerva-subject-link' => $this->getSubjectPage(), + 'data-minerva-secondary-actions' => $this->hasSecondaryActions() ? $this->getSecondaryActions() : [], ]; } @@ -212,9 +220,6 @@ class SkinMinerva extends SkinMustache { // Generate skin template $tpl = parent::prepareQuickTemplate(); - // Set the links for page secondary actions - $tpl->set( 'secondary_actions', $this->getSecondaryActions( $tpl ) ); - // Construct various Minerva-specific interface elements $this->prepareMenus( $tpl ); $this->prepareHeaderAndFooter( $tpl ); @@ -733,10 +738,13 @@ class SkinMinerva extends SkinMustache { /** * Returns an array of links for page secondary actions - * @param BaseTemplate $tpl * @return array */ - protected function getSecondaryActions( BaseTemplate $tpl ) { + protected function getSecondaryActions() { + if ( $this->isFallbackEditor() ) { + return []; + } + $services = MediaWikiServices::getInstance(); $skinOptions = $this->getSkinOptions(); $namespaceInfo = $services->getNamespaceInfo(); @@ -757,7 +765,7 @@ class SkinMinerva extends SkinMustache { $this->getUser()->isRegistered() && !$this->isTalkPageWithViewAction() ) { - $namespaces = $tpl->data['content_navigation']['namespaces']; + $namespaces = $this->contentNavigationUrls['namespaces']; // FIXME [core]: This seems unnecessary.. $subjectId = $title->getNamespaceKey( '' ); $talkId = $subjectId === 'main' ? 'talk' : "{$subjectId}_talk"; diff --git a/includes/Skins/skin.mustache b/includes/Skins/skin.mustache index ef2da2fe5..8cd472881 100644 --- a/includes/Skins/skin.mustache +++ b/includes/Skins/skin.mustache @@ -75,7 +75,18 @@ {{{html-minerva-subject-link}}}
- {{{secondaryactionshtml}}} + {{#data-minerva-secondary-actions}} + {{#talk}} + + {{{label}}} + + {{/talk}} + {{#language}} + + {{{label}}} + + {{/language}} + {{/data-minerva-secondary-actions}}
{{#html-categories}}
{{{.}}}