jenkins-bot has submitted this change and it was merged.
Change subject: Feature flag categories
......................................................................
Feature flag categories
The feature is enabled in the beta mode as before.
Also, in order to output the categories button,
make use of the output page categories rather than
generating skin category links. This change should make
the code faster.
Bug: T148195
Change-Id: I8abfd39821743877ec4b834673297bf5330e8d1b
---
M extension.json
M includes/skins/MinervaTemplateBeta.php
M includes/skins/SkinMinerva.php
M includes/skins/SkinMinervaBeta.php
M tests/phpunit/skins/SkinMinervaTest.php
5 files changed, 102 insertions(+), 51 deletions(-)
Approvals:
Pmiazga: Looks good to me, but someone else must approve
Jdlrobson: Looks good to me, approved
Bmansurov: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index ab6658a..0a2a274 100644
--- a/extension.json
+++ b/extension.json
@@ -2030,6 +2030,10 @@
"beta": true,
"base": true
},
+ "MinervaShowCategoriesButton": {
+ "base": false,
+ "beta": true
+ },
"MFStripResponsiveImages": true,
"MFResponsiveImageWhitelist": [
"image/svg+xml"
diff --git a/includes/skins/MinervaTemplateBeta.php
b/includes/skins/MinervaTemplateBeta.php
index 5b32b76..d87322c 100644
--- a/includes/skins/MinervaTemplateBeta.php
+++ b/includes/skins/MinervaTemplateBeta.php
@@ -8,41 +8,4 @@
* beta mode via Special:MobileOptions
*/
class MinervaTemplateBeta extends MinervaTemplate {
- /**
- * Get category button if categories are present
- * @return array A map of the button's friendly name, "categories" to
its
- * spec if the button can be displayed.
- */
- protected function getCategoryButton() {
- $skin = $this->getSkin();
- $categories = $skin->getCategoryLinks( false /* don't render
the heading */ );
-
- if ( !$categories ) {
- return [];
- }
-
- return [
- 'categories' => [
- 'attributes' => [
- 'href' => '#/categories',
- // add hidden class (the overlay works
only, when JS is enabled (class will
- // be removed in categories/init.js)
- 'class' => 'category-button hidden',
- ],
- 'label' => $this->getMsg( 'categories' )->text()
- ],
- ];
- }
-
- /**
- * Get page secondary actions
- *
- * @return array An array of button definitions
- */
- protected function getSecondaryActions() {
- $result = parent::getSecondaryActions();
- $result += $this->getCategoryButton();
-
- return $result;
- }
}
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 24b8c4a..4c6fcfd 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -26,9 +26,10 @@
public $isUserPage = false;
/** @var ContentHandler Content handler of page; only access through
getContentHandler */
protected $contentHandler = null;
-
/** @var bool Whether the page is also available in other languages or
variants */
protected $doesPageHaveLanguages = false;
+ /** @var bool Whether to show the categories button on the page */
+ protected $shouldShowCategoriesButton = false;
/**
* Wrapper for MobileContext::getMFConfig()
@@ -272,6 +273,18 @@
}
/**
+ * Whether the output page contains category links
+ * @return bool
+ */
+ private function hasCategoryLinks() {
+ $categoryLinks = $this->getOutput()->getCategoryLinks();
+ if ( !count( $categoryLinks ) ) {
+ return false;
+ }
+ return !empty( $categoryLinks['normal'] ) || !empty(
$categoryLinks['hidden'] );
+ }
+
+ /**
* Initiate class
*/
public function __construct() {
@@ -285,6 +298,8 @@
$this->isUserPage = true;
}
}
+ $this->shouldShowCategoriesButton =
$this->mobileContext->getConfigVariable(
+ 'MinervaShowCategoriesButton' ) &&
$this->hasCategoryLinks();
}
/**
@@ -933,6 +948,22 @@
}
/**
+ * Returns an array with details for a categories button.
+ * @return array
+ */
+ protected function getCategoryButton() {
+ return [
+ 'attributes' => [
+ 'href' => '#/categories',
+ // add hidden class (the overlay works only,
when JS is enabled (class will
+ // be removed in categories/init.js)
+ 'class' => 'category-button hidden',
+ ],
+ 'label' => $this->msg( 'categories' )->text()
+ ];
+ }
+
+ /**
* Returns an array of links for page secondary actions
* @param BaseTemplate $tpl
* @return string[]
@@ -958,6 +989,10 @@
if ( $this->doesPageHaveLanguages && $title->isMainPage() ) {
$buttons['language'] = $this->getLanguageButton();
+ }
+
+ if ( $this->shouldShowCategoriesButton ) {
+ $buttons['categories'] = $this->getCategoryButton();
}
return $buttons;
@@ -1230,6 +1265,10 @@
$modules[] = 'skins.minerva.talk';
}
+ if ( $this->shouldShowCategoriesButton ) {
+ $modules[] = 'skins.minerva.categories';
+ }
+
return $modules;
}
diff --git a/includes/skins/SkinMinervaBeta.php
b/includes/skins/SkinMinervaBeta.php
index 1782962..c35d88e 100644
--- a/includes/skins/SkinMinervaBeta.php
+++ b/includes/skins/SkinMinervaBeta.php
@@ -14,19 +14,6 @@
protected $mode = 'beta';
/**
- * Returns an array of modules related to the current context of the
page.
- * @return array
- */
- public function getContextSpecificModules() {
- $modules = parent::getContextSpecificModules();
- if ( $this->getCategoryLinks( false ) ) {
- $modules[] = 'skins.minerva.categories';
- }
-
- return $modules;
- }
-
- /**
* Returns the javascript modules to load.
* @return array
*/
diff --git a/tests/phpunit/skins/SkinMinervaTest.php
b/tests/phpunit/skins/SkinMinervaTest.php
index 28e56eb..e00a315 100644
--- a/tests/phpunit/skins/SkinMinervaTest.php
+++ b/tests/phpunit/skins/SkinMinervaTest.php
@@ -4,7 +4,9 @@
use MediaWikiTestCase;
use MobileContext;
+use OutputPage;
use SkinMinerva;
+use TestingAccessWrapper;
class TestSkinMinerva extends SkinMinerva {
@@ -21,6 +23,7 @@
}
/**
+ * @covers SkinMinerva
* @group MobileFrontend
*/
class SkinMinervaTest extends MediaWikiTestCase {
@@ -65,4 +68,59 @@
private function factorySkin( MobileContext $context ) {
return new TestSkinMinerva( $context );
}
+
+ /**
+ * @dataProvider provideHasCategoryLinks
+ * @param array $categoryLinks
+ * @param bool $expected
+ */
+ public function testHasCategoryLinks( array $categoryLinks, $expected )
{
+ $outputPage = $this->getMockBuilder( OutputPage::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $outputPage->expects( $this->once() )
+ ->method( 'getCategoryLinks' )
+ ->will( $this->returnValue( $categoryLinks ) );
+
+ $skin = TestingAccessWrapper::newFromObject(
+ $this->getMockBuilder( SkinMinerva::class )
+ ->disableOriginalConstructor()
+ ->getMock()
+ );
+ $skin->expects( $this->once() )
+ ->method( 'getOutput' )
+ ->will( $this->returnValue( $outputPage ) );
+ $this->assertEquals( $skin->hasCategoryLinks(), $expected );
+ }
+
+ public function provideHasCategoryLinks() {
+ return [
+ [ [], false ],
+ [
+ [
+ 'normal' => '<ul><li><a
href="/wiki/Category:1">1</a></li></ul>'
+ ],
+ true
+ ],
+ [
+ [
+ 'hidden' => '<ul><li><a
href="/wiki/Category:Hidden">Hidden</a></li></ul>'
+ ],
+ true
+ ],
+ [
+ [
+ 'normal' => '<ul><li><a
href="/wiki/Category:1">1</a></li></ul>',
+ 'hidden' => '<ul><li><a
href="/wiki/Category:Hidden">Hidden</a></li></ul>'
+ ],
+ true
+ ],
+ [
+ [
+ 'unexpected' => '<ul><li><a
href="/wiki/Category:1">1</a></li></ul>'
+ ],
+ false
+ ],
+ ];
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/322967
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8abfd39821743877ec4b834673297bf5330e8d1b
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Pmiazga <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits