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
|
|
|
|
*/
|
|
|
|
|
2020-08-24 21:49:04 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
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 [
|
2021-05-03 14:12:42 +00:00
|
|
|
'Minerva.Menu.Definitions' => static function ( MediaWikiServices $services ): Definitions {
|
2019-07-25 10:34:50 +00:00
|
|
|
return new Definitions( RequestContext::getMain(), $services->getSpecialPageFactory() );
|
|
|
|
},
|
2021-05-03 14:12:42 +00:00
|
|
|
'Minerva.Menu.UserMenuDirector' => static function ( MediaWikiServices $services ): UserMenuDirector {
|
2019-07-25 10:34:50 +00:00
|
|
|
$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()
|
|
|
|
);
|
|
|
|
},
|
2021-05-03 14:12:42 +00:00
|
|
|
'Minerva.Menu.MainDirector' => static 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();
|
2020-06-25 21:06:46 +00:00
|
|
|
// Add a donate link (see https://phabricator.wikimedia.org/T219793)
|
|
|
|
$showDonateLink = $options->get( SkinOptions::SHOW_DONATE );
|
2019-08-22 20:31:31 +00:00
|
|
|
$builder = $options->get( SkinOptions::MAIN_MENU_EXPANDED ) ?
|
2020-06-25 21:06:46 +00:00
|
|
|
new AdvancedMainMenuBuilder( $showMobileOptions, $showDonateLink, $user, $definitions ) :
|
|
|
|
new DefaultMainMenuBuilder( $showMobileOptions, $showDonateLink, $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' =>
|
2021-05-03 14:12:42 +00:00
|
|
|
static function ( MediaWikiServices $services ): PageActionsMenu\PageActionsDirector {
|
2020-05-31 14:35:29 +00:00
|
|
|
/**
|
|
|
|
* @var SkinOptions $skinOptions
|
|
|
|
* @var SkinMinerva $skin
|
|
|
|
* @var SkinUserPageHelper $userPageHelper
|
|
|
|
*/
|
|
|
|
$skinOptions = $services->getService( 'Minerva.SkinOptions' );
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
$title = $context->getTitle();
|
|
|
|
$user = $context->getUser();
|
|
|
|
$userPageHelper = $services->getService( 'Minerva.SkinUserPageHelper' );
|
|
|
|
$languagesHelper = $services->getService( 'Minerva.LanguagesHelper' );
|
2019-12-12 22:49:48 +00:00
|
|
|
|
2020-05-31 14:35:29 +00:00
|
|
|
$relevantUserPageHelper = $title->inNamespace( NS_USER_TALK ) ?
|
|
|
|
new SkinUserPageHelper(
|
2021-02-26 10:45:05 +00:00
|
|
|
$services->getUserNameUtils(),
|
2021-04-29 20:24:13 +00:00
|
|
|
$context->getSkin()->getRelevantTitle()->getSubjectPage(),
|
|
|
|
$context
|
2020-05-31 14:35:29 +00:00
|
|
|
) :
|
|
|
|
$userPageHelper;
|
2019-12-12 22:49:48 +00:00
|
|
|
|
2021-04-27 20:39:57 +00:00
|
|
|
$watchlistManager = $services->getWatchlistManager();
|
|
|
|
|
2020-05-31 14:35:29 +00:00
|
|
|
$toolbarBuilder = new PageActionsMenu\ToolbarBuilder(
|
|
|
|
$title,
|
|
|
|
$user,
|
|
|
|
$context,
|
|
|
|
$services->getService( 'Minerva.Permissions' ),
|
|
|
|
$skinOptions,
|
|
|
|
$relevantUserPageHelper,
|
2020-08-24 21:49:04 +00:00
|
|
|
$languagesHelper,
|
|
|
|
new ServiceOptions( PageActionsMenu\ToolbarBuilder::CONSTRUCTOR_OPTIONS,
|
2021-04-27 20:39:57 +00:00
|
|
|
$services->getMainConfig() ),
|
|
|
|
$watchlistManager
|
2020-05-31 14:35:29 +00:00
|
|
|
);
|
|
|
|
if ( $skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) ) {
|
2021-03-09 19:43:14 +00:00
|
|
|
$overflowBuilder = $relevantUserPageHelper->isUserPage() ?
|
|
|
|
new PageActionsMenu\UserNamespaceOverflowBuilder(
|
|
|
|
$title,
|
|
|
|
$context,
|
|
|
|
$services->getService( 'Minerva.Permissions' ),
|
|
|
|
$languagesHelper
|
|
|
|
) :
|
|
|
|
new PageActionsMenu\DefaultOverflowBuilder(
|
|
|
|
$context,
|
|
|
|
$services->getService( 'Minerva.Permissions' )
|
|
|
|
);
|
2020-05-31 14:35:29 +00:00
|
|
|
} else {
|
|
|
|
$overflowBuilder = new PageActionsMenu\EmptyOverflowBuilder();
|
|
|
|
}
|
2019-05-23 22:34:10 +00:00
|
|
|
|
2020-05-31 14:35:29 +00:00
|
|
|
return new PageActionsMenu\PageActionsDirector(
|
|
|
|
$toolbarBuilder,
|
|
|
|
$overflowBuilder,
|
|
|
|
$context
|
|
|
|
);
|
|
|
|
},
|
2021-05-03 14:12:42 +00:00
|
|
|
'Minerva.SkinUserPageHelper' => static function ( MediaWikiServices $services ): SkinUserPageHelper {
|
2019-07-31 11:10:57 +00:00
|
|
|
return new SkinUserPageHelper(
|
2021-02-26 10:45:05 +00:00
|
|
|
$services->getUserNameUtils(),
|
2021-04-29 20:24:13 +00:00
|
|
|
RequestContext::getMain()->getSkin()->getRelevantTitle(),
|
|
|
|
RequestContext::getMain()
|
2019-07-31 11:10:57 +00:00
|
|
|
);
|
2019-04-10 21:43:50 +00:00
|
|
|
},
|
2021-05-03 14:12:42 +00:00
|
|
|
'Minerva.LanguagesHelper' => static function (): LanguagesHelper {
|
2019-07-09 16:10:31 +00:00
|
|
|
return new LanguagesHelper( RequestContext::getMain()->getOutput() );
|
|
|
|
},
|
2021-05-03 14:12:42 +00:00
|
|
|
'Minerva.SkinOptions' => static function (): SkinOptions {
|
2019-04-10 21:43:50 +00:00
|
|
|
return new SkinOptions();
|
2019-05-24 00:07:27 +00:00
|
|
|
},
|
2021-05-03 14:12:42 +00:00
|
|
|
'Minerva.Permissions' => static 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
|
|
|
}
|
|
|
|
];
|