Settings link is hidden to non-JS users when beta and AMC unavailable

Bug: T198265
Change-Id: I6340da6dbbd031d8c91ae99801065bafe9245920
This commit is contained in:
jdlrobson 2020-01-07 12:29:35 -08:00 committed by Jdlrobson
parent 3ec0ca1e6e
commit da5798ef22
2 changed files with 31 additions and 3 deletions

View file

@ -207,14 +207,31 @@ final class Definitions {
*/ */
public function insertMobileOptionsItem( Group $group ) { public function insertMobileOptionsItem( Group $group ) {
$title = $this->context->getTitle(); $title = $this->context->getTitle();
$config = $this->context->getConfig();
$returnToTitle = $title->getPrefixedText(); $returnToTitle = $title->getPrefixedText();
$user = $this->user;
$betaEnabled = $config->get( 'MFEnableBeta' );
/*
* to avoid linking to an empty settings page we make this jsonly when:
* - AMC and beta is disabled (if logged in there is nothing to show)
* - user is logged out and beta is disabled (beta is the only thing a non-js user can do)
* In future we might want to make this a static function on Special:MobileOptions.
*/
$jsonly = ( $user->isAnon() && !$betaEnabled ) ||
( !$user->isAnon() && !$config->get( 'MFAdvancedMobileContributions' ) &&
!$betaEnabled
);
$group->insertEntry( SingleMenuEntry::create( $item = SingleMenuEntry::create(
'settings', 'settings',
$this->context->msg( 'mobile-frontend-main-menu-settings' )->escaped(), $this->context->msg( 'mobile-frontend-main-menu-settings' )->escaped(),
SpecialPage::getTitleFor( 'MobileOptions' ) SpecialPage::getTitleFor( 'MobileOptions' )
->getLocalURL( [ 'returnto' => $returnToTitle ] ) ->getLocalURL( [ 'returnto' => $returnToTitle ] )
) ); );
if ( $jsonly ) {
$item->setJSOnly();
}
$group->insertEntry( $item );
} }
/** /**

View file

@ -32,6 +32,10 @@ class SingleMenuEntry implements IMenuEntry {
* @var array * @var array
*/ */
private $attributes; private $attributes;
/**
* @var bool
*/
private $isJSOnly;
/** /**
* Create a simple menu element with one component * Create a simple menu element with one component
@ -82,7 +86,7 @@ class SingleMenuEntry implements IMenuEntry {
* @inheritDoc * @inheritDoc
*/ */
public function getCSSClasses(): array { public function getCSSClasses(): array {
return []; return $this->isJSOnly ? [ 'jsonly' ] : [];
} }
/** /**
@ -135,4 +139,11 @@ class SingleMenuEntry implements IMenuEntry {
return $this; return $this;
} }
/**
* Mark entry as JS only.
*/
public function setJSOnly() {
$this->isJSOnly = true;
}
} }