Remove getPageActionsHtml and related methods

Bug: T293813
Change-Id: I90e45cac13a13c2ce18af16274e327d951868433
This commit is contained in:
jdlrobson 2021-10-19 11:16:43 -07:00
parent 5a7a9c9c31
commit c407d92d5d
3 changed files with 99 additions and 78 deletions

View file

@ -24,55 +24,16 @@ use MediaWiki\Minerva\SkinOptions;
* Extended Template class of BaseTemplate for mobile devices
*/
class MinervaTemplate extends BaseTemplate {
/** @var bool Specify whether the page is a special page */
protected $isSpecialPage;
/** @var bool Specify whether the page is main page */
protected $isMainPage;
/** @var bool */
protected $isMainPageTalk;
/**
* Start render the page in template
* @deprecated please migrate code here to SkinMinerva::getTemplateData
* @return array
*/
public function execute() {
$title = $this->getSkin()->getTitle();
$this->isSpecialPage = $title->isSpecialPage();
$this->isMainPage = $title->isMainPage();
$subjectPage = MediaWikiServices::getInstance()->getNamespaceInfo()
->getSubjectPage( $title );
$this->isMainPageTalk = Title::newFromLinkTarget( $subjectPage )->isMainPage();
Hooks::run( 'MinervaPreRender', [ $this ], '1.35' );
return $this->getTemplateData();
}
/**
* Returns available page actions
* @return array
*/
protected function getPageActions() {
return $this->isFallbackEditor() ? [] : $this->data['pageActionsMenu'];
}
/**
* Get the HTML for rendering the available page actions
* @return string
*/
protected function getPageActionsHtml() {
$templateParser = new TemplateParser( __DIR__ . '/../../includes/Skins/components' );
$pageActions = $this->getPageActions();
$html = '';
if ( $pageActions && $pageActions['toolbar'] ) {
$html = $templateParser->processTemplate( 'PageActionsMenu', $pageActions );
}
return $html;
}
/**
* Returns the 'Last edited' message, e.g. 'Last edited on...'
* @param array $data Data used to build the page
@ -167,8 +128,6 @@ class MinervaTemplate extends BaseTemplate {
$data = $this->data;
$skinOptions = MediaWikiServices::getInstance()->getService( 'Minerva.SkinOptions' );
$templateParser = new TemplateParser( __DIR__ );
$hasHeadingHolder = isset( $data['pageActionsMenu'] );
$hasPageActions = $this->hasPageActions( $data['skin']->getContext() );
// prepare template data
return [
@ -176,11 +135,9 @@ class MinervaTemplate extends BaseTemplate {
'isAnon' => $data['username'] === null,
'userNotificationsHTML' => $data['userNotificationsHTML'] ?? '',
'data-main-menu' => $this->getMainMenuData( $data ),
'hasheadingholder' => $hasHeadingHolder,
'taglinehtml' => $data['taglinehtml'],
'headinghtml' => $data['headinghtml'] ?? '',
'postheadinghtml' => $data['postheadinghtml'] ?? '',
'pageactionshtml' => $hasPageActions ? $this->getPageActionsHtml() : '',
'userMenuHTML' => $data['userMenuHTML'],
'secondaryactionshtml' => $this->getSecondaryActionsHtml(),
@ -191,33 +148,6 @@ class MinervaTemplate extends BaseTemplate {
MobileFrontendSkinHooks::getLicenseText( $this->getSkin() ) : '',
'isBeta' => $skinOptions->get( SkinOptions::BETA_MODE ),
'tabs' => $this->showTalkTabs( $hasPageActions, $skinOptions ) &&
$skinOptions->get( SkinOptions::TALK_AT_TOP ) ? [
'items' => array_values( $data['content_navigation']['namespaces'] ),
] : false,
];
}
/**
* @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::TABS_ON_SPECIALS ) ) {
$hasTalkTabs = true;
}
return $hasTalkTabs;
}
}

View file

@ -31,6 +31,11 @@ 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|null cached array of page action URLs */
private $pageActionsMenu = null;
/** @const LEAD_SECTION_NUMBER integer which corresponds to the lead section
* in editing mode
*/
@ -61,6 +66,50 @@ class SkinMinerva extends SkinMustache {
return $this->skinOptions;
}
/**
* @return bool
*/
private function hasPageActions() {
$title = $this->getTitle();
return !$title->isSpecialPage() && !$title->isMainPage() &&
Action::getActionName( $this->getContext() ) === 'view';
}
/**
* @return bool
*/
private function isFallbackEditor() {
$action = $this->getRequest()->getVal( 'action' );
return $action === 'edit';
}
/**
* Returns available page actions
* @return array
*/
private function getPageActions() {
return $this->isFallbackEditor() ? [] : $this->pageActionsMenu;
}
/**
* Get the HTML for rendering the available page actions
* @return string
*/
private function getPageActionsHtml() {
$hasPageActions = $this->hasPageActions();
if ( !$hasPageActions ) {
return '';
}
$templateParser = new TemplateParser( __DIR__ . '/../../includes/Skins/components' );
$pageActions = $this->getPageActions();
$html = '';
if ( $pageActions && $pageActions['toolbar'] ) {
$html = $templateParser->processTemplate( 'PageActionsMenu', $pageActions );
}
return $html;
}
/**
* @inheritDoc
*/
@ -69,14 +118,56 @@ class SkinMinerva extends SkinMustache {
if ( !$this->hasCategoryLinks() ) {
unset( $data['html-categories'] );
}
$hasPageActions = $this->hasPageActions();
$tpl = $this->prepareQuickTemplate();
$tplData = $tpl->execute();
return $data + $tplData + [
'has-minerva-page-actions' => $hasPageActions,
'data-minerva-tabs' => $this->getTabsData(),
'html-minerva-page-actions' => $this->getPageActionsHtml(),
'html-minerva-subject-link' => $this->getSubjectPage(),
];
}
/**
* Tabs are available if a page has page actions but is not the talk page of
* the main page.
*
* Special pages have tabs if SkinOptions::TABS_ON_SPECIALS is enabled.
* This is used by Extension:GrowthExperiments
*
* @return bool
*/
private function hasPageTabs() {
$title = $this->getTitle();
$skinOptions = $this->getSkinOptions();
$isSpecialPage = $title->isSpecialPage();
$subjectPage = MediaWikiServices::getInstance()->getNamespaceInfo()
->getSubjectPage( $title );
$isMainPageTalk = Title::newFromLinkTarget( $subjectPage )->isMainPage();
return (
$this->hasPageActions() && !$isMainPageTalk
) || (
$isSpecialPage &&
$skinOptions->get( SkinOptions::TABS_ON_SPECIALS )
);
}
/**
* @return array
*/
private function getTabsData() {
$skinOptions = $this->getSkinOptions();
$hasTalkTabs = $skinOptions->get( SkinOptions::TALK_AT_TOP ) && $this->hasPageTabs();
if ( !$hasTalkTabs ) {
return [];
}
return $this->contentNavigationUrls ? [
'items' => array_values( $this->contentNavigationUrls['namespaces'] ),
] : [];
}
/**
* Lazy load the permissions object. We don't want to initialize it as it requires many
* dependencies, sometimes some of those dependencies cannot be fulfilled (like missing Title
@ -149,11 +240,11 @@ class SkinMinerva extends SkinMustache {
$sidebar = parent::buildSidebar();
$personalUrls = $tpl->get( 'personal_urls' );
$personalTools = $this->getSkin()->getPersonalToolsForMakeListItem( $personalUrls );
$nav = $tpl->get( 'content_navigation' ) ?? [];
$nav = $this->buildContentNavigationUrls();
$actions = $nav['actions'] ?? [];
$tpl->set( 'mainMenu', $this->getMainMenu()->getMenuData() );
$tpl->set( 'pageActionsMenu', $pageActionsDirector->buildMenu( $sidebar['TOOLBOX'], $actions ) );
$this->contentNavigationUrls = $nav;
$this->pageActionsMenu = $pageActionsDirector->buildMenu( $sidebar['TOOLBOX'], $actions );
$tpl->set( 'userMenuHTML', $userMenuDirector->renderMenuData( $personalTools ) );
}

View file

@ -50,24 +50,24 @@
<div class="banner-container">
{{>banners}}
</div>
{{#hasheadingholder}}
<div class="pre-content heading-holder">
<div class="page-heading">
{{{headinghtml}}}
{{{taglinehtml}}}
</div>
{{#tabs}}
{{#data-minerva-tabs}}
<div class="minerva__tab-container">
{{#items}}
<a href="{{href}}" rel="{{rel}}" class="minerva__tab {{class}}" data-event-name="tabs.{{context}}">{{text}}</a>
{{/items}}
</div>
{{/tabs}}
{{{pageactionshtml}}}
{{/data-minerva-tabs}}
{{#has-minerva-page-actions}}
{{{html-minerva-page-actions}}}
{{/has-minerva-page-actions}}
{{{postheadinghtml}}}
<div class="minerva__subtitle">{{{html-subtitle}}}</div>
</div>
{{/hasheadingholder}}
<div id="bodyContent" class="content">
{{{html-body-content}}}
{{! This shows "Return to page" on talk page when talk tab not shown at top.