Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/343920 )

Change subject: Introduce and start using LexemeViewFactory
......................................................................

Introduce and start using LexemeViewFactory

This is, at this point, doing nothing but moving existing code around.
Note that this moves the dependency on WikibaseRepo into the new factory.
I believe we should avoid this but do not wanted to do this in the same
patch, making it more complicated.

Change-Id: Ie3dd7b3b0d2809c30606051e338ff2f415300f8b
---
M WikibaseLexeme.entitytypes.php
A src/View/LexemeViewFactory.php
A tests/phpunit/mediawiki/View/LexemeViewFactoryTest.php
3 files changed, 153 insertions(+), 41 deletions(-)


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

diff --git a/WikibaseLexeme.entitytypes.php b/WikibaseLexeme.entitytypes.php
index 714ebd6..3e2ff7f 100644
--- a/WikibaseLexeme.entitytypes.php
+++ b/WikibaseLexeme.entitytypes.php
@@ -12,26 +12,15 @@
  * @author Amir Sarabadani <ladsgr...@gmail.com>
  */
 
-use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\Lexeme\ChangeOp\Deserialization\LemmaChangeOpDeserializer;
-use Wikibase\Lexeme\ChangeOp\Deserialization\LanguageChangeOpDeserializer;
-use 
Wikibase\Lexeme\ChangeOp\Deserialization\LexicalCategoryChangeOpDeserializer;
-use Wikibase\Lexeme\Rdf\LexemeRdfBuilder;
-use Wikibase\Lexeme\Validators\LexemeValidatorFactory;
-use Wikibase\Lexeme\View\LexemeFormsView;
-use Wikibase\Rdf\RdfVocabulary;
-use Wikibase\Repo\ChangeOp\Deserialization\ClaimsChangeOpDeserializer;
-use Wikibase\Repo\ChangeOp\Deserialization\TermChangeOpSerializationValidator;
-use Wikibase\Repo\MediaWikiLanguageDirectionalityLookup;
-use Wikibase\Repo\MediaWikiLocalizedTextProvider;
-use Wikibase\Repo\ParserOutput\FallbackHintHtmlTermRenderer;
-use Wikibase\Repo\WikibaseRepo;
 use Wikibase\DataModel\DeserializerFactory;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\SerializerFactory;
 use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
-use Wikibase\Lib\LanguageNameLookup;
 use Wikibase\LanguageFallbackChain;
+use Wikibase\Lexeme\ChangeOp\Deserialization\LanguageChangeOpDeserializer;
+use Wikibase\Lexeme\ChangeOp\Deserialization\LemmaChangeOpDeserializer;
 use Wikibase\Lexeme\ChangeOp\Deserialization\LexemeChangeOpDeserializer;
+use 
Wikibase\Lexeme\ChangeOp\Deserialization\LexicalCategoryChangeOpDeserializer;
 use Wikibase\Lexeme\Content\LexemeContent;
 use Wikibase\Lexeme\Content\LexemeHandler;
 use Wikibase\Lexeme\DataModel\Lexeme;
@@ -40,10 +29,15 @@
 use Wikibase\Lexeme\DataModel\Serialization\LexemeSerializer;
 use Wikibase\Lexeme\DataModel\Services\Diff\LexemeDiffer;
 use Wikibase\Lexeme\DataModel\Services\Diff\LexemePatcher;
-use Wikibase\Lexeme\View\LexemeView;
+use Wikibase\Lexeme\Rdf\LexemeRdfBuilder;
+use Wikibase\Lexeme\Validators\LexemeValidatorFactory;
+use Wikibase\Lexeme\View\LexemeViewFactory;
+use Wikibase\Rdf\RdfVocabulary;
+use Wikibase\Repo\ChangeOp\Deserialization\ClaimsChangeOpDeserializer;
+use Wikibase\Repo\ChangeOp\Deserialization\TermChangeOpSerializationValidator;
+use Wikibase\Repo\WikibaseRepo;
 use Wikibase\View\EditSectionGenerator;
 use Wikibase\View\EntityTermsView;
