mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-18 00:30:40 +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\DefaultMainMenuBuilder;
|
||||||
use MediaWiki\Minerva\Menu\Main\MainMenuDirector;
|
use MediaWiki\Minerva\Menu\Main\MainMenuDirector;
|
||||||
use MediaWiki\Minerva\Menu\PageActions as PageActionsMenu;
|
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\IMinervaPagePermissions;
|
||||||
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
|
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
|
||||||
use MediaWiki\Minerva\SkinOptions;
|
use MediaWiki\Minerva\SkinOptions;
|
||||||
|
@ -43,25 +40,6 @@ return [
|
||||||
$services->getSpecialPageFactory()
|
$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 {
|
'Minerva.Menu.MainDirector' => static function ( MediaWikiServices $services ): MainMenuDirector {
|
||||||
$context = RequestContext::getMain();
|
$context = RequestContext::getMain();
|
||||||
/** @var SkinOptions $options */
|
/** @var SkinOptions $options */
|
||||||
|
|
|
@ -29,8 +29,11 @@ use MediaWiki\Linker\LinkRenderer;
|
||||||
use MediaWiki\Linker\LinkTarget;
|
use MediaWiki\Linker\LinkTarget;
|
||||||
use MediaWiki\MediaWikiServices;
|
use MediaWiki\MediaWikiServices;
|
||||||
use MediaWiki\Minerva\LanguagesHelper;
|
use MediaWiki\Minerva\LanguagesHelper;
|
||||||
|
use MediaWiki\Minerva\Menu\Definitions;
|
||||||
use MediaWiki\Minerva\Menu\Main\MainMenuDirector;
|
use MediaWiki\Minerva\Menu\Main\MainMenuDirector;
|
||||||
use MediaWiki\Minerva\Menu\PageActions\PageActionsDirector;
|
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\Menu\User\UserMenuDirector;
|
||||||
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
|
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
|
||||||
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
|
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
|
||||||
|
@ -71,6 +74,8 @@ class SkinMinerva extends SkinMustache {
|
||||||
|
|
||||||
private LanguagesHelper $languagesHelper;
|
private LanguagesHelper $languagesHelper;
|
||||||
|
|
||||||
|
private Definitions $definitions;
|
||||||
|
|
||||||
private IMinervaPagePermissions $permissions;
|
private IMinervaPagePermissions $permissions;
|
||||||
|
|
||||||
private SkinOptions $skinOptions;
|
private SkinOptions $skinOptions;
|
||||||
|
@ -87,6 +92,7 @@ class SkinMinerva extends SkinMustache {
|
||||||
* @param GenderCache $genderCache
|
* @param GenderCache $genderCache
|
||||||
* @param LinkRenderer $linkRenderer
|
* @param LinkRenderer $linkRenderer
|
||||||
* @param LanguagesHelper $languagesHelper
|
* @param LanguagesHelper $languagesHelper
|
||||||
|
* @param Definitions $definitions
|
||||||
* @param MinervaPagePermissions $permissions
|
* @param MinervaPagePermissions $permissions
|
||||||
* @param SkinOptions $skinOptions
|
* @param SkinOptions $skinOptions
|
||||||
* @param SkinUserPageHelper $skinUserPageHelper
|
* @param SkinUserPageHelper $skinUserPageHelper
|
||||||
|
@ -99,6 +105,7 @@ class SkinMinerva extends SkinMustache {
|
||||||
GenderCache $genderCache,
|
GenderCache $genderCache,
|
||||||
LinkRenderer $linkRenderer,
|
LinkRenderer $linkRenderer,
|
||||||
LanguagesHelper $languagesHelper,
|
LanguagesHelper $languagesHelper,
|
||||||
|
Definitions $definitions,
|
||||||
MinervaPagePermissions $permissions,
|
MinervaPagePermissions $permissions,
|
||||||
SkinOptions $skinOptions,
|
SkinOptions $skinOptions,
|
||||||
SkinUserPageHelper $skinUserPageHelper,
|
SkinUserPageHelper $skinUserPageHelper,
|
||||||
|
@ -111,6 +118,8 @@ class SkinMinerva extends SkinMustache {
|
||||||
$this->genderCache = $genderCache;
|
$this->genderCache = $genderCache;
|
||||||
$this->linkRenderer = $linkRenderer;
|
$this->linkRenderer = $linkRenderer;
|
||||||
$this->languagesHelper = $languagesHelper;
|
$this->languagesHelper = $languagesHelper;
|
||||||
|
$this->definitions = $definitions
|
||||||
|
->setContext( $this->getContext() );
|
||||||
$this->permissions = $permissions
|
$this->permissions = $permissions
|
||||||
->setContext( $this->getContext() );
|
->setContext( $this->getContext() );
|
||||||
$this->skinOptions = $skinOptions;
|
$this->skinOptions = $skinOptions;
|
||||||
|
@ -530,9 +539,18 @@ class SkinMinerva extends SkinMustache {
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
private function getPersonalToolsMenu( array $personalUrls ) {
|
private function getPersonalToolsMenu( array $personalUrls ) {
|
||||||
$services = MediaWikiServices::getInstance();
|
$builder = $this->skinOptions->get( SkinOptions::PERSONAL_MENU ) ?
|
||||||
/** @var UserMenuDirector $userMenuDirector */
|
new AdvancedUserMenuBuilder(
|
||||||
$userMenuDirector = $services->getService( 'Minerva.Menu.UserMenuDirector' );
|
$this->getContext(),
|
||||||
|
$this->getUser(),
|
||||||
|
$this->definitions
|
||||||
|
) :
|
||||||
|
new DefaultUserMenuBuilder();
|
||||||
|
|
||||||
|
$userMenuDirector = new UserMenuDirector(
|
||||||
|
$builder,
|
||||||
|
$this->getContext()->getSkin()
|
||||||
|
);
|
||||||
return $userMenuDirector->renderMenuData( $personalUrls );
|
return $userMenuDirector->renderMenuData( $personalUrls );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@
|
||||||
"GenderCache",
|
"GenderCache",
|
||||||
"LinkRenderer",
|
"LinkRenderer",
|
||||||
"Minerva.LanguagesHelper",
|
"Minerva.LanguagesHelper",
|
||||||
|
"Minerva.Menu.Definitions",
|
||||||
"Minerva.Permissions",
|
"Minerva.Permissions",
|
||||||
"Minerva.SkinOptions",
|
"Minerva.SkinOptions",
|
||||||
"Minerva.SkinUserPageHelper",
|
"Minerva.SkinUserPageHelper",
|
||||||
|
|
|
@ -42,6 +42,7 @@ class SkinMinervaTest extends MediaWikiIntegrationTestCase {
|
||||||
$services->getGenderCache(),
|
$services->getGenderCache(),
|
||||||
$services->getLinkRenderer(),
|
$services->getLinkRenderer(),
|
||||||
$services->getService( 'Minerva.LanguagesHelper' ),
|
$services->getService( 'Minerva.LanguagesHelper' ),
|
||||||
|
$services->getService( 'Minerva.Menu.Definitions' ),
|
||||||
$services->getService( 'Minerva.Permissions' ),
|
$services->getService( 'Minerva.Permissions' ),
|
||||||
$services->getService( 'Minerva.SkinOptions' ),
|
$services->getService( 'Minerva.SkinOptions' ),
|
||||||
$services->getService( 'Minerva.SkinUserPageHelper' ),
|
$services->getService( 'Minerva.SkinUserPageHelper' ),
|
||||||
|
|
Loading…
Reference in a new issue