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-05-23 22:34:10 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Main as MainMenu;
|
|
|
|
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;
|
|
|
|
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
|
|
|
|
use MediaWiki\Minerva\Permissions\MinervaNoPagePermissions;
|
2019-04-10 21:43:50 +00:00
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
2019-04-10 12:52:34 +00:00
|
|
|
use MediaWiki\Minerva\SkinUserPageHelper;
|
|
|
|
|
|
|
|
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-01 16:18:18 +00:00
|
|
|
$builder = $options->get( SkinOptions::AMC_MODE ) ?
|
2019-07-25 10:34:50 +00:00
|
|
|
new AdvancedUserMenuBuilder(
|
|
|
|
$context,
|
|
|
|
$context->getUser(),
|
|
|
|
$definitions
|
|
|
|
) :
|
|
|
|
new DefaultUserMenuBuilder();
|
|
|
|
|
|
|
|
return new UserMenuDirector(
|
|
|
|
$builder,
|
|
|
|
$context->getSkin()
|
|
|
|
);
|
|
|
|
},
|
2019-06-21 16:52:22 +00:00
|
|
|
'Minerva.Menu.MainDirector' => function ( MediaWikiServices $services ): MainMenu\Director {
|
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-01 16:18:18 +00:00
|
|
|
$builder = $options->get( SkinOptions::AMC_MODE ) ?
|
2019-05-23 22:34:10 +00:00
|
|
|
new MainMenu\AdvancedBuilder( $showMobileOptions, $user, $definitions ) :
|
|
|
|
new MainMenu\DefaultBuilder( $showMobileOptions, $user, $definitions );
|
2019-04-08 17:08:57 +00:00
|
|
|
|
2019-06-21 16:22:17 +00:00
|
|
|
return new MainMenu\Director( $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-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-05-24 00:07:27 +00:00
|
|
|
$services->getPermissionManager(),
|
2019-06-24 16:15:06 +00:00
|
|
|
$services->getService( 'Minerva.Permissions' ),
|
|
|
|
$skinOptions,
|
2019-07-09 16:10:31 +00:00
|
|
|
$userPageHelper,
|
|
|
|
$languagesHelper
|
2019-05-23 22:34:10 +00:00
|
|
|
);
|
2019-08-01 16:18:18 +00:00
|
|
|
if ( $skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) ) {
|
2019-05-23 22:34:10 +00:00
|
|
|
$overflowBuilder = $userPageHelper->isUserPage() ?
|
|
|
|
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
|
|
|
$userPageHelper,
|
|
|
|
$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 {
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
$title = $context->getTitle();
|
|
|
|
|
|
|
|
// Title may be undefined in certain contexts (T179833)
|
|
|
|
if ( $title ) {
|
|
|
|
$contentHandler = ContentHandler::getForTitle( $title );
|
|
|
|
|
|
|
|
return new MinervaPagePermissions(
|
|
|
|
$context->getTitle(),
|
|
|
|
$context->getConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$services->getService( 'Minerva.SkinOptions' ),
|
2019-07-09 16:10:31 +00:00
|
|
|
$contentHandler,
|
|
|
|
$services->getService( 'Minerva.LanguagesHelper' )
|
2019-05-24 00:07:27 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return new MinervaNoPagePermissions();
|
|
|
|
}
|
2019-04-10 12:52:34 +00:00
|
|
|
}
|
|
|
|
];
|