-use Wikibase\View\Template\TemplateFactory;
 use Wikimedia\Purtle\RdfWriter;
 
 return [
@@ -68,32 +62,15 @@
                        EditSectionGenerator $editSectionGenerator,
                        EntityTermsView $entityTermsView
                ) {
-                       $wikibaseRepo = WikibaseRepo::getDefaultInstance();
-                       $userLanguage = $wikibaseRepo->getUserLanguage();
-                       $textProvider = new MediaWikiLocalizedTextProvider( 
$userLanguage->getCode() );
-                       $viewFactory = $wikibaseRepo->getViewFactory();
-                       $languageDirectionalityLookup = new 
MediaWikiLanguageDirectionalityLookup();
-                       $htmlTermRenderer = new FallbackHintHtmlTermRenderer(
-                               $languageDirectionalityLookup,
-                               new LanguageNameLookup( $languageCode )
+                       $factory = new LexemeViewFactory(
+                               $languageCode,
+                               $labelDescriptionLookup,
+                               $fallbackChain,
+                               $editSectionGenerator,
+                               $entityTermsView
                        );
 
-                       // TODO: One of the next steps should be to extract 
this to a LexemeViewFactory.
-                       return new LexemeView(
-                               TemplateFactory::getDefaultInstance(),
-                               $entityTermsView,
-                               $languageDirectionalityLookup,
-                               $languageCode,
-                               new LexemeFormsView( $textProvider ),
-                               $viewFactory->newStatementSectionsView(
-                                       $languageCode,
-                                       $labelDescriptionLookup,
-                                       $fallbackChain,
-                                       $editSectionGenerator
-                               ),
-                               $htmlTermRenderer,
-                               $labelDescriptionLookup
-                       );
+                       return $factory->newLexemeView();
                },
                'content-model-id' => LexemeContent::CONTENT_MODEL_ID,
                'content-handler-factory-callback' => function() {
diff --git a/src/View/LexemeViewFactory.php b/src/View/LexemeViewFactory.php
new file mode 100644
index 0000000..ae2ad50
--- /dev/null
+++ b/src/View/LexemeViewFactory.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace Wikibase\Lexeme\View;
+
+use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
+use Wikibase\LanguageFallbackChain;
+use Wikibase\Lib\LanguageNameLookup;
+use Wikibase\Repo\MediaWikiLanguageDirectionalityLookup;
+use Wikibase\Repo\MediaWikiLocalizedTextProvider;
+use Wikibase\Repo\ParserOutput\FallbackHintHtmlTermRenderer;
+use Wikibase\Repo\WikibaseRepo;
+use Wikibase\View\EditSectionGenerator;
+use Wikibase\View\EntityTermsView;
+use Wikibase\View\Template\TemplateFactory;
+
+/**
+ * @license GPL-2.0+
+ * @author Thiemo Mättig
+ */
+class LexemeViewFactory {
+
+       /**
+        * @var string
+        */
+       private $languageCode;
+
+       /**
+        * @var LabelDescriptionLookup
+        */
+       private $labelDescriptionLookup;
+
+       /**
+        * @var LanguageFallbackChain
+        */
+       private $fallbackChain;
+
+       /**
+        * @var EditSectionGenerator
+        */
+       private $editSectionGenerator;
+
+       /**
+        * @var EntityTermsView
+        */
+       private $entityTermsView;
+
+       /**
+        * @param string $languageCode
+        * @param LabelDescriptionLookup $labelDescriptionLookup
+        * @param LanguageFallbackChain $fallbackChain
+        * @param EditSectionGenerator $editSectionGenerator
+        * @param EntityTermsView $entityTermsView
+        */
+       public function __construct(
+               $languageCode,
+               LabelDescriptionLookup $labelDescriptionLookup,
+               LanguageFallbackChain $fallbackChain,
+               EditSectionGenerator $editSectionGenerator,
+               EntityTermsView $entityTermsView
+       ) {
+               $this->languageCode = $languageCode;
+               $this->labelDescriptionLookup = $labelDescriptionLookup;
+               $this->fallbackChain = $fallbackChain;
+               $this->editSectionGenerator = $editSectionGenerator;
+               $this->entityTermsView = $entityTermsView;
+       }
+
+       public function newLexemeView() {
+               $languageDirectionalityLookup = new 
MediaWikiLanguageDirectionalityLookup();
+
+               $formsView = new LexemeFormsView(
+                       new MediaWikiLocalizedTextProvider( $this->languageCode 
)
+               );
+
+               $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+               $statementSectionsView = 
$wikibaseRepo->getViewFactory()->newStatementSectionsView(
+                       $this->languageCode,
+                       $this->labelDescriptionLookup,
+                       $this->fallbackChain,
+                       $this->editSectionGenerator
+               );
+
+               $htmlTermRenderer = new FallbackHintHtmlTermRenderer(
+                       $languageDirectionalityLookup,
+                       new LanguageNameLookup( $this->languageCode )
+               );
+
+               return new LexemeView(
+                       TemplateFactory::getDefaultInstance(),
+                       $this->entityTermsView,
+                       $languageDirectionalityLookup,
+                       $this->languageCode,
+                       $formsView,
+                       $statementSectionsView,
+                       $htmlTermRenderer,
+                       $this->labelDescriptionLookup
+               );
+       }
+
+}
diff --git a/tests/phpunit/mediawiki/View/LexemeViewFactoryTest.php 
b/tests/phpunit/mediawiki/View/LexemeViewFactoryTest.php
new file mode 100644
index 0000000..432be6a
--- /dev/null
+++ b/tests/phpunit/mediawiki/View/LexemeViewFactoryTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Wikibase\Lexeme\Tests\MediaWiki\View;
+
+use PHPUnit_Framework_TestCase;
+use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
+use Wikibase\LanguageFallbackChain;
+use Wikibase\Lexeme\View\LexemeView;
+use Wikibase\Lexeme\View\LexemeViewFactory;
+use Wikibase\View\EditSectionGenerator;
+use Wikibase\View\EntityTermsView;
+
+/**
+ * @covers Wikibase\Lexeme\View\LexemeViewFactory
+ *
+ * @group WikibaseLexeme
+ *
+ * @license GPL-2.0+
+ * @author Thiemo Mättig
+ */
+class LexemeViewFactoryTest extends PHPUnit_Framework_TestCase {
+
+       public function testNewLexemeView() {
+               $factory = new LexemeViewFactory(
+                       'en',
+                       $this->getMock( LabelDescriptionLookup::class ),
+                       new LanguageFallbackChain( [] ),
+                       $this->getMock( EditSectionGenerator::class ),
+                       $this->getMock( EntityTermsView::class )
+               );
+               $view = $factory->newLexemeView();
+               $this->assertInstanceOf( LexemeView::class, $view );
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie3dd7b3b0d2809c30606051e338ff2f415300f8b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

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

Reply via email to