Hygiene: Wrap userMenu and pageActions into prepareMenus
Changes: - introduce preapreMenus() - move getUserMenuHTML logic into prepareMenus - move preparePageActions logic into prepareMenus - rename 'page_actions' into 'pageActionsMenu' to be consistent Change-Id: Ie8cc137f749741074e1a5787bee67893fc45fde9
This commit is contained in:
parent
d8de612e0c
commit
ab1d39ea4f
|
@ -55,7 +55,7 @@ class MinervaTemplate extends BaseTemplate {
|
|||
* @return array
|
||||
*/
|
||||
protected function getPageActions() {
|
||||
return $this->isFallbackEditor() ? [] : $this->data['page_actions'];
|
||||
return $this->isFallbackEditor() ? [] : $this->data['pageActionsMenu'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,7 +233,7 @@ class MinervaTemplate extends BaseTemplate {
|
|||
|
||||
$internalBanner = $data[ 'internalBanner' ];
|
||||
$preBodyHtml = $data['prebodyhtml'] ?? '';
|
||||
$hasHeadingHolder = $internalBanner || $preBodyHtml || isset( $data['page_actions'] );
|
||||
$hasHeadingHolder = $internalBanner || $preBodyHtml || isset( $data['pageActionsMenu'] );
|
||||
$hasPageActions = $this->hasPageActions( $data['skin']->getContext() );
|
||||
|
||||
// prepare template data
|
||||
|
|
|
@ -89,17 +89,6 @@ class SkinMinerva extends SkinTemplate {
|
|||
return $this->mainMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BaseTemplate $tpl
|
||||
* @return string|null
|
||||
*/
|
||||
private function getUserMenuHTML( BaseTemplate $tpl ) {
|
||||
/** @var \MediaWiki\Minerva\Menu\User\UserMenuDirector $director */
|
||||
$director = MediaWikiServices::getInstance()
|
||||
->getService( 'Minerva.Menu.UserMenuDirector' );
|
||||
return $director->renderMenuData( $tpl->getPersonalTools() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the site name for the footer, either as a text or <img> tag
|
||||
* @return string
|
||||
|
@ -164,26 +153,37 @@ class SkinMinerva extends SkinTemplate {
|
|||
// example, on a special page)
|
||||
$tpl->set( 'unstyledContent', $out->getProperty( 'unstyledContent' ) );
|
||||
|
||||
// Set the links for the main menu
|
||||
$tpl->set( 'mainMenu', $this->getMainMenu()->getMenuData() );
|
||||
|
||||
// Set the links for page secondary actions
|
||||
$tpl->set( 'userMenuHTML', $this->getUserMenuHTML( $tpl ) );
|
||||
|
||||
// Set the links for page secondary actions
|
||||
$tpl->set( 'secondary_actions', $this->getSecondaryActions( $tpl ) );
|
||||
|
||||
// Construct various Minerva-specific interface elements
|
||||
$this->prepareMenus( $tpl );
|
||||
$this->preparePageContent( $tpl );
|
||||
$this->prepareHeaderAndFooter( $tpl );
|
||||
$this->prepareBanners( $tpl );
|
||||
$this->preparePageActions( $tpl );
|
||||
$this->prepareUserNotificationsButton( $tpl, $tpl->get( 'newtalk' ) );
|
||||
$this->prepareLanguages( $tpl );
|
||||
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare all Minerva menus
|
||||
* @param BaseTemplate $tpl
|
||||
* @throws MWException
|
||||
*/
|
||||
private function prepareMenus( BaseTemplate $tpl ) {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
/** @var \MediaWiki\Minerva\Menu\PageActions\PageActionsDirector $pageActionsDirector */
|
||||
$pageActionsDirector = $services->getService( 'Minerva.Menu.PageActionsDirector' );
|
||||
/** @var \MediaWiki\Minerva\Menu\User\UserMenuDirector $userMenuDirector */
|
||||
$userMenuDirector = $services->getService( 'Minerva.Menu.UserMenuDirector' );
|
||||
|
||||
$tpl->set( 'mainMenu', $this->getMainMenu()->getMenuData() );
|
||||
$tpl->set( 'pageActionsMenu', $pageActionsDirector->buildMenu( $tpl->getToolbox() ) );
|
||||
$tpl->set( 'userMenuHTML', $userMenuDirector->renderMenuData( $tpl->getPersonalTools() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the header and the content of a page
|
||||
* Stores in QuickTemplate prebodytext, postbodytext keys
|
||||
|
@ -764,23 +764,6 @@ class SkinMinerva extends SkinTemplate {
|
|||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare configured and available page actions
|
||||
*
|
||||
* If a page action should display a placeholder element
|
||||
* (i.e. it will be hydrated on the client with JS) add the 'jsonly' CSS class to
|
||||
* the 'class' key of its array.
|
||||
*
|
||||
* @param BaseTemplate $tpl
|
||||
*/
|
||||
protected function preparePageActions( BaseTemplate $tpl ) {
|
||||
/** @var \MediaWiki\Minerva\Menu\PageActions\PageActionsDirector $director */
|
||||
$director = MediaWikiServices::getInstance()->getService( 'Minerva.Menu.PageActionsDirector' );
|
||||
$tpl->set( 'page_actions',
|
||||
$director->buildMenu( $tpl->getToolbox() )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Minerva skin do not have sidebar, there is no need to calculate that.
|
||||
* @return array
|
||||
|
|
Loading…
Reference in New Issue