Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.46% |
23 / 26 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| WikiImporterFactory | |
92.00% |
23 / 25 |
|
50.00% |
1 / 2 |
3.00 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| getWikiImporter | |
87.50% |
14 / 16 |
|
0.00% |
0 / 1 |
2.01 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | * @author Zabe |
| 6 | */ |
| 7 | |
| 8 | namespace MediaWiki\Import; |
| 9 | |
| 10 | use MediaWiki\Config\Config; |
| 11 | use MediaWiki\Content\IContentHandlerFactory; |
| 12 | use MediaWiki\Context\RequestContext; |
| 13 | use MediaWiki\HookContainer\HookContainer; |
| 14 | use MediaWiki\Language\Language; |
| 15 | use MediaWiki\Page\WikiPageFactory; |
| 16 | use MediaWiki\Permissions\Authority; |
| 17 | use MediaWiki\Revision\SlotRoleRegistry; |
| 18 | use MediaWiki\Title\NamespaceInfo; |
| 19 | use MediaWiki\Title\TitleFactory; |
| 20 | |
| 21 | /** |
| 22 | * Factory service for WikiImporter instances. |
| 23 | * |
| 24 | * @since 1.37 |
| 25 | */ |
| 26 | class WikiImporterFactory { |
| 27 | private Config $config; |
| 28 | private HookContainer $hookContainer; |
| 29 | private Language $contentLanguage; |
| 30 | private NamespaceInfo $namespaceInfo; |
| 31 | private TitleFactory $titleFactory; |
| 32 | private WikiPageFactory $wikiPageFactory; |
| 33 | private UploadRevisionImporter $uploadRevisionImporter; |
| 34 | private IContentHandlerFactory $contentHandlerFactory; |
| 35 | private SlotRoleRegistry $slotRoleRegistry; |
| 36 | |
| 37 | public function __construct( |
| 38 | Config $config, |
| 39 | HookContainer $hookContainer, |
| 40 | Language $contentLanguage, |
| 41 | NamespaceInfo $namespaceInfo, |
| 42 | TitleFactory $titleFactory, |
| 43 | WikiPageFactory $wikiPageFactory, |
| 44 | UploadRevisionImporter $uploadRevisionImporter, |
| 45 | IContentHandlerFactory $contentHandlerFactory, |
| 46 | SlotRoleRegistry $slotRoleRegistry |
| 47 | ) { |
| 48 | $this->config = $config; |
| 49 | $this->hookContainer = $hookContainer; |
| 50 | $this->contentLanguage = $contentLanguage; |
| 51 | $this->namespaceInfo = $namespaceInfo; |
| 52 | $this->titleFactory = $titleFactory; |
| 53 | $this->wikiPageFactory = $wikiPageFactory; |
| 54 | $this->uploadRevisionImporter = $uploadRevisionImporter; |
| 55 | $this->contentHandlerFactory = $contentHandlerFactory; |
| 56 | $this->slotRoleRegistry = $slotRoleRegistry; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @param ImportSource $source |
| 61 | * @param Authority|null $performer Authority used for permission checks only (to ensure that |
| 62 | * the user performing the import is allowed to edit the pages they're importing). To skip |
| 63 | * the checks, use UltimateAuthority. |
| 64 | * |
| 65 | * When omitted, defaults to the current global user. This behavior is deprecated since 1.42. |
| 66 | * |
| 67 | * If you want to also log the import actions, see ImportReporter. |
| 68 | * @return WikiImporter |
| 69 | */ |
| 70 | public function getWikiImporter( ImportSource $source, ?Authority $performer = null ): WikiImporter { |
| 71 | if ( !$performer ) { |
| 72 | wfDeprecated( __METHOD__ . ' without $performer', '1.42' ); |
| 73 | $performer = RequestContext::getMain()->getAuthority(); |
| 74 | } |
| 75 | |
| 76 | return new WikiImporter( |
| 77 | $source, |
| 78 | $performer, |
| 79 | $this->config, |
| 80 | $this->hookContainer, |
| 81 | $this->contentLanguage, |
| 82 | $this->namespaceInfo, |
| 83 | $this->titleFactory, |
| 84 | $this->wikiPageFactory, |
| 85 | $this->uploadRevisionImporter, |
| 86 | $this->contentHandlerFactory, |
| 87 | $this->slotRoleRegistry |
| 88 | ); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** @deprecated class alias since 1.46 */ |
| 93 | class_alias( WikiImporterFactory::class, 'WikiImporterFactory' ); |