Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
64.00% covered (warning)
64.00%
16 / 25
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
HtmlTransformFactory
64.00% covered (warning)
64.00%
16 / 25
66.67% covered (warning)
66.67%
2 / 3
3.42
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 getHtmlToContentTransform
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 getLanguageVariantConverter
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Parser\Parsoid;
4
5use MediaWiki\Content\IContentHandlerFactory;
6use MediaWiki\Languages\LanguageConverterFactory;
7use MediaWiki\Languages\LanguageFactory;
8use MediaWiki\Page\PageIdentity;
9use MediaWiki\Parser\Parsoid\Config\PageConfigFactory;
10use MediaWiki\Title\TitleFactory;
11use Wikimedia\Parsoid\Config\SiteConfig;
12use Wikimedia\Parsoid\Parsoid;
13
14/**
15 * @since 1.40
16 * @unstable should be marked stable before 1.40 release
17 */
18class HtmlTransformFactory {
19    private Parsoid $parsoid;
20    private array $parsoidSettings;
21    private PageConfigFactory $configFactory;
22    private IContentHandlerFactory $contentHandlerFactory;
23    private SiteConfig $siteConfig;
24    private TitleFactory $titleFactory;
25    private LanguageConverterFactory $languageConverterFactory;
26    private LanguageFactory $languageFactory;
27
28    /**
29     * @param Parsoid $parsoid
30     * @param array $parsoidSettings
31     * @param PageConfigFactory $configFactory
32     * @param IContentHandlerFactory $contentHandlerFactory
33     * @param SiteConfig $siteConfig
34     * @param TitleFactory $titleFactory
35     * @param LanguageConverterFactory $languageConverterFactory
36     * @param LanguageFactory $languageFactory
37     */
38    public function __construct(
39        Parsoid $parsoid,
40        array $parsoidSettings,
41        PageConfigFactory $configFactory,
42        IContentHandlerFactory $contentHandlerFactory,
43        SiteConfig $siteConfig,
44        TitleFactory $titleFactory,
45        LanguageConverterFactory $languageConverterFactory,
46        LanguageFactory $languageFactory
47    ) {
48        $this->parsoid = $parsoid;
49        $this->parsoidSettings = $parsoidSettings;
50        $this->configFactory = $configFactory;
51        $this->contentHandlerFactory = $contentHandlerFactory;
52        $this->siteConfig = $siteConfig;
53        $this->titleFactory = $titleFactory;
54        $this->languageConverterFactory = $languageConverterFactory;
55        $this->languageFactory = $languageFactory;
56    }
57
58    /**
59     * Get the HTML transform object for a given page and specified
60     * modified HTML.
61     *
62     * @param string $modifiedHTML
63     * @param PageIdentity $page
64     *
65     * @return HtmlToContentTransform
66     */
67    public function getHtmlToContentTransform( string $modifiedHTML, PageIdentity $page ) {
68        return new HtmlToContentTransform(
69            $modifiedHTML,
70            $page,
71            $this->parsoid,
72            $this->parsoidSettings,
73            $this->configFactory,
74            $this->contentHandlerFactory
75        );
76    }
77
78    /**
79     * Get a language variant converter object for a given page
80     *
81     * @param PageIdentity $page
82     *
83     * @return LanguageVariantConverter
84     */
85    public function getLanguageVariantConverter( PageIdentity $page ): LanguageVariantConverter {
86        return new LanguageVariantConverter(
87            $page,
88            $this->configFactory,
89            $this->parsoid,
90            $this->siteConfig,
91            $this->titleFactory,
92            $this->languageConverterFactory,
93            $this->languageFactory
94        );
95    }
96
97}