Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.00% covered (success)
92.00%
23 / 25
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
WikiImporterFactory
92.00% covered (success)
92.00%
23 / 25
50.00% covered (danger)
50.00%
1 / 2
3.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 getWikiImporter
87.50% covered (warning)
87.50%
14 / 16
0.00% covered (danger)
0.00%
0 / 1
2.01
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @author Zabe
20 */
21
22use MediaWiki\Config\Config;
23use MediaWiki\Content\IContentHandlerFactory;
24use MediaWiki\Context\RequestContext;
25use MediaWiki\HookContainer\HookContainer;
26use MediaWiki\Page\WikiPageFactory;
27use MediaWiki\Permissions\Authority;
28use MediaWiki\Revision\SlotRoleRegistry;
29use MediaWiki\Title\NamespaceInfo;
30use MediaWiki\Title\TitleFactory;
31
32/**
33 * Factory service for WikiImporter instances.
34 *
35 * @since 1.37
36 */
37class WikiImporterFactory {
38    private Config $config;
39    private HookContainer $hookContainer;
40    private Language $contentLanguage;
41    private NamespaceInfo $namespaceInfo;
42    private TitleFactory $titleFactory;
43    private WikiPageFactory $wikiPageFactory;
44    private UploadRevisionImporter $uploadRevisionImporter;
45    private IContentHandlerFactory $contentHandlerFactory;
46    private SlotRoleRegistry $slotRoleRegistry;
47
48    public function __construct(
49        Config $config,
50        HookContainer $hookContainer,
51        Language $contentLanguage,
52        NamespaceInfo $namespaceInfo,
53        TitleFactory $titleFactory,
54        WikiPageFactory $wikiPageFactory,
55        UploadRevisionImporter $uploadRevisionImporter,
56        IContentHandlerFactory $contentHandlerFactory,
57        SlotRoleRegistry $slotRoleRegistry
58    ) {
59        $this->config = $config;
60        $this->hookContainer = $hookContainer;
61        $this->contentLanguage = $contentLanguage;
62        $this->namespaceInfo = $namespaceInfo;
63        $this->titleFactory = $titleFactory;
64        $this->wikiPageFactory = $wikiPageFactory;
65        $this->uploadRevisionImporter = $uploadRevisionImporter;
66        $this->contentHandlerFactory = $contentHandlerFactory;
67        $this->slotRoleRegistry = $slotRoleRegistry;
68    }
69
70    /**
71     * @param ImportSource $source
72     * @param Authority|null $performer Authority used for permission checks only (to ensure that
73     *     the user performing the import is allowed to edit the pages they're importing). To skip
74     *     the checks, use UltimateAuthority.
75     *
76     *     When omitted, defaults to the current global user. This behavior is deprecated since 1.42.
77     *
78     *     If you want to also log the import actions, see ImportReporter.
79     * @return WikiImporter
80     */
81    public function getWikiImporter( ImportSource $source, Authority $performer = null ): WikiImporter {
82        if ( !$performer ) {
83            wfDeprecated( __METHOD__ . ' without $performer', '1.42' );
84            $performer = RequestContext::getMain()->getAuthority();
85        }
86
87        return new WikiImporter(
88            $source,
89            $performer,
90            $this->config,
91            $this->hookContainer,
92            $this->contentLanguage,
93            $this->namespaceInfo,
94            $this->titleFactory,
95            $this->wikiPageFactory,
96            $this->uploadRevisionImporter,
97            $this->contentHandlerFactory,
98            $this->slotRoleRegistry
99        );
100    }
101}