From bb0071383a3061927951fdb8fe49227dc6dfe3e9 Mon Sep 17 00:00:00 2001 From: Piotr Miazga Date: Fri, 21 Jun 2019 17:46:44 +0200 Subject: [PATCH] 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 --- .../permissions/MinervaPagePermissions.php | 14 ++++++++++-- .../MinervaPagePermissionsTest.php | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/includes/permissions/MinervaPagePermissions.php b/includes/permissions/MinervaPagePermissions.php index 3908216..a978d0b 100644 --- a/includes/permissions/MinervaPagePermissions.php +++ b/includes/permissions/MinervaPagePermissions.php @@ -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() ); diff --git a/tests/phpunit/permissions/MinervaPagePermissionsTest.php b/tests/phpunit/permissions/MinervaPagePermissionsTest.php index 0e7c072..04d058f 100644 --- a/tests/phpunit/permissions/MinervaPagePermissionsTest.php +++ b/tests/phpunit/permissions/MinervaPagePermissionsTest.php @@ -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 $wgMinervaAlwaysShowLanguageButton