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\Language\Language;
27use MediaWiki\Page\WikiPageFactory;
28use MediaWiki\Permissions\Authority;
29use MediaWiki\Revision\SlotRoleRegistry;
30use MediaWiki\Title\NamespaceInfo;
31use MediaWiki\Title\TitleFactory;
32
33/**
34 * Factory service for WikiImporter instances.
35 *
36 * @since 1.37
37 */
38class WikiImporterFactory {
39    private Config $config;
40    private HookContainer $hookContainer;
41    private Language $contentLanguage;
42    private NamespaceInfo $namespaceInfo;
43    private TitleFactory $titleFactory;
44    private WikiPageFactory $wikiPageFactory;
45    private UploadRevisionImporter $uploadRevisionImporter;
46    private IContentHandlerFactory $contentHandlerFactory;
47    private SlotRoleRegistry $slotRoleRegistry;
48
49    public function __construct(
50        Config $config,
51        HookContainer $hookContainer,
52        Language $contentLanguage,
53        NamespaceInfo $namespaceInfo,
54        TitleFactory $titleFactory,
55        WikiPageFactory $wikiPageFactory,
56        UploadRevisionImporter $uploadRevisionImporter,
57        IContentHandlerFactory $contentHandlerFactory,
58        SlotRoleRegistry $slotRoleRegistry
59    ) {
60        $this->config = $config;
61        $this->hookContainer = $hookContainer;
62        $this->contentLanguage = $contentLanguage;
63        $this->namespaceInfo = $namespaceInfo;
64        $this->titleFactory = $titleFactory;
65        $this->wikiPageFactory = $wikiPageFactory;
66        $this->uploadRevisionImporter = $uploadRevisionImporter;
67        $this->contentHandlerFactory = $contentHandlerFactory;
68        $this->slotRoleRegistry = $slotRoleRegistry;
69    }
70
71    /**
72     * @param ImportSource $source
73     * @param Authority|null $performer Authority used for permission checks only (to ensure that
74     *     the user performing the import is allowed to edit the pages they're importing). To skip
75     *     the checks, use UltimateAuthority.
76     *
77     *     When omitted, defaults to the current global user. This behavior is deprecated since 1.42.
78     *
79     *     If you want to also log the import actions, see ImportReporter.
80     * @return WikiImporter
81     */
82    public function getWikiImporter( ImportSource $source, ?Authority $performer = null ): WikiImporter {
83        if ( !$performer ) {
84            wfDeprecated( __METHOD__ . ' without $performer', '1.42' );
85            $performer = RequestContext::getMain()->getAuthority();
86        }
87
88        return new WikiImporter(
89            $source,
90            $performer,
91            $this->config,
92            $this->hookContainer,
93            $this->contentLanguage,
94            $this->namespaceInfo,
95            $this->titleFactory,
96            $this->wikiPageFactory,
97            $this->uploadRevisionImporter,
98            $this->contentHandlerFactory,
99            $this->slotRoleRegistry
100        );
101    }
102}