jenkins-bot has submitted this change and it was merged.

Change subject: Inject SiteLinksView into ItemView
......................................................................


Inject SiteLinksView into ItemView

Change-Id: I2a5bf0b8538655d1b71521760968e91d8d7cc441
---
M repo/includes/View/EntityViewFactory.php
M repo/includes/View/ItemView.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
M repo/tests/phpunit/includes/View/ItemViewTest.php
5 files changed, 64 insertions(+), 19 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
index 6467dfb..46fceda 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -4,11 +4,13 @@
 
 use InvalidArgumentException;
 use Language;
+use SiteStore;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatter;
 use Wikibase\LanguageFallbackChain;
 use Wikibase\Lib\EntityIdFormatter;
 use Wikibase\Lib\EntityIdFormatterFactory;
+use Wikibase\Lib\Store\EntityLookup;
 use Wikibase\Lib\OutputFormatSnakFormatterFactory;
 use Wikibase\Lib\SnakFormatter;
 use Wikibase\Lib\Store\LabelLookup;
@@ -37,17 +39,31 @@
        private $idFormatterFactory;
 
        /**
-        * @param EntityIdFormatterFactory $idFormatterFactory
-        * @param OutputFormatSnakFormatterFactory $snakFormatterFactory
+        * @var EntityLookup
         */
+       private $entityLookup;
+
+       /**
+        * @var SiteStore
+        */
+       private $siteStore;
+
        /**
         * @var string[]
         */
        private $siteLinkGroups;
 
+       /**
+        * @param EntityIdFormatterFactory $idFormatterFactory
+        * @param OutputFormatSnakFormatterFactory $snakFormatterFactory
+        * @param EntityLookup $entityLookup
+        * @param SiteStore $siteStore
+        */
        public function __construct(
                EntityIdFormatterFactory $idFormatterFactory,
                OutputFormatSnakFormatterFactory $snakFormatterFactory,
+               EntityLookup $entityLookup,
+               SiteStore $siteStore,
                array $siteLinkGroups
        ) {
                $this->checkOutputFormat( 
$idFormatterFactory->getOutputFormat() );
@@ -55,6 +71,8 @@
                $this->idFormatterFactory = $idFormatterFactory;
                $this->snakFormatterFactory = $snakFormatterFactory;
                $this->sectionEditLinkGenerator = new 
SectionEditLinkGenerator();
+               $this->entityLookup = $entityLookup;
+               $this->siteStore = $siteStore;
                $this->siteLinkGroups = $siteLinkGroups;
        }
 
@@ -98,7 +116,21 @@
                // @fixme support more entity types
                switch ( $entityType ) {
                        case 'item':
-                               return new ItemView( $fingerprintView, 
$claimsView, $language, $this->siteLinkGroups, $editable );
+                               $siteLinksView = new SiteLinksView(
+                                       $this->siteStore->getSites(),
+                                       $this->sectionEditLinkGenerator,
+                                       $this->entityLookup,
+                                       $language->getCode()
+                               );
+
+                               return new ItemView(
+                                       $fingerprintView,
+                                       $claimsView,
+                                       $language,
+                                       $siteLinksView,
+                                       $this->siteLinkGroups,
+                                       $editable
+                               );
                        case 'property':
                                return new PropertyView( $fingerprintView, 
$claimsView, $language, $editable );
                }
diff --git a/repo/includes/View/ItemView.php b/repo/includes/View/ItemView.php
index 96f8620..907f578 100644
--- a/repo/includes/View/ItemView.php
+++ b/repo/includes/View/ItemView.php
@@ -6,7 +6,6 @@
 use Language;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\EntityRevision;
-use Wikibase\Repo\WikibaseRepo;
 
 /**
  * Class for creating views for Item instances.
@@ -26,11 +25,17 @@
        private $siteLinkGroups;
 
        /**
+        * @var SiteLinksView
+        */
+       private $siteLinksView;
+
+       /**
         * @see EntityView::__construct
         *
         * @param FingerprintView $fingerprintView
         * @param ClaimsView $claimsView
         * @param Language $language
+        * @param SiteLinksView $siteLinksView
         * @param string[] $siteLinkGroups
         * @param bool $editable
         */
@@ -38,12 +43,14 @@
                FingerprintView $fingerprintView,
                ClaimsView $claimsView,
                Language $language,
+               SiteLinksView $siteLinksView,
                array $siteLinkGroups,
-               $editable  = true
+               $editable = true
        ) {
                parent::__construct( $fingerprintView, $claimsView, $language, 
$editable );
 
                $this->siteLinkGroups = $siteLinkGroups;
+               $this->siteLinksView = $siteLinksView;
        }
 
        /**
@@ -95,21 +102,9 @@
         * @return string
         */
        protected function getHtmlForSiteLinks( Item $item ) {
-               $wikibaseRepo = WikibaseRepo::getDefaultInstance();
-
-               // FIXME: Inject this
-               $siteLinksView = new SiteLinksView(
-                       $wikibaseRepo->getSiteStore()->getSites(),
-                       new SectionEditLinkGenerator(),
-                       $wikibaseRepo->getEntityLookup(),
-                       $this->language->getCode()
-               );
-
-               $itemId = $item->getId();
-
-               return $siteLinksView->getHtml(
+               return $this->siteLinksView->getHtml(
                        $item->getSiteLinks(),
-                       $itemId,
+                       $item->getId(),
                        $this->siteLinkGroups,
                        $this->editable
                );
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 68ad994..1bbc910 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -991,6 +991,8 @@
                $entityViewFactory = new EntityViewFactory(
                        $this->getEntityIdHtmlLinkFormatter(),
                        $this->getSnakFormatterFactory(),
+                       $this->getEntityLookup(),
+                       $this->getSiteStore(),
                        $this->getSettings()->getSetting( 'siteLinkGroups' )
                );
 
diff --git a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php 
b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
index 309c699..095fe07 100644
--- a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
+++ b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Test;
 
+use SiteList;
 use Wikibase\LanguageFallbackChain;
 use Wikibase\Lib\EntityIdHtmlLinkFormatterFactory;
 use Wikibase\Lib\SnakFormatter;
@@ -58,6 +59,8 @@
                return new EntityViewFactory(
                        $this->getEntityIdFormatterFactory(),
                        $this->getSnakFormatterFactory(),
+                       $this->getMock( 'Wikibase\Lib\Store\EntityLookup' ),
+                       $this->getSiteStore(),
                        array()
                );
        }
@@ -96,4 +99,14 @@
                return $snakFormatterFactory;
        }
 
+       private function getSiteStore() {
+               $siteStore = $this->getMock( 'SiteStore' );
+
+               $siteStore->expects( $this->any() )
+                       ->method( 'getSites' )
+                       ->will( $this->returnValue( new SiteList() ) );
+
+               return $siteStore;
+       }
+
 }
diff --git a/repo/tests/phpunit/includes/View/ItemViewTest.php 
b/repo/tests/phpunit/includes/View/ItemViewTest.php
index 1c2738c..a33c2c0 100644
--- a/repo/tests/phpunit/includes/View/ItemViewTest.php
+++ b/repo/tests/phpunit/includes/View/ItemViewTest.php
@@ -55,6 +55,9 @@
                                ->disableOriginalConstructor()
                                ->getMock(),
                        $this->getMock( 'Language' ),
+                       $this->getMockBuilder( 
'Wikibase\Repo\View\SiteLinksView' )
+                               ->disableOriginalConstructor()
+                               ->getMock(),
                        array()
                );
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2a5bf0b8538655d1b71521760968e91d8d7cc441
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to