Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/350392 )

Change subject: Grammatical features view
......................................................................

Grammatical features view

Bug: T162788
Change-Id: Ic5e7ca48f572850f370e0e964e06908dbc1feba8
---
M WikibaseLexeme.entitytypes.php
M resources/lexeme.css
M resources/templates.php
M src/DataModel/LexemeForm.php
M src/View/LexemeFormsView.php
M src/View/LexemeView.php
M src/View/LexemeViewFactory.php
M tests/phpunit/mediawiki/View/LexemeFormsViewTest.php
8 files changed, 115 insertions(+), 19 deletions(-)


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

diff --git a/WikibaseLexeme.entitytypes.php b/WikibaseLexeme.entitytypes.php
index 3492e4c..55db0e6 100644
--- a/WikibaseLexeme.entitytypes.php
+++ b/WikibaseLexeme.entitytypes.php
@@ -68,7 +68,8 @@
                                $labelDescriptionLookup,
                                $fallbackChain,
                                $editSectionGenerator,
-                               $entityTermsView
+                               $entityTermsView,
+                               
WikibaseRepo::getDefaultInstance()->getEntityIdHtmlLinkFormatterFactory()
                        );
 
                        return $factory->newLexemeView();
diff --git a/resources/lexeme.css b/resources/lexeme.css
index 531efe9..9a50d86 100644
--- a/resources/lexeme.css
+++ b/resources/lexeme.css
@@ -17,3 +17,11 @@
        clear: left;
        margin-left: 10px; /* same as .wb-section-heading */
 }
+
+.wikibase-lexeme-form-grammatical-features {
+       display: flex;
+}
+
+.wikibase-lexeme-form-grammatical-features-values {
+       margin: 0 10px;
+}
diff --git a/resources/templates.php b/resources/templates.php
index 324a6d1..f4a3fed 100644
--- a/resources/templates.php
+++ b/resources/templates.php
@@ -15,7 +15,13 @@
        $templates = [];
 
        $templates['wikibase-lexeme-form'] = <<<'HTML'
-<h3 class="wikibase-lexeme-form-representation" lang="$1">$2<!-- 
wikibase-lexeme-form-id --> $3</h3>
+<div class="wikibase-lexeme-form">
+       <h3 class="wikibase-lexeme-form-representation" lang="$1">$2<!-- 
wikibase-lexeme-form-id --> $3</h3>
+       <div class="wikibase-lexeme-form-grammatical-features">
+               <div 
class="wikibase-lexeme-form-grammatical-features-header">Grammatical 
features</div>
+               <div 
class="wikibase-lexeme-form-grammatical-features-values">$4</div>
+       </div>
+</div>
 HTML;
 
        $templates['wikibase-lexeme-form-id'] = <<<'HTML'
diff --git a/src/DataModel/LexemeForm.php b/src/DataModel/LexemeForm.php
index 3ae2bec..381a9aa 100644
--- a/src/DataModel/LexemeForm.php
+++ b/src/DataModel/LexemeForm.php
@@ -2,6 +2,8 @@
 
 namespace Wikibase\Lexeme\DataModel;
 
+use Wikibase\DataModel\Entity\ItemId;
+
 /**
  * @license GPL-2.0+
  * @author Thiemo Mättig
@@ -19,12 +21,18 @@
        private $representation;
 
        /**
+        * @var ItemId[]
+        */
+       private $grammaticalFeatures;
+
+       /**
         * @param LexemeFormId $id|null
         * @param string $representation
         */
-       public function __construct( LexemeFormId $id = null, $representation ) 
{
+       public function __construct( LexemeFormId $id = null, $representation, 
array $grammaticalFeatures ) {
                $this->id = $id;
                $this->representation = $representation;
+               $this->grammaticalFeatures = $grammaticalFeatures;
        }
 
        /**
@@ -41,4 +49,8 @@
                return $this->representation;
        }
 
+       public function getGrammaticalFeatures() {
+               return $this->grammaticalFeatures;
+       }
+
 }
diff --git a/src/View/LexemeFormsView.php b/src/View/LexemeFormsView.php
index 36bd16b..8187d1e 100644
--- a/src/View/LexemeFormsView.php
+++ b/src/View/LexemeFormsView.php
@@ -2,9 +2,12 @@
 
 namespace Wikibase\Lexeme\View;
 
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
 use Wikibase\Lexeme\DataModel\LexemeForm;
 use Wikibase\Lexeme\DataModel\LexemeFormId;
 use Wikibase\Lexeme\View\Template\LexemeTemplateFactory;
+use Wikibase\Lib\EntityIdHtmlLinkFormatter;
 use Wikibase\View\LocalizedTextProvider;
 
 /**
@@ -23,12 +26,23 @@
         */
        private $templateFactory;
 
+       /**
+        * @var LabelDescriptionLookup
+        */
+       private $labelDescriptionLookup;
+       /**
+        * @var EntityIdHtmlLinkFormatter
+        */
+       private $entityIdHtmlFormatter;
+
        public function __construct(
                LocalizedTextProvider $textProvider,
-               LexemeTemplateFactory $templateFactory
+               LexemeTemplateFactory $templateFactory,
+               EntityIdHtmlLinkFormatter $entityIdHtmlFormatter
        ) {
                $this->textProvider = $textProvider;
                $this->templateFactory = $templateFactory;
+               $this->entityIdHtmlFormatter = $entityIdHtmlFormatter;
        }
 
        /**
@@ -63,11 +77,28 @@
                return $this->templateFactory->render( 'wikibase-lexeme-form', [
                        'some language',
                        htmlspecialchars( $representation ),
-                       $this->getFormIdHtml( $form->getId() )
+                       $this->getFormIdHtml( $form->getId() ),
+                       implode(
+                               ', ',
+                               array_map(
+                                       function ( ItemId $id ) {
+                                               return 
$this->getGrammaticalFeatureHtml( $id );
+                                       },
+                                       $form->getGrammaticalFeatures()
+                               )
+                       )
                ] );
        }
 
        /**
+        * @param ItemId $id
+        * @return string
+        */
+       private function getGrammaticalFeatureHtml( ItemId $id ) {
+               return $this->entityIdHtmlFormatter->formatEntityId( $id );
+       }
+
+       /**
         * @param LexemeFormId|null $id
         *
         * @return string HTML
diff --git a/src/View/LexemeView.php b/src/View/LexemeView.php
index c7eadd7..c5205e6 100644
--- a/src/View/LexemeView.php
+++ b/src/View/LexemeView.php
@@ -105,9 +105,9 @@
 
                // TODO: This obviously is a dummy that must be removed
                $forms = [
-                       new LexemeForm( new LexemeFormId( 'F1' ), 'A' ),
-                       new LexemeForm( new LexemeFormId( 'F2' ), 'B' ),
-                       new LexemeForm( new LexemeFormId( 'F3' ), 'C' ),
+                       new LexemeForm( new LexemeFormId( 'F1' ), 'A', [] ),
+                       new LexemeForm( new LexemeFormId( 'F2' ), 'B', [ new 
ItemId( 'Q2' ) ] ),
+                       new LexemeForm( new LexemeFormId( 'F3' ), 'C', [ new 
ItemId( 'Q2' ), new ItemId( 'Q3' ) ] ),
                ];
 
                $html = $this->getHtmlForLexicalCategoryAndLanguage( $entity )
diff --git a/src/View/LexemeViewFactory.php b/src/View/LexemeViewFactory.php
index 37844e4..2dd6aff 100644
--- a/src/View/LexemeViewFactory.php
+++ b/src/View/LexemeViewFactory.php
@@ -7,6 +7,7 @@
 use Wikibase\LanguageFallbackChain;
 use Wikibase\Lexeme\View\Template\LexemeTemplateFactory;
 use Wikibase\Lib\LanguageNameLookup;
+use Wikibase\Repo\EntityIdHtmlLinkFormatterFactory;
 use Wikibase\Repo\MediaWikiLanguageDirectionalityLookup;
 use Wikibase\Repo\MediaWikiLocalizedTextProvider;
 use Wikibase\Repo\ParserOutput\FallbackHintHtmlTermRenderer;
@@ -47,6 +48,11 @@
        private $entityTermsView;
 
        /**
+        * @var EntityIdHtmlLinkFormatterFactory
+        */
+       private $entityIdHtmlLinkFormatterFactory;
+
+       /**
         * @param string $languageCode
         * @param LabelDescriptionLookup $labelDescriptionLookup
         * @param LanguageFallbackChain $fallbackChain
@@ -58,13 +64,15 @@
                LabelDescriptionLookup $labelDescriptionLookup,
                LanguageFallbackChain $fallbackChain,
                EditSectionGenerator $editSectionGenerator,
-               EntityTermsView $entityTermsView
+               EntityTermsView $entityTermsView,
+               EntityIdHtmlLinkFormatterFactory 
$entityIdHtmlLinkFormatterFactory
        ) {
                $this->languageCode = $languageCode;
                $this->labelDescriptionLookup = $labelDescriptionLookup;
                $this->fallbackChain = $fallbackChain;
                $this->editSectionGenerator = $editSectionGenerator;
                $this->entityTermsView = $entityTermsView;
+               $this->entityIdHtmlLinkFormatterFactory = 
$entityIdHtmlLinkFormatterFactory;
        }
 
        public function newLexemeView() {
@@ -72,10 +80,6 @@
                $languageDirectionalityLookup = new 
MediaWikiLanguageDirectionalityLookup();
                $localizedTextProvider = new MediaWikiLocalizedTextProvider( 
$this->languageCode );
 
-               $formsView = new LexemeFormsView(
-                       $localizedTextProvider,
-                       new LexemeTemplateFactory( $templates )
-               );
                $sensesView = new SensesView( $localizedTextProvider );
 
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
@@ -99,6 +103,12 @@
                        ->getLanguageFallbackLabelDescriptionLookupFactory()
                        ->newLabelDescriptionLookup( Language::factory( 
$this->languageCode ) );
 
+               $formsView = new LexemeFormsView(
+                       $localizedTextProvider,
+                       new LexemeTemplateFactory( $templates ),
+                       
$this->entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($retrievingLabelDescriptionLookup)
+               );
+
                return new LexemeView(
                        TemplateFactory::getDefaultInstance(),
                        $this->entityTermsView,
diff --git a/tests/phpunit/mediawiki/View/LexemeFormsViewTest.php 
b/tests/phpunit/mediawiki/View/LexemeFormsViewTest.php
index 86e9ca8..709952e 100644
--- a/tests/phpunit/mediawiki/View/LexemeFormsViewTest.php
+++ b/tests/phpunit/mediawiki/View/LexemeFormsViewTest.php
@@ -3,10 +3,15 @@
 namespace Wikibase\Lexeme\Tests\MediaWiki\View;
 
 use PHPUnit_Framework_TestCase;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
 use Wikibase\Lexeme\DataModel\LexemeForm;
 use Wikibase\Lexeme\DataModel\LexemeFormId;
 use Wikibase\Lexeme\View\LexemeFormsView;
 use Wikibase\Lexeme\View\Template\LexemeTemplateFactory;
+use Wikibase\Lib\EntityIdHtmlLinkFormatter;
+use Wikibase\Lib\LanguageNameLookup;
+use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\View\DummyLocalizedTextProvider;
 
 /**
@@ -50,14 +55,32 @@
        public function testHtmlContainsFormRepresentationWithIdAndLanguage() {
                $view = $this->newFormsView();
                $html = $view->getHtml( [
-                       new LexemeForm( new LexemeFormId( 'FORM_ID' ), 
'FORM_REPRESENTATION' )
+                       new LexemeForm( new LexemeFormId( 'FORM_ID' ), 
'FORM_REPRESENTATION', [] )
                ] );
 
                assertThat(
                        $html,
-                       is( htmlPiece( havingChild( both( tagMatchingOutline(
-                               '<h3 lang="some language">'
-                       ) )->andAlso( havingTextContents( 'FORM_REPRESENTATION 
(FORM_ID)' ) ) ) ) )
+                       is( htmlPiece( havingChild(
+                               both( tagMatchingOutline( '<h3 lang="some 
language">' ) )
+                                       ->andAlso( havingTextContents( 
containsString( 'FORM_REPRESENTATION (FORM_ID)' ) ) )
+                       ) ) )
+               );
+       }
+
+       public function testHtmlContainsFormGrammaticalFeatures() {
+               $view = $this->newFormsView();
+               $grammaticalFeature = new ItemId( 'Q1' );
+               $lexemeForm = new LexemeForm(
+                       new LexemeFormId( 'FORM_ID' ),
+                       'FORM_REPRESENTATION',
+                       [ $grammaticalFeature ]
+               );
+
+               $html = $view->getHtml( [ $lexemeForm ] );
+
+               assertThat(
+                       $html,
+                       is( htmlPiece( havingChild( havingTextContents( 
containsString( 'Q1' ) ) ) ) )
                );
        }
 
@@ -65,9 +88,14 @@
                return new LexemeFormsView(
                        new DummyLocalizedTextProvider(),
                        new LexemeTemplateFactory( [
-                               'wikibase-lexeme-form' => '<h3 lang="$1">$2 
$3</h3>',
+                               'wikibase-lexeme-form' => '<h3 lang="$1">$2 $3 
$4</h3>',
                                'wikibase-lexeme-form-id' => '$1',
-                       ] )
+                       ] ),
+                       new EntityIdHtmlLinkFormatter(
+                               $this->getMock( LabelDescriptionLookup::class ),
+                               $this->getMock( EntityTitleLookup::class ),
+                               $this->getMock( LanguageNameLookup::class )
+                       )
                );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5e7ca48f572850f370e0e964e06908dbc1feba8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>

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

Reply via email to