Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
56 / 56
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
LexemeViewFactory
100.00% covered (success)
100.00%
56 / 56
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 newLexemeView
100.00% covered (success)
100.00%
49 / 49
100.00% covered (success)
100.00%
1 / 1
1
 newToolbarEditSectionGenerator
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Wikibase\Lexeme\Presentation\View;
4
5use MediaWiki\Context\DerivativeContext;
6use MediaWiki\Context\RequestContext;
7use MediaWiki\Language\Language;
8use Wikibase\Lexeme\Presentation\Formatters\LexemeTermFormatter;
9use Wikibase\Lexeme\Presentation\View\Template\LexemeTemplateFactory;
10use Wikibase\Lexeme\WikibaseLexemeServices;
11use Wikibase\Lib\TermLanguageFallbackChain;
12use Wikibase\Repo\MediaWikiLocalizedTextProvider;
13use Wikibase\Repo\View\RepoSpecialPageLinker;
14use Wikibase\Repo\WikibaseRepo;
15use Wikibase\View\Template\TemplateFactory;
16use Wikibase\View\ToolbarEditSectionGenerator;
17
18/**
19 * @license GPL-2.0-or-later
20 * @author Thiemo Kreuz
21 */
22class LexemeViewFactory {
23
24    /**
25     * @var TermLanguageFallbackChain
26     */
27    private $termFallbackChain;
28
29    /**
30     * @var Language
31     */
32    private $language;
33
34    public function __construct(
35        Language $language,
36        TermLanguageFallbackChain $termFallbackChain
37    ) {
38        $this->termFallbackChain = $termFallbackChain;
39        $this->language = $language;
40    }
41
42    public function newLexemeView() {
43        $templates = include __DIR__ . '/../../../resources/templates.php';
44        $templateFactory = new LexemeTemplateFactory( $templates );
45
46        $languageDirectionalityLookup = WikibaseRepo::getLanguageDirectionalityLookup();
47        $localizedTextProvider = new MediaWikiLocalizedTextProvider( $this->language );
48
49        $viewFactory = WikibaseRepo::getViewFactory();
50
51        $editSectionGenerator = $this->newToolbarEditSectionGenerator();
52
53        $context = new DerivativeContext( RequestContext::getMain() );
54        $context->setLanguage( $this->language );
55        $languageNameLookup = WikibaseLexemeServices::getLanguageNameLookupFactory()
56            ->getForContextSource( $context );
57
58        $statementSectionsView = $viewFactory->newStatementSectionsView(
59            $this->language->getCode(),
60            $this->termFallbackChain,
61            $editSectionGenerator
62        );
63
64        $statementGroupListView = $viewFactory->newStatementGroupListView(
65            $this->language->getCode(),
66            $this->termFallbackChain,
67            $editSectionGenerator
68        );
69
70        $idLinkFormatter = WikibaseRepo::getEntityIdHtmlLinkFormatterFactory()
71            ->getEntityIdFormatter( $this->language );
72
73        $formsView = new FormsView(
74            $localizedTextProvider,
75            $templateFactory,
76            $idLinkFormatter,
77            $statementGroupListView,
78            WikibaseLexemeServices::getGrammaticalFeaturesOrderProvider()
79        );
80
81        $sensesView = new SensesView(
82            $localizedTextProvider,
83            $languageDirectionalityLookup,
84            $templateFactory,
85            $statementGroupListView,
86            $languageNameLookup
87        );
88
89        return new LexemeView(
90            TemplateFactory::getDefaultInstance(),
91            $languageDirectionalityLookup,
92            $this->language->getCode(),
93            $formsView,
94            $sensesView,
95            $statementSectionsView,
96            new LexemeTermFormatter(
97                $localizedTextProvider
98                    ->get( 'wikibaselexeme-presentation-lexeme-display-label-separator-multiple-lemma' )
99            ),
100            $idLinkFormatter
101        );
102    }
103
104    private function newToolbarEditSectionGenerator() {
105        return new ToolbarEditSectionGenerator(
106            new RepoSpecialPageLinker(),
107            TemplateFactory::getDefaultInstance(),
108            new MediaWikiLocalizedTextProvider( $this->language )
109        );
110    }
111
112}