2019-04-10 12:52:34 +00:00
|
|
|
<?php
|
|
|
|
|
2019-04-08 17:08:57 +00:00
|
|
|
/**
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
|
2019-04-10 12:52:34 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-07-09 16:10:31 +00:00
|
|
|
use MediaWiki\Minerva\LanguagesHelper;
|
2019-04-08 17:08:57 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Definitions;
|
2019-08-02 09:00:18 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Main\AdvancedMainMenuBuilder;
|
2020-01-26 19:26:31 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Main\DefaultMainMenuBuilder;
|
|
|
|
use MediaWiki\Minerva\Menu\Main\MainMenuDirector;
|
2019-05-23 22:34:10 +00:00
|
|
|
use MediaWiki\Minerva\Menu\PageActions as PageActionsMenu;
|
2019-07-25 10:34:50 +00:00
|
|
|
use MediaWiki\Minerva\Menu\User\AdvancedUserMenuBuilder;
|
|
|
|
use MediaWiki\Minerva\Menu\User\DefaultUserMenuBuilder;
|
|
|
|
use MediaWiki\Minerva\Menu\User\UserMenuDirector;
|
2019-05-24 00:07:27 +00:00
|
|
|
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
|
2020-01-26 19:26:31 +00:00
|
|
|
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
|
2019-04-10 21:43:50 +00:00
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
2020-05-01 01:16:53 +00:00
|
|
|
use MediaWiki\Minerva\Skins\SkinUserPageHelper;
|
2019-04-10 12:52:34 +00:00
|
|
|
|
|
|
|
return [
|
2019-07-25 10:34:50 +00:00
|
|
|
'Minerva.Menu.Definitions' => function ( MediaWikiServices $services ): Definitions {
|
|
|
|
return new Definitions( RequestContext::getMain(), $services->getSpecialPageFactory() );
|
|
|
|
},
|
|
|
|
'Minerva.Menu.UserMenuDirector' => function ( MediaWikiServices $services ): UserMenuDirector {
|
|
|
|
$options = $services->getService( 'Minerva.SkinOptions' );
|
|
|
|
$definitions = $services->getService( 'Minerva.Menu.Definitions' );
|
|
|
|
|
|
|
|
$context = RequestContext::getMain();
|
2019-08-22 20:31:31 +00:00
|
|
|
$builder = $options->get( SkinOptions::PERSONAL_MENU ) ?
|
2019-07-25 10:34:50 +00:00
|
|
|
new AdvancedUserMenuBuilder(
|
|
|
|
$context,
|
|
|
|
$context->getUser(),
|
|
|
|
$definitions
|
|
|
|
) :
|
|
|
|
new DefaultUserMenuBuilder();
|
|
|
|
|
|
|
|
return new UserMenuDirector(
|
|
|
|
$builder,
|
|
|
|
$context->getSkin()
|
|
|
|
);
|
|
|
|
},
|
2019-08-02 09:00:18 +00:00
|
|
|
'Minerva.Menu.MainDirector' => function ( MediaWikiServices $services ): MainMenuDirector {
|
2019-04-08 17:08:57 +00:00
|
|
|
$context = RequestContext::getMain();
|
|
|
|
/** @var SkinOptions $options */
|
|
|
|
$options = $services->getService( 'Minerva.SkinOptions' );
|
2019-07-25 10:34:50 +00:00
|
|
|
$definitions = $services->getService( 'Minerva.Menu.Definitions' );
|
2019-08-01 16:18:18 +00:00
|
|
|
$showMobileOptions = $options->get( SkinOptions::MOBILE_OPTIONS );
|
2019-04-08 17:08:57 +00:00
|
|
|
$user = $context->getUser();
|
2019-08-22 20:31:31 +00:00
|
|
|
$builder = $options->get( SkinOptions::MAIN_MENU_EXPANDED ) ?
|
2019-08-02 09:00:18 +00:00
|
|
|
new AdvancedMainMenuBuilder( $showMobileOptions, $user, $definitions ) :
|
|
|
|
new DefaultMainMenuBuilder( $showMobileOptions, $user, $definitions );
|
2019-04-08 17:08:57 +00:00
|
|
|
|
2019-08-02 09:00:18 +00:00
|
|
|
return new MainMenuDirector( $builder, $context, $services->getSpecialPageFactory() );
|
2019-04-08 17:08:57 +00:00
|
|
|
},
|
2019-06-21 16:52:22 +00:00
|
|
|
'Minerva.Menu.PageActionsDirector' =>
|
|
|
|
function ( MediaWikiServices $services ): PageActionsMenu\PageActionsDirector {
|
2019-05-23 22:34:10 +00:00
|
|
|
/**
|
|
|
|
* @var SkinOptions $skinOptions
|
|
|
|
* @var SkinMinerva $skin
|
|
|
|
* @var SkinUserPageHelper $userPageHelper
|
|
|
|
*/
|
|
|
|
$skinOptions = $services->getService( 'Minerva.SkinOptions' );
|
|
|
|
$context = RequestContext::getMain();
|
2019-06-24 17:59:11 +00:00
|
|
|
$title = $context->getTitle();
|
|
|
|
$user = $context->getUser();
|
2019-05-23 22:34:10 +00:00
|
|
|
$userPageHelper = $services->getService( 'Minerva.SkinUserPageHelper' );
|
2019-07-09 16:10:31 +00:00
|
|
|
$languagesHelper = $services->getService( 'Minerva.LanguagesHelper' );
|
2019-12-12 22:49:48 +00:00
|
|
|
|
|
|
|
$relevantUserPageHelper = $title->inNamespace( NS_USER_TALK ) ?
|
|
|
|
new SkinUserPageHelper(
|
|
|
|
$context->getSkin()->getRelevantTitle()->getSubjectPage()
|
|
|
|
) :
|
|
|
|
$userPageHelper;
|
|
|
|
|
2019-05-23 22:34:10 +00:00
|
|
|
$toolbarBuilder = new PageActionsMenu\ToolbarBuilder(
|
2019-06-24 17:59:11 +00:00
|
|
|
$title,
|
|
|
|
$user,
|
2019-05-23 23:14:06 +00:00
|
|
|
$context,
|
2019-06-24 16:15:06 +00:00
|
|
|
$services->getService( 'Minerva.Permissions' ),
|
|
|
|
$skinOptions,
|
2019-12-12 22:49:48 +00:00
|
|
|
$relevantUserPageHelper,
|
2019-07-09 16:10:31 +00:00
|
|
|
$languagesHelper
|
2019-05-23 22:34:10 +00:00
|
|
|
);
|
2019-08-01 16:18:18 +00:00
|
|
|
if ( $skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) ) {
|
2019-12-12 22:49:48 +00:00
|
|
|
$overflowBuilder = $relevantUserPageHelper->isUserPage() ?
|
2019-05-23 22:34:10 +00:00
|
|
|
new PageActionsMenu\UserNamespaceOverflowBuilder(
|
2019-06-24 17:59:11 +00:00
|
|
|
$title,
|
2019-05-23 22:34:10 +00:00
|
|
|
$context,
|
2019-06-24 17:59:11 +00:00
|
|
|
$services->getService( 'Minerva.Permissions' ),
|
2019-07-09 16:10:31 +00:00
|
|
|
$languagesHelper
|
2019-05-23 22:34:10 +00:00
|
|
|
) :
|
|
|
|
new PageActionsMenu\DefaultOverflowBuilder(
|
|
|
|
$context
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$overflowBuilder = new PageActionsMenu\EmptyOverflowBuilder();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new PageActionsMenu\PageActionsDirector(
|
|
|
|
$toolbarBuilder,
|
|
|
|
$overflowBuilder,
|
|
|
|
$context
|
|
|
|
);
|
2019-06-21 16:52:22 +00:00
|
|
|
},
|
|
|
|
'Minerva.SkinUserPageHelper' => function (): SkinUserPageHelper {
|
2019-07-31 11:10:57 +00:00
|
|
|
return new SkinUserPageHelper(
|
|
|
|
RequestContext::getMain()->getSkin()->getRelevantTitle()
|
|
|
|
);
|
2019-04-10 21:43:50 +00:00
|
|
|
},
|
2019-07-09 16:10:31 +00:00
|
|
|
'Minerva.LanguagesHelper' => function (): LanguagesHelper {
|
|
|
|
return new LanguagesHelper( RequestContext::getMain()->getOutput() );
|
|
|
|
},
|
2019-06-21 16:52:22 +00:00
|
|
|
'Minerva.SkinOptions' => function (): SkinOptions {
|
2019-04-10 21:43:50 +00:00
|
|
|
return new SkinOptions();
|
2019-05-24 00:07:27 +00:00
|
|
|
},
|
|
|
|
'Minerva.Permissions' => function ( MediaWikiServices $services ): IMinervaPagePermissions {
|
2019-10-08 17:22:31 +00:00
|
|
|
$permissions = new MinervaPagePermissions(
|
|
|
|
$services->getService( 'Minerva.SkinOptions' ),
|
|
|
|
$services->getService( 'Minerva.LanguagesHelper' ),
|
|
|
|
$services->getPermissionManager()
|
|
|
|
);
|
|
|
|
// TODO: This should not be allowed, this is basically global $wgTitle and $wgUser.
|
|
|
|
$permissions->setContext( RequestContext::getMain() );
|
|
|
|
return $permissions;
|
2019-04-10 12:52:34 +00:00
|
|
|
}
|
|
|
|
];
|