| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Minerva\Menu\PageActions; |
| 22 |
|
| 23 |
use MediaWiki\Minerva\Menu\Entries\IMenuEntry; |
| 24 |
use MediaWiki\Minerva\Menu\Entries\SingleMenuEntry; |
| 25 |
use MediaWiki\Minerva\Menu\Group; |
| 26 |
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions; |
| 27 |
use MediaWiki\Title\Title; |
| 28 |
use MessageLocalizer; |
| 29 |
|
| 30 |
class DefaultOverflowBuilder implements IOverflowBuilder { |
| 31 |
|
| 32 |
private Title $title; |
| 33 |
private MessageLocalizer $messageLocalizer; |
| 34 |
private IMinervaPagePermissions $permissions; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function __construct( |
| 44 |
Title $title, |
| 45 |
MessageLocalizer $messageLocalizer, |
| 46 |
IMinervaPagePermissions $permissions |
| 47 |
) { |
| 48 |
$this->title = $title; |
| 49 |
$this->messageLocalizer = $messageLocalizer; |
| 50 |
$this->permissions = $permissions; |
| 51 |
} |
| 52 |
|
| 53 |
public function getTitle(): Title { |
| 54 |
return $this->title; |
| 55 |
} |
| 56 |
|
| 57 |
public function getMessageLocalizer(): MessageLocalizer { |
| 58 |
return $this->messageLocalizer; |
| 59 |
} |
| 60 |
|
| 61 |
public function isAllowed( string $permission ): bool { |
| 62 |
return $this->permissions->isAllowed( $permission ); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function getGroup( array $toolbox, array $actions ): Group { |
| 69 |
$group = new Group( 'p-tb' ); |
| 70 |
|
| 71 |
$override = $this->isAllowed( IMinervaPagePermissions::EDIT_OR_CREATE ) ? [ |
| 72 |
'editfull' => [ |
| 73 |
'icon' => 'edit', |
| 74 |
'text' => $this->messageLocalizer->msg( 'minerva-page-actions-editfull' ), |
| 75 |
'href' => $this->title->getLocalURL( [ 'action' => 'edit', 'section' => 'all' ] ), |
| 76 |
'class' => 'edit-link', |
| 77 |
], |
| 78 |
] : []; |
| 79 |
|
| 80 |
$combinedMenu = array_merge( $toolbox, $override, $actions ); |
| 81 |
unset( $combinedMenu[ 'watch' ] ); |
| 82 |
unset( $combinedMenu[ 'unwatch' ] ); |
| 83 |
foreach ( $combinedMenu as $key => $definition ) { |
| 84 |
$icon = $definition['icon'] ?? null; |
| 85 |
|
| 86 |
if ( $icon ) { |
| 87 |
$entry = $this->build( $key, $icon, $key, $combinedMenu ); |
| 88 |
if ( $entry ) { |
| 89 |
$group->insertEntry( $entry ); |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
return $group; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
private function build( $name, $icon, $toolboxIdx, array $toolbox ): ?IMenuEntry { |
| 106 |
$href = $toolbox[$toolboxIdx]['href'] ?? null; |
| 107 |
$originalMsg = $toolbox[$toolboxIdx]['text'] ?? |
| 108 |
$this->messageLocalizer->msg( $toolboxIdx )->text(); |
| 109 |
|
| 110 |
$entry = new SingleMenuEntry( |
| 111 |
'page-actions-overflow-' . $name, |
| 112 |
$originalMsg, |
| 113 |
$href, |
| 114 |
$toolbox[$name]['class'] ?? false |
| 115 |
); |
| 116 |
|
| 117 |
return $href ? $entry->setIcon( $icon )->trackClicks( $name ) : null; |
| 118 |
} |
| 119 |
} |