Adrian Lang has uploaded a new change for review.

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

Change subject: Pass EditSectionGenerator to EntityViewFactory
......................................................................

Pass EditSectionGenerator to EntityViewFactory

This is a prerequisite for T93745. EntityViewFactory is part of WikibaseView,
but it currently references RepoSpecialPageLinker, which is part of
WikibaseRepo.

Change-Id: I4bd4bfb3fde415b815a3daa16e28d967954af346
---
M repo/includes/EntityParserOutputGenerator.php
M repo/includes/EntityParserOutputGeneratorFactory.php
M repo/includes/View/EntityViewFactory.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php
M repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
6 files changed, 48 insertions(+), 19 deletions(-)


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

diff --git a/repo/includes/EntityParserOutputGenerator.php 
b/repo/includes/EntityParserOutputGenerator.php
index 279d942..5e2f424 100644
--- a/repo/includes/EntityParserOutputGenerator.php
+++ b/repo/includes/EntityParserOutputGenerator.php
@@ -20,7 +20,11 @@
 use Wikibase\Lib\Store\EntityInfoTermLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Lib\Store\LanguageFallbackLabelLookup;
+use Wikibase\Repo\View\EmptyEditSectionGenerator;
 use Wikibase\Repo\View\EntityViewFactory;
+use Wikibase\Repo\View\RepoSpecialPageLinker;
+use Wikibase\Repo\View\ToolbarEditSectionGenerator;
+use Wikibase\Template\TemplateFactory;
 
 /**
  * Creates the parser output for an entity.
@@ -76,6 +80,11 @@
         */
        private $referencedEntitiesFinder;
 
+       /**
+        * @var TemplateFactory
+        */
+       private $templateFactory;
+
        public function __construct(
                EntityViewFactory $entityViewFactory,
                ParserOutputJsConfigBuilder $configBuilder,
@@ -83,7 +92,8 @@
                ValuesFinder $valuesFinder,
                EntityInfoBuilderFactory $entityInfoBuilderFactory,
                LanguageFallbackChain $languageFallbackChain,
-               $languageCode
+               $languageCode,
+               TemplateFactory $templateFactory
        ) {
                $this->entityViewFactory = $entityViewFactory;
                $this->configBuilder = $configBuilder;
@@ -94,6 +104,7 @@
                $this->languageCode = $languageCode;
 
                $this->referencedEntitiesFinder = new 
ReferencedEntitiesFinder();
+               $this->templateFactory = $templateFactory;
        }
 
        /**
@@ -312,7 +323,7 @@
        /**
         * @param ParserOutput $parserOutput
         * @param EntityRevision $entityRevision
-        * @param EntityInfo $entityInfo obtained from 
EntityInfoBuilder::getEntityInfo
+        * @param EntityInfo $entityInfo
         * @param bool $editable
         */
        private function addHtmlToParserOutput(
@@ -327,12 +338,17 @@
                        $this->languageFallbackChain
                );
 
+               $editSectionGenerator = $editable ? new 
ToolbarEditSectionGenerator(
+                       new RepoSpecialPageLinker(),
+                       $this->templateFactory
+               ) : new EmptyEditSectionGenerator();
+
                $entityView = $this->entityViewFactory->newEntityView(
                        $entityRevision->getEntity()->getType(),
                        $this->languageCode,
                        $labelLookup,
                        $this->languageFallbackChain,
-                       $editable
+                       $editSectionGenerator
                );
 
                $html = $entityView->getHtml( $entityRevision );
diff --git a/repo/includes/EntityParserOutputGeneratorFactory.php 
b/repo/includes/EntityParserOutputGeneratorFactory.php
index e113b72..de2f03f 100644
--- a/repo/includes/EntityParserOutputGeneratorFactory.php
+++ b/repo/includes/EntityParserOutputGeneratorFactory.php
@@ -3,13 +3,13 @@
 namespace Wikibase;
 
 use ParserOptions;
-use RequestContext;
 use ValueFormatters\ValueFormatter;
 use Wikibase\DataModel\Entity\EntityIdParser;
 use Wikibase\Lib\Serializers\SerializationOptions;
 use Wikibase\Lib\Store\EntityInfoBuilderFactory;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Repo\View\EntityViewFactory;
+use Wikibase\Template\TemplateFactory;
 
 /**
  * @since 0.5
@@ -18,6 +18,11 @@
  * @author Katie Filbert < aude.w...@gmail.com >
  */
 class EntityParserOutputGeneratorFactory {
+
+       /**
+        * @var TemplateFactory
+        */
+       private $templateFactory;
 
        /**
         * @var EntityViewFactory
@@ -55,7 +60,8 @@
                EntityTitleLookup $entityTitleLookup,
                EntityIdParser $entityIdParser,
                ValuesFinder $valuesFinder,
-               LanguageFallbackChainFactory $languageFallbackChainFactory
+               LanguageFallbackChainFactory $languageFallbackChainFactory,
+               TemplateFactory $templateFactory
        ) {
                $this->entityViewFactory = $entityViewFactory;
                $this->entityInfoBuilderFactory = $entityInfoBuilderFactory;
@@ -63,6 +69,7 @@
                $this->entityIdParser = $entityIdParser;
                $this->valuesFinder = $valuesFinder;
                $this->languageFallbackChainFactory = 
$languageFallbackChainFactory;
+               $this->templateFactory = $templateFactory;
        }
 
        /**
@@ -82,7 +89,8 @@
                        $this->valuesFinder,
                        $this->entityInfoBuilderFactory,
                        $this->getLanguageFallbackChain( $languageCode ),
-                       $languageCode
+                       $languageCode,
+                       $this->templateFactory
                );
        }
 
diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
index c46b6cc..084d327 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -133,7 +133,7 @@
         * @param string $languageCode
         * @param LabelLookup $labelLookup
         * @param LanguageFallbackChain $fallbackChain
-        * @param bool $editable
+        * @param EditSectionGenerator $editSectionGenerator
         *
         * @throws InvalidArgumentException
         * @return EntityView
@@ -143,12 +143,9 @@
                $languageCode,
                LabelLookup $labelLookup,
                LanguageFallbackChain $fallbackChain,
-               $editable = true
+               EditSectionGenerator $editSectionGenerator
         ) {
-               $editSectionGenerator = $editable ? new 
ToolbarEditSectionGenerator(
-                       new RepoSpecialPageLinker(),
-                       $this->templateFactory
-               ) : new EmptyEditSectionGenerator();
+
                $entityTermsView = $this->newEntityTermsView( $languageCode, 
$editSectionGenerator );
                $statementGroupListView = $this->newStatementGroupListView(
                        $languageCode,
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 0b31fd2..f52297a 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1011,6 +1011,7 @@
         * @return EntityParserOutputGeneratorFactory
         */
        public function getEntityParserOutputGeneratorFactory() {
+               $templateFactory = new TemplateFactory( 
TemplateRegistry::getDefaultInstance() );
 
                $entityViewFactory = new EntityViewFactory(
                        $this->getEntityIdHtmlLinkFormatterFactory(),
@@ -1018,7 +1019,7 @@
                        $this->getEntityLookup(),
                        $this->getSiteStore(),
                        $this->getDataTypeFactory(),
-                       new TemplateFactory( 
TemplateRegistry::getDefaultInstance() ),
+                       $templateFactory,
                        new LanguageNameLookup(),
                        $this->getSettings()->getSetting( 'siteLinkGroups' ),
                        $this->getSettings()->getSetting( 
'specialSiteLinkGroups' ),
@@ -1031,7 +1032,8 @@
                        $this->getEntityContentFactory(),
                        $this->getEntityIdParser(),
                        new ValuesFinder( $this->getPropertyDataTypeLookup() ),
-                       $this->getLanguageFallbackChainFactory()
+                       $this->getLanguageFallbackChainFactory(),
+                       $templateFactory
                );
        }
 
diff --git a/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php 
b/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php
index 8f6d202..6fc6326 100644
--- a/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php
+++ b/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php
@@ -3,8 +3,9 @@
 namespace Wikibase\Test;
 
 use DataValues\StringValue;
-use ParserOptions;
 use Language;
+use MediaWikiTestCase;
+use ParserOptions;
 use Title;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\InMemoryDataTypeLookup;
@@ -15,6 +16,8 @@
 use Wikibase\EntityParserOutputGenerator;
 use Wikibase\EntityRevision;
 use Wikibase\Lib\Store\Sql\SqlEntityInfoBuilderFactory;
+use Wikibase\Template\TemplateFactory;
+use Wikibase\Template\TemplateRegistry;
 use Wikibase\ValuesFinder;
 
 /**
@@ -27,7 +30,7 @@
  * @license GNU GPL v2+
  * @author Bene* < benestar.wikime...@gmail.com >
  */
-class EntityParserOutputGeneratorTest extends \MediaWikiTestCase {
+class EntityParserOutputGeneratorTest extends MediaWikiTestCase {
 
        private static $html = '<html>Nyan data!!!</html>';
        private static $placeholders = array( 'key' => 'value' );
@@ -113,7 +116,8 @@
                        $this->getValuesFinder(),
                        new SqlEntityInfoBuilderFactory(),
                        $this->newLanguageFallbackChain(),
-                       'en'
+                       'en',
+                       new TemplateFactory( 
TemplateRegistry::getDefaultInstance() )
                );
        }
 
diff --git a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php 
b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
index 489f45c..94e0c96 100644
--- a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
+++ b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
@@ -47,7 +47,8 @@
                        $entityType,
                        'de',
                        $this->getMock( 'Wikibase\Lib\Store\LabelLookup' ),
-                       $languageFallback
+                       $languageFallback,
+                       $this->getMock( 
'Wikibase\Repo\View\EditSectionGenerator' )
                );
 
                $this->assertInstanceOf( $expectedClass, $entityView );
@@ -71,7 +72,8 @@
                        'kittens',
                        'de',
                        $this->getMock( 'Wikibase\Lib\Store\LabelLookup' ),
-                       $languageFallback
+                       $languageFallback,
+                       $this->getMock( 
'Wikibase\Repo\View\EditSectionGenerator' )
                );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4bd4bfb3fde415b815a3daa16e28d967954af346
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <adrian.he...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to