mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-23 22:03:39 +00:00
Integrate service 'Minerva.Menu.UserMenuDirector' into SkinMinerva
The service 'Minerva.Menu.UserMenuDirector' is bad because it depends on the global state. Change-Id: Ife13188745b39844356e7976379582d5f451f5a3
This commit is contained in:
parent
5027a28fc1
commit
c50069252d
|
@ -27,9 +27,6 @@ use MediaWiki\Minerva\Menu\Main\AdvancedMainMenuBuilder;
|
|||
use MediaWiki\Minerva\Menu\Main\DefaultMainMenuBuilder;
|
||||
use MediaWiki\Minerva\Menu\Main\MainMenuDirector;
|
||||
use MediaWiki\Minerva\Menu\PageActions as PageActionsMenu;
|
||||
use MediaWiki\Minerva\Menu\User\AdvancedUserMenuBuilder;
|
||||
use MediaWiki\Minerva\Menu\User\DefaultUserMenuBuilder;
|
||||
use MediaWiki\Minerva\Menu\User\UserMenuDirector;
|
||||
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
|
||||
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
|
||||
use MediaWiki\Minerva\SkinOptions;
|
||||
|
@ -43,25 +40,6 @@ return [
|
|||
$services->getSpecialPageFactory()
|
||||
);
|
||||
},
|
||||
'Minerva.Menu.UserMenuDirector' => static function ( MediaWikiServices $services ): UserMenuDirector {
|
||||
$context = RequestContext::getMain();
|
||||
$options = $services->getService( 'Minerva.SkinOptions' );
|
||||
$definitions = $services->getService( 'Minerva.Menu.Definitions' )
|
||||
->setContext( $context );
|
||||
|
||||
$builder = $options->get( SkinOptions::PERSONAL_MENU ) ?
|
||||
new AdvancedUserMenuBuilder(
|
||||
$context,
|
||||
$context->getUser(),
|
||||
$definitions
|
||||
) :
|
||||
new DefaultUserMenuBuilder();
|
||||
|
||||
return new UserMenuDirector(
|
||||
$builder,
|
||||
$context->getSkin()
|
||||
);
|
||||
},
|
||||
'Minerva.Menu.MainDirector' => static function ( MediaWikiServices $services ): MainMenuDirector {
|
||||
$context = RequestContext::getMain();
|
||||
/** @var SkinOptions $options */
|
||||
|
|
|
@ -29,8 +29,11 @@ use MediaWiki\Linker\LinkRenderer;
|
|||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Minerva\LanguagesHelper;
|
||||
use MediaWiki\Minerva\Menu\Definitions;
|
||||
use MediaWiki\Minerva\Menu\Main\MainMenuDirector;
|
||||
use MediaWiki\Minerva\Menu\PageActions\PageActionsDirector;
|
||||
use MediaWiki\Minerva\Menu\User\AdvancedUserMenuBuilder;
|
||||
use MediaWiki\Minerva\Menu\User\DefaultUserMenuBuilder;
|
||||
use MediaWiki\Minerva\Menu\User\UserMenuDirector;
|
||||
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
|
||||
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
|
||||
|
@ -71,6 +74,8 @@ class SkinMinerva extends SkinMustache {
|
|||
|
||||
private LanguagesHelper $languagesHelper;
|
||||
|
||||
private Definitions $definitions;
|
||||
|
||||
private IMinervaPagePermissions $permissions;
|
||||
|
||||
private SkinOptions $skinOptions;
|
||||
|
@ -87,6 +92,7 @@ class SkinMinerva extends SkinMustache {
|
|||
* @param GenderCache $genderCache
|
||||
* @param LinkRenderer $linkRenderer
|
||||
* @param LanguagesHelper $languagesHelper
|
||||
* @param Definitions $definitions
|
||||
* @param MinervaPagePermissions $permissions
|
||||
* @param SkinOptions $skinOptions
|
||||
* @param SkinUserPageHelper $skinUserPageHelper
|
||||
|
@ -99,6 +105,7 @@ class SkinMinerva extends SkinMustache {
|
|||
GenderCache $genderCache,
|
||||
LinkRenderer $linkRenderer,
|
||||
LanguagesHelper $languagesHelper,
|
||||
Definitions $definitions,
|
||||
MinervaPagePermissions $permissions,
|
||||
SkinOptions $skinOptions,
|
||||
SkinUserPageHelper $skinUserPageHelper,
|
||||
|
@ -111,6 +118,8 @@ class SkinMinerva extends SkinMustache {
|
|||
$this->genderCache = $genderCache;
|
||||
$this->linkRenderer = $linkRenderer;
|
||||
$this->languagesHelper = $languagesHelper;
|
||||
$this->definitions = $definitions
|
||||
->setContext( $this->getContext() );
|
||||
$this->permissions = $permissions
|
||||
->setContext( $this->getContext() );
|
||||
$this->skinOptions = $skinOptions;
|
||||
|
@ -530,9 +539,18 @@ class SkinMinerva extends SkinMustache {
|
|||
* @return string|null
|
||||
*/
|
||||
private function getPersonalToolsMenu( array $personalUrls ) {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
/** @var UserMenuDirector $userMenuDirector */
|
||||
$userMenuDirector = $services->getService( 'Minerva.Menu.UserMenuDirector' );
|
||||
$builder = $this->skinOptions->get( SkinOptions::PERSONAL_MENU ) ?
|
||||
new AdvancedUserMenuBuilder(
|
||||
$this->getContext(),
|
||||
$this->getUser(),
|
||||
$this->definitions
|
||||
) :
|
||||
new DefaultUserMenuBuilder();
|
||||
|
||||
$userMenuDirector = new UserMenuDirector(
|
||||
$builder,
|
||||
$this->getContext()->getSkin()
|
||||
);
|
||||
return $userMenuDirector->renderMenuData( $personalUrls );
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,7 @@
|
|||
"GenderCache",
|
||||
"LinkRenderer",
|
||||
"Minerva.LanguagesHelper",
|
||||
"Minerva.Menu.Definitions",
|
||||
"Minerva.Permissions",
|
||||
"Minerva.SkinOptions",
|
||||
"Minerva.SkinUserPageHelper",
|
||||
|
|
|
@ -42,6 +42,7 @@ class SkinMinervaTest extends MediaWikiIntegrationTestCase {
|
|||
$services->getGenderCache(),
|
||||
$services->getLinkRenderer(),
|
||||
$services->getService( 'Minerva.LanguagesHelper' ),
|
||||
$services->getService( 'Minerva.Menu.Definitions' ),
|
||||
$services->getService( 'Minerva.Permissions' ),
|
||||
$services->getService( 'Minerva.SkinOptions' ),
|
||||
$services->getService( 'Minerva.SkinUserPageHelper' ),
|
||||
|
|
Loading…
Reference in a new issue