mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-23 22:03:39 +00:00
Donate link should be in a separate group in main menu
Bug: T219793 Change-Id: I7501c87eaa799e4c8a9052f5e3f650a89f376d1b
This commit is contained in:
parent
36384b6050
commit
2e450e104e
|
@ -63,8 +63,13 @@ When enabled and hacks.less exists, hacks.less workarounds are included in style
|
|||
|
||||
#### $wgMinervaDonateLink
|
||||
|
||||
* Type: `Boolean`
|
||||
* Default: `true`
|
||||
* Type: `Array`
|
||||
* Default:
|
||||
```php
|
||||
[
|
||||
'base' => true,
|
||||
]
|
||||
```
|
||||
|
||||
When enabled a donate link will be added to the main menu. The donate link uses the `sitesupport` and `sitesupport-url` mediawiki messages.
|
||||
|
||||
|
|
|
@ -386,8 +386,12 @@ final class Definitions {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
$url = wfAppendQuery( $ctx->msg( 'sitesupport-url' )->text(),
|
||||
[ 'utm_medium' => 'mobileSidebar' ] );
|
||||
// Add term field to allow distinguishing from other sidebars.
|
||||
// https://www.mediawiki.org/wiki/Wikimedia_Product/Analytics_Infrastructure/Schema_fragments#Campaign_Attribution
|
||||
$url = wfAppendQuery(
|
||||
$ctx->msg( 'sitesupport-url' )->text(),
|
||||
[ 'utm_key' => 'minerva' ]
|
||||
);
|
||||
|
||||
$group->insert( 'donate' )->addComponent(
|
||||
$ctx->msg( 'sitesupport' )->text(),
|
||||
|
|
|
@ -40,6 +40,11 @@ final class AdvancedMainMenuBuilder implements IMainMenuBuilder {
|
|||
*/
|
||||
private $showMobileOptions;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $showDonateLink;
|
||||
|
||||
/**
|
||||
* Currently logged in user
|
||||
* @var User
|
||||
|
@ -55,11 +60,13 @@ final class AdvancedMainMenuBuilder implements IMainMenuBuilder {
|
|||
* Initialize the Default Main Menu builder
|
||||
*
|
||||
* @param bool $showMobileOptions Show MobileOptions instead of Preferences
|
||||
* @param bool $showDonateLink whether to show the donate link
|
||||
* @param User $user The current user
|
||||
* @param Definitions $definitions A menu items definitions set
|
||||
*/
|
||||
public function __construct( $showMobileOptions, User $user, Definitions $definitions ) {
|
||||
public function __construct( $showMobileOptions, $showDonateLink, User $user, Definitions $definitions ) {
|
||||
$this->showMobileOptions = $showMobileOptions;
|
||||
$this->showDonateLink = $showDonateLink;
|
||||
$this->user = $user;
|
||||
$this->definitions = $definitions;
|
||||
}
|
||||
|
@ -71,11 +78,19 @@ final class AdvancedMainMenuBuilder implements IMainMenuBuilder {
|
|||
* @throws MWException
|
||||
*/
|
||||
public function getGroups(): array {
|
||||
return [
|
||||
$donate = $this->showDonateLink ?
|
||||
BuilderUtil::getDonateGroup( $this->definitions ) : null;
|
||||
|
||||
$groups = [
|
||||
BuilderUtil::getDiscoveryTools( $this->definitions ),
|
||||
$this->getSiteTools(),
|
||||
BuilderUtil::getConfigurationTools( $this->definitions, $this->showMobileOptions ),
|
||||
];
|
||||
|
||||
if ( $donate ) {
|
||||
$groups[] = $donate;
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,6 @@ namespace MediaWiki\Minerva\Menu\Main;
|
|||
|
||||
use FatalError;
|
||||
use Hooks;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Minerva\Menu\Definitions;
|
||||
use MediaWiki\Minerva\Menu\Group;
|
||||
use MWException;
|
||||
|
@ -33,6 +32,19 @@ use MWException;
|
|||
* @package MediaWiki\Minerva\Menu\Main
|
||||
*/
|
||||
final class BuilderUtil {
|
||||
/**
|
||||
* Prepares donate group if available
|
||||
* @param Definitions $definitions A menu items definitions set
|
||||
* @return Group|null if not available
|
||||
* @throws FatalError
|
||||
* @throws MWException
|
||||
*/
|
||||
public static function getDonateGroup( Definitions $definitions ) {
|
||||
$group = new Group( 'p-donation' );
|
||||
$definitions->insertDonateItem( $group );
|
||||
return $group->hasEntries() ? $group : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a list of links that have the purpose of discovery in the main navigation menu
|
||||
* @param Definitions $definitions A menu items definitions set
|
||||
|
@ -47,13 +59,6 @@ final class BuilderUtil {
|
|||
$definitions->insertRandomItem( $group );
|
||||
$definitions->insertNearbyIfSupported( $group );
|
||||
|
||||
// Add a donate link (see https://phabricator.wikimedia.org/T219793)
|
||||
$config = MediaWikiServices::getInstance()->getConfigFactory()
|
||||
->makeConfig( 'minerva' );
|
||||
if ( $config->get( 'MinervaDonateLink' ) ) {
|
||||
$definitions->insertDonateItem( $group );
|
||||
}
|
||||
|
||||
// Allow other extensions to add or override tools
|
||||
Hooks::run( 'MobileMenu', [ 'discovery', &$group ] );
|
||||
return $group;
|
||||
|
|
|
@ -37,6 +37,11 @@ final class DefaultMainMenuBuilder implements IMainMenuBuilder {
|
|||
*/
|
||||
private $showMobileOptions;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $showDonateLink;
|
||||
|
||||
/**
|
||||
* Currently logged in user
|
||||
* @var User
|
||||
|
@ -52,11 +57,13 @@ final class DefaultMainMenuBuilder implements IMainMenuBuilder {
|
|||
* Initialize the Default Main Menu builder
|
||||
*
|
||||
* @param bool $showMobileOptions Show MobileOptions instead of Preferences
|
||||
* @param bool $showDonateLink whether to show the donate link
|
||||
* @param User $user The current user
|
||||
* @param Definitions $definitions A menu items definitions set
|
||||
*/
|
||||
public function __construct( $showMobileOptions, User $user, Definitions $definitions ) {
|
||||
public function __construct( $showMobileOptions, $showDonateLink, User $user, Definitions $definitions ) {
|
||||
$this->showMobileOptions = $showMobileOptions;
|
||||
$this->showDonateLink = $showDonateLink;
|
||||
$this->user = $user;
|
||||
$this->definitions = $definitions;
|
||||
}
|
||||
|
@ -67,11 +74,18 @@ final class DefaultMainMenuBuilder implements IMainMenuBuilder {
|
|||
* @throws MWException
|
||||
*/
|
||||
public function getGroups(): array {
|
||||
return [
|
||||
$donate = $this->showDonateLink ?
|
||||
BuilderUtil::getDonateGroup( $this->definitions ) : null;
|
||||
|
||||
$groups = [
|
||||
BuilderUtil::getDiscoveryTools( $this->definitions ),
|
||||
$this->getPersonalTools(),
|
||||
BuilderUtil::getConfigurationTools( $this->definitions, $this->showMobileOptions ),
|
||||
];
|
||||
if ( $donate ) {
|
||||
$groups[] = $donate;
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -110,6 +110,13 @@ class MinervaHooks {
|
|||
$config->get( 'MinervaTalkAtTop' )
|
||||
)
|
||||
);
|
||||
$featureManager->registerFeature(
|
||||
new MobileFrontend\Features\Feature(
|
||||
'MinervaDonateLink',
|
||||
'skin-minerva',
|
||||
$config->get( 'MinervaDonateLink' )
|
||||
)
|
||||
);
|
||||
$featureManager->registerFeature(
|
||||
new MobileFrontend\Features\Feature(
|
||||
'MinervaHistoryInPageActions',
|
||||
|
@ -235,6 +242,7 @@ class MinervaHooks {
|
|||
|
||||
$isBeta = $mobileContext->isBetaGroupMember();
|
||||
$skinOptions->setMultiple( [
|
||||
SkinOptions::SHOW_DONATE => $featureManager->isFeatureAvailableForCurrentUser( 'MinervaDonateLink' ),
|
||||
SkinOptions::TALK_AT_TOP => $isUserPageOrUserTalkPage ?
|
||||
true : $featureManager->isFeatureAvailableForCurrentUser( 'MinervaTalkAtTop' ),
|
||||
SkinOptions::BETA_MODE
|
||||
|
|
|
@ -63,9 +63,11 @@ return [
|
|||
$definitions = $services->getService( 'Minerva.Menu.Definitions' );
|
||||
$showMobileOptions = $options->get( SkinOptions::MOBILE_OPTIONS );
|
||||
$user = $context->getUser();
|
||||
// Add a donate link (see https://phabricator.wikimedia.org/T219793)
|
||||
$showDonateLink = $options->get( SkinOptions::SHOW_DONATE );
|
||||
$builder = $options->get( SkinOptions::MAIN_MENU_EXPANDED ) ?
|
||||
new AdvancedMainMenuBuilder( $showMobileOptions, $user, $definitions ) :
|
||||
new DefaultMainMenuBuilder( $showMobileOptions, $user, $definitions );
|
||||
new AdvancedMainMenuBuilder( $showMobileOptions, $showDonateLink, $user, $definitions ) :
|
||||
new DefaultMainMenuBuilder( $showMobileOptions, $showDonateLink, $user, $definitions );
|
||||
|
||||
return new MainMenuDirector( $builder, $context, $services->getSpecialPageFactory() );
|
||||
},
|
||||
|
|
|
@ -29,6 +29,7 @@ final class SkinOptions {
|
|||
public const PAGE_ISSUES = 'pageIssues';
|
||||
public const BETA_MODE = 'beta';
|
||||
public const TALK_AT_TOP = 'talkAtTop';
|
||||
public const SHOW_DONATE = 'donate';
|
||||
public const HISTORY_IN_PAGE_ACTIONS = 'historyInPageActions';
|
||||
public const TOOLBAR_SUBMENU = 'overflowSubmenu';
|
||||
public const TABS_ON_SPECIALS = 'tabsOnSpecials';
|
||||
|
@ -41,6 +42,7 @@ final class SkinOptions {
|
|||
// overridden on mobile.
|
||||
private $skinOptions = [
|
||||
self::BETA_MODE => false,
|
||||
self::SHOW_DONATE => true,
|
||||
/**
|
||||
* Whether the main menu should include a link to
|
||||
* Special:Preferences of Special:MobileOptions
|
||||
|
|
|
@ -29,7 +29,9 @@
|
|||
"value": false
|
||||
},
|
||||
"MinervaDonateLink": {
|
||||
"value": false
|
||||
"value": {
|
||||
"base": true
|
||||
}
|
||||
},
|
||||
"MinervaDownloadNamespaces": {
|
||||
"value": [
|
||||
|
|
|
@ -118,6 +118,8 @@ class SkinMinervaTest extends MediaWikiTestCase {
|
|||
*/
|
||||
public function testGetContextSpecificModules( $categoryLinks, $moduleName, $expected ) {
|
||||
$this->overrideSkinOptions( [
|
||||
SkinOptions::SHOW_DONATE => false,
|
||||
SkinOptions::TALK_AT_TOP => false,
|
||||
SkinOptions::TALK_AT_TOP => false,
|
||||
SkinOptions::HISTORY_IN_PAGE_ACTIONS => false,
|
||||
SkinOptions::TOOLBAR_SUBMENU => false,
|
||||
|
|
|
@ -37,6 +37,7 @@ class SkinOptionsTest extends \MediaWikiUnitTestCase {
|
|||
$options = new SkinOptions();
|
||||
$this->assertTrue( $options->hasSkinOptions() );
|
||||
$options->setMultiple( [
|
||||
SkinOptions::SHOW_DONATE => false,
|
||||
SkinOptions::TALK_AT_TOP => false,
|
||||
SkinOptions::HISTORY_IN_PAGE_ACTIONS => false,
|
||||
SkinOptions::TOOLBAR_SUBMENU => false,
|
||||
|
|
Loading…
Reference in a new issue