Hygiene: rename $navUrls to $toolbox

Previously we were passing the $tpl->data['nav_urls'] array,
because of that all params were called $navUrls. That approach
was incorrect and we have to pass $tpl->getToolbox(), which
means all $navUrls variables/paramters have to be renamed to
$toolbox for better clarity

Changes:
 - renamed $navUrls to $toolbox
 - update phpdocs blocks
 - renamed buildEntry() into build()

Bug: T222630
Change-Id: Id0023cfbb9779c502edc0f91e31a2a912af84084
This commit is contained in:
Piotr Miazga 2019-06-14 18:57:26 +02:00
parent 3461c9dd93
commit b8abf809ac
5 changed files with 34 additions and 28 deletions

View File

@ -44,14 +44,14 @@ class DefaultOverflowBuilder implements IOverflowBuilder {
/**
* @inheritDoc
*/
public function getGroup( array $navUrls ) {
public function getGroup( array $toolbox ) {
$group = new Group();
$possibleEntries = array_filter( [
$this->buildEntry( 'info', 'info', 'info', $navUrls ),
$this->buildEntry( 'permalink', 'link', 'permalink', $navUrls ),
$this->buildEntry( 'backlinks', 'articleRedirect', 'whatlinkshere', $navUrls ),
$this->buildEntry( 'wikibase', 'logo-Wikidata', 'wikibase', $navUrls ),
$this->buildEntry( 'cite', 'quotes', 'citethispage', $navUrls )
$this->build( 'info', 'info', 'info', $toolbox ),
$this->build( 'permalink', 'link', 'permalink', $toolbox ),
$this->build( 'backlinks', 'articleRedirect', 'whatlinkshere', $toolbox ),
$this->build( 'wikibase', 'logo-Wikidata', 'wikibase', $toolbox ),
$this->build( 'cite', 'quotes', 'citethispage', $toolbox )
] );
foreach ( $possibleEntries as $menuEntry ) {
@ -62,14 +62,16 @@ class DefaultOverflowBuilder implements IOverflowBuilder {
}
/**
* Build the single menu entry
*
* @param string $name
* @param string $icon Wikimedia UI icon name.
* @param string $navUrlKey
* @param array $navUrls A set of navigation urls build by SkinTemplate::buildNavUrls()
* @param string $toolboxIdx
* @param array $toolbox An array of common toolbox items from the sidebar menu
* @return PageActionMenuEntry|null
*/
private function buildEntry( $name, $icon, $navUrlKey, array $navUrls ) {
$href = $navUrls[$navUrlKey]['href'] ?? null;
private function build( $name, $icon, $toolboxIdx, array $toolbox ) {
$href = $toolbox[$toolboxIdx]['href'] ?? null;
return $href ?
new PageActionMenuEntry(

View File

@ -27,7 +27,7 @@ class EmptyOverflowBuilder implements IOverflowBuilder {
/**
* @inheritDoc
*/
public function getGroup( array $navUrls ) {
public function getGroup( array $toolbox ) {
return new Group();
}
}

View File

@ -25,8 +25,8 @@ use MediaWiki\Minerva\Menu\Group;
interface IOverflowBuilder {
/**
* @param array $navUrls A set of navigation urls build by SkinTemplate::buildNavUrls()
* @param array $toolbox An array of common toolbox items from the sidebar menu
* @return Group
*/
public function getGroup( array $navUrls );
public function getGroup( array $toolbox );
}

View File

@ -60,14 +60,14 @@ final class PageActionsDirector {
/**
* Build the menu data array that can be passed to views/javascript
* @param array $navUrls A set of navigation urls passed to the builder
* @param array $toolbox An array of common toolbox items from the sidebar menu
* @param bool $doesHaveLangUrls Whether the page is also available in other languages or variants
* @return array
* @throws MWException
*/
public function buildMenu( array $navUrls, $doesHaveLangUrls ): array {
public function buildMenu( array $toolbox, $doesHaveLangUrls ): array {
$toolbar = $this->toolbarBuilder->getGroup( $doesHaveLangUrls );
$overflowMenu = $this->overflowBuilder->getGroup( $navUrls );
$overflowMenu = $this->overflowBuilder->getGroup( $toolbox );
$menu = [
'toolbar' => $toolbar->getEntries()

View File

@ -55,18 +55,18 @@ class UserNamespaceOverflowBuilder implements IOverflowBuilder {
* @inheritDoc
* @throws MWException
*/
public function getGroup( array $navUrls ) {
public function getGroup( array $toolbox ) {
$group = new Group();
$group->insertEntry( $this->buildEntry(
$group->insertEntry( $this->build(
'uploads', 'upload', SpecialPage::getTitleFor( 'Uploads', $this->pageUser )->getLocalURL()
) );
$possibleEntries = array_filter( [
$this->buildEntryFromNav( 'user-rights', 'userAvatar', 'userrights', $navUrls ),
$this->buildEntryFromNav( 'logs', 'listBullet', 'log', $navUrls ),
$this->buildEntryFromNav( 'info', 'info', 'info', $navUrls ),
$this->buildEntryFromNav( 'permalink', 'link', 'permalink', $navUrls ),
$this->buildEntryFromNav( 'backlinks', 'articleRedirect', 'whatlinkshere', $navUrls )
$this->buildFromToolbox( 'user-rights', 'userAvatar', 'userrights', $toolbox ),
$this->buildFromToolbox( 'logs', 'listBullet', 'log', $toolbox ),
$this->buildFromToolbox( 'info', 'info', 'info', $toolbox ),
$this->buildFromToolbox( 'permalink', 'link', 'permalink', $toolbox ),
$this->buildFromToolbox( 'backlinks', 'articleRedirect', 'whatlinkshere', $toolbox )
] );
foreach ( $possibleEntries as $menuEntry ) {
@ -77,23 +77,27 @@ class UserNamespaceOverflowBuilder implements IOverflowBuilder {
}
/**
* Build entry based on the $toolbox element
*
* @param string $name
* @param string $icon Wikimedia UI icon name.
* @param string $navUrlKey
* @param array $navUrls A set of navigation urls build by SkinTemplate::buildNavUrls()
* @param string $toolboxIdx
* @param array $toolbox An array of common toolbox items from the sidebar menu
* @return PageActionMenuEntry|null
*/
private function buildEntryFromNav( $name, $icon, $navUrlKey, array $navUrls ) {
return $this->buildEntry( $name, $icon, $navUrls[$navUrlKey]['href'] ?? null );
private function buildFromToolbox( $name, $icon, $toolboxIdx, array $toolbox ) {
return $this->build( $name, $icon, $toolbox[$toolboxIdx]['href'] ?? null );
}
/**
* Build single Menu entry
*
* @param string $name
* @param string $icon Wikimedia UI icon name.
* @param string|null $href
* @return PageActionMenuEntry|null
*/
private function buildEntry( $name, $icon, $href ) {
private function build( $name, $icon, $href ) {
return $href ?
new PageActionMenuEntry(
'page-actions-overflow-' . $name,