MinervaPermissions must respect $wgHideInterlanguageLinks config

MediaWiki Core defined $wgHideInterlanguageLinks that can be used to
disable the interwiki links. Minerva skin should respect this config,
furthermore, this config should take precedence over the Minerva's
$wgMinervaAlwaysShowLanguageButton config.

Bug: T214540
Bug: T221792
Change-Id: Id4fe8b67a17f9c28c00a8a3a207946e146502cde
This commit is contained in:
Piotr Miazga 2019-06-21 17:46:44 +02:00 committed by Pmiazga
parent 8c7553935e
commit bb0071383a
2 changed files with 34 additions and 2 deletions

View File

@ -108,11 +108,18 @@ final class MinervaPagePermissions implements IMinervaPagePermissions {
* @throws ConfigException
*/
public function isAllowed( $action ) {
global $wgHideInterlanguageLinks;
// T206406: Enable "Talk" or "Discussion" button on Main page, also, not forgetting
// the "switch-language" button. But disable "edit" and "watch" actions.
if ( $this->title->isMainPage() ) {
return ( in_array( $action, $this->config->get( 'MinervaPageActions' ) )
&& ( $action === self::TALK || $action === self::SWITCH_LANGUAGE ) );
if ( !in_array( $action, $this->config->get( 'MinervaPageActions' ) ) ) {
return false;
}
if ( $action === self::SWITCH_LANGUAGE ) {
return !$wgHideInterlanguageLinks;
}
return $action === self::TALK;
}
if ( $action === self::HISTORY && $this->title->exists() ) {
@ -138,6 +145,9 @@ final class MinervaPagePermissions implements IMinervaPagePermissions {
}
if ( $action === self::SWITCH_LANGUAGE ) {
if ( $wgHideInterlanguageLinks ) {
return false;
}
$hasVariants = $this->title->getPageLanguage()->hasVariants();
$hasLanguages = count( $this->output->getLanguageLinks() );

View File

@ -151,6 +151,28 @@ class MinervaPagePermissionsTest extends MediaWikiTestCase {
];
}
/**
* MediaWiki defines wgHideInterlanguageLinks which is default set to false, but some wikis
* can set this config to true. Minerva page permissions must respect that
* @covers ::isAllowed
*/
public function testGlobalHideLanguageLinksTakesPrecedenceOnMainPage() {
$this->setMwGlobals( [ 'wgHideInterlanguageLinks' => true ] );
$perms = $this->buildPermissionsObject( Title::newMainPage() );
$this->assertFalse( $perms->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) );
}
/**
* MediaWiki defines wgHideInterlanguageLinks which is default set to false, but some wikis
* can set this config to true. Minerva page permissions must respect that
* @covers ::isAllowed
*/
public function testGlobalHideLanguageLinksTakesPrecedence() {
$this->setMwGlobals( [ 'wgHideInterlanguageLinks' => true ] );
$perms = $this->buildPermissionsObject( Title::newFromText( 'test' ) );
$this->assertFalse( $perms->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) );
}
/**
* The "switch-language" page action is allowed when: v2 of the page action bar is enabled and
* if the page has interlanguage links or if the <code>$wgMinervaAlwaysShowLanguageButton</code>