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:
parent
3461c9dd93
commit
b8abf809ac
|
@ -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(
|
||||
|
|
|
@ -27,7 +27,7 @@ class EmptyOverflowBuilder implements IOverflowBuilder {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getGroup( array $navUrls ) {
|
||||
public function getGroup( array $toolbox ) {
|
||||
return new Group();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue