From a2fd0b3c1fb6006022c4b3d6bebc1d3d783cad8c Mon Sep 17 00:00:00 2001 From: Alangi Derick Date: Sun, 21 Oct 2018 16:10:41 +0100 Subject: [PATCH] Add "Discussion" button to Main page on Mobile View * Enable discussion button on main page in mobile view so users can view discussion topics related to the main page on mobile. * Update test to make sure only 'talk' and 'switch-language' actions are enabled on the main page and 'edit' and 'watch' are disabled on the main page. * Minor typo fix for doc type. Use "array" instead of "Array" and CSS alignment fix issue with Discussion button when displayed together with Language selector button. * [Suggested by: @Jdlrobson] Use a generic "a" CSS selector to style the ".talk" and ".language-selector" classes on the main page. This also avoids fixing the CSS for future buttons if added (future proofing the code), so if any other button is added in the future, the same css rule will be applied to it at once. Very wise idea from @Jdlrobson, thanks! Bug: T206406 Change-Id: Iedce84595adc357f3a707f8b94d23b2ffea3476c --- includes/skins/SkinMinerva.php | 12 +++++++++--- resources/skins.minerva.mainPage.styles/common.less | 2 +- tests/phpunit/skins/SkinMinervaPageActionsTest.php | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php index 9f21c02..f9cc4d3 100644 --- a/includes/skins/SkinMinerva.php +++ b/includes/skins/SkinMinerva.php @@ -242,9 +242,15 @@ class SkinMinerva extends SkinTemplate { return false; } + // T206406: Enable "Talk" or "Discussion" button on Main page, also, not forgetting + // the "switch-language" button. But disable "edit" and "watch" actions. + if ( $title->isMainPage() ) { + return ( in_array( $action, $config->get( 'MinervaPageActions' ) ) + && ( $action === 'talk' || $action === 'switch-language' ) ); + } + if ( ! in_array( $action, $config->get( 'MinervaPageActions' ) ) - || $title->isMainPage() || ( $this->getUserPageHelper()->isUserPage() && !$title->exists() ) ) { return false; @@ -270,7 +276,7 @@ class SkinMinerva extends SkinTemplate { * @return string */ public function doEditSectionLink( Title $nt, $section, $tooltip, Language $lang ) { - if ( $this->isAllowedPageAction( 'edit' ) ) { + if ( $this->isAllowedPageAction( 'edit' ) && !$nt->isMainPage() ) { $message = $this->msg( 'mobile-frontend-editor-edit' )->inLanguage( $lang )->text(); $html = Html::openElement( 'span', [ 'class' => 'mw-editsection' ] ); $html .= Html::element( 'a', [ @@ -980,7 +986,7 @@ class SkinMinerva extends SkinTemplate { /** * Returns an array of sitelinks to add into the main menu footer. - * @return Array array of site links + * @return array Array of site links */ protected function getSiteLinks() { $menu = new MenuBuilder(); diff --git a/resources/skins.minerva.mainPage.styles/common.less b/resources/skins.minerva.mainPage.styles/common.less index ed8d895..06406c5 100644 --- a/resources/skins.minerva.mainPage.styles/common.less +++ b/resources/skins.minerva.mainPage.styles/common.less @@ -18,7 +18,7 @@ } #page-secondary-actions { - .language-selector { + a { margin-top: 1em; } } diff --git a/tests/phpunit/skins/SkinMinervaPageActionsTest.php b/tests/phpunit/skins/SkinMinervaPageActionsTest.php index 4582cfa..ccdfb3e 100644 --- a/tests/phpunit/skins/SkinMinervaPageActionsTest.php +++ b/tests/phpunit/skins/SkinMinervaPageActionsTest.php @@ -66,6 +66,11 @@ class SkinMinervaPageActionsTest extends MediaWikiTestCase { $skin = $this->getSkin( Title::newMainPage() ); $this->assertFalse( $skin->isAllowedPageAction( 'watch' ) ); + $this->assertFalse( $skin->isAllowedPageAction( 'edit' ) ); + + // Check to make sure 'talk' and 'switch-language' are enabled on the Main page. + $this->assertTrue( $skin->isAllowedPageAction( 'talk' ) ); + $this->assertTrue( $skin->isAllowedPageAction( 'switch-language' ) ); } /**