Adrian Lang has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/180134

Change subject: Inject settings into SiteLinksView
......................................................................

Inject settings into SiteLinksView

Change-Id: I7d735abe79462f5ce835ed39055f7e42c58a7664
---
M repo/includes/View/EntityViewFactory.php
M repo/includes/View/SiteLinksView.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
M repo/tests/phpunit/includes/View/SiteLinksViewTest.php
5 files changed, 38 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/34/180134/1

diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
index 46fceda..803f229 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -54,6 +54,16 @@
        private $siteLinkGroups;
 
        /**
+        * @var string[]
+        */
+       private $specialSiteLinkGroups;
+
+       /**
+        * @var array
+        */
+       private $badgeItems;
+
+       /**
         * @param EntityIdFormatterFactory $idFormatterFactory
         * @param OutputFormatSnakFormatterFactory $snakFormatterFactory
         * @param EntityLookup $entityLookup
@@ -64,7 +74,9 @@
                OutputFormatSnakFormatterFactory $snakFormatterFactory,
                EntityLookup $entityLookup,
                SiteStore $siteStore,
-               array $siteLinkGroups
+               array $siteLinkGroups,
+               array $specialSiteLinkGroups,
+               array $badgeItems
        ) {
                $this->checkOutputFormat( 
$idFormatterFactory->getOutputFormat() );
 
@@ -74,6 +86,8 @@
                $this->entityLookup = $entityLookup;
                $this->siteStore = $siteStore;
                $this->siteLinkGroups = $siteLinkGroups;
+               $this->specialSiteLinkGroups = $specialSiteLinkGroups;
+               $this->badgeItems = $badgeItems;
        }
 
        /**
@@ -120,6 +134,8 @@
                                        $this->siteStore->getSites(),
                                        $this->sectionEditLinkGenerator,
                                        $this->entityLookup,
+                                       $this->badgeItems,
+                                       $this->specialSiteLinkGroups,
                                        $language->getCode()
                                );
 
diff --git a/repo/includes/View/SiteLinksView.php 
b/repo/includes/View/SiteLinksView.php
index d158e46..ae1a932 100644
--- a/repo/includes/View/SiteLinksView.php
+++ b/repo/includes/View/SiteLinksView.php
@@ -11,7 +11,6 @@
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\SiteLink;
 use Wikibase\Lib\Store\EntityLookup;
-use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Utils;
 
 /**
@@ -55,17 +54,20 @@
         */
        private $badgeItems;
 
-       public function __construct( SiteList $sites, SectionEditLinkGenerator 
$sectionEditLinkGenerator,
-                       EntityLookup $entityLookup, $languageCode ) {
+       public function __construct(
+               SiteList $sites,
+               SectionEditLinkGenerator $sectionEditLinkGenerator,
+               EntityLookup $entityLookup,
+               array $badgeItems,
+               array $specialSiteLinkGroups,
+               $languageCode
+       ) {
                $this->sites = $sites;
                $this->sectionEditLinkGenerator = $sectionEditLinkGenerator;
                $this->entityLookup = $entityLookup;
+               $this->badgeItems = $badgeItems;
+               $this->specialSiteLinkGroups = $specialSiteLinkGroups;
                $this->languageCode = $languageCode;
-
-               // @todo inject option/objects instead of using the singleton
-               $settings = WikibaseRepo::getDefaultInstance()->getSettings();
-               $this->specialSiteLinkGroups = $settings->getSetting( 
'specialSiteLinkGroups' );
-               $this->badgeItems = $settings->getSetting( 'badgeItems' );
        }
 
        /**
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 1bbc910..9c4d948 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -993,7 +993,9 @@
                        $this->getSnakFormatterFactory(),
                        $this->getEntityLookup(),
                        $this->getSiteStore(),
-                       $this->getSettings()->getSetting( 'siteLinkGroups' )
+                       $this->getSettings()->getSetting( 'siteLinkGroups' ),
+                       $this->getSettings()->getSetting( 
'specialSiteLinkGroups' ),
+                       $this->getSettings()->getSetting( 'badgeItems' )
                );
 
                return new EntityParserOutputGeneratorFactory(
diff --git a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php 
b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
index 095fe07..135e3f2 100644
--- a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
+++ b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
@@ -61,6 +61,8 @@
                        $this->getSnakFormatterFactory(),
                        $this->getMock( 'Wikibase\Lib\Store\EntityLookup' ),
                        $this->getSiteStore(),
+                       array(),
+                       array(),
                        array()
                );
        }
diff --git a/repo/tests/phpunit/includes/View/SiteLinksViewTest.php 
b/repo/tests/phpunit/includes/View/SiteLinksViewTest.php
index ee08ee6..670ddf7 100644
--- a/repo/tests/phpunit/includes/View/SiteLinksViewTest.php
+++ b/repo/tests/phpunit/includes/View/SiteLinksViewTest.php
@@ -26,32 +26,6 @@
  */
 class SiteLinksViewTest extends \PHPUnit_Framework_TestCase {
 
-       private $settings = array(
-               'specialSiteLinkGroups' => array( 'special group' ),
-               'badgeItems' => array(
-                       'Q42' => 'wb-badge-featuredarticle',
-                       'Q12' => 'wb-badge-goodarticle'
-               )
-       );
-
-       protected function setUp() {
-               parent::setUp();
-               $this->switchSettings();
-       }
-
-       protected function tearDown() {
-               parent::tearDown();
-               $this->switchSettings();
-       }
-
-       private function switchSettings() {
-               $settings = WikibaseRepo::getDefaultInstance()->getSettings();
-               foreach ( $this->settings as $name => $value ) {
-                       $this->settings[$name] = $settings->getSetting( $name );
-                       $settings->setSetting( $name, $value );
-               }
-       }
-
        /**
         * @dataProvider getHtmlProvider
         */
@@ -213,10 +187,16 @@
         * @return SiteLinksView
         */
        private function getSiteLinksView() {
+
                return new SiteLinksView(
                        $this->newSiteList(),
                        $this->getSectionEditLinkGeneratorMock(),
                        $this->getEntityLookupMock(),
+                       array(
+                               'Q42' => 'wb-badge-featuredarticle',
+                               'Q12' => 'wb-badge-goodarticle'
+                       ),
+                       array( 'special group' ),
                        'en'
                );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/180134
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7d735abe79462f5ce835ed39055f7e42c58a7664
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to