Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ImportPlanFactory | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
newPlan | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace FileImporter\Services; |
4 | |
5 | use FileImporter\Data\ImportDetails; |
6 | use FileImporter\Data\ImportPlan; |
7 | use FileImporter\Data\ImportRequest; |
8 | use FileImporter\Exceptions\ImportException; |
9 | use FileImporter\Remote\MediaWiki\CommonsHelperConfigRetriever; |
10 | use FileImporter\Services\Http\HttpRequestExecutor; |
11 | use FileImporter\Services\UploadBase\UploadBaseFactory; |
12 | use FileImporter\Services\Wikitext\WikiLinkParserFactory; |
13 | use MediaWiki\Config\Config; |
14 | use MediaWiki\Context\RequestContext; |
15 | use MediaWiki\Permissions\RestrictionStore; |
16 | use MediaWiki\User\User; |
17 | |
18 | /** |
19 | * @license GPL-2.0-or-later |
20 | * @author Addshore |
21 | */ |
22 | class ImportPlanFactory { |
23 | |
24 | private Config $config; |
25 | private WikiLinkParserFactory $wikiLinkParserFactory; |
26 | private RestrictionStore $restrictionStore; |
27 | private HttpRequestExecutor $httpRequestExecutor; |
28 | private SourceSiteLocator $sourceSiteLocator; |
29 | private DuplicateFileRevisionChecker $duplicateFileRevisionChecker; |
30 | private UploadBaseFactory $uploadBaseFactory; |
31 | |
32 | public function __construct( |
33 | Config $config, |
34 | WikiLinkParserFactory $wikiLinkParserFactory, |
35 | RestrictionStore $restrictionStore, |
36 | HttpRequestExecutor $httpRequestExecutor, |
37 | SourceSiteLocator $sourceSiteLocator, |
38 | DuplicateFileRevisionChecker $duplicateFileRevisionChecker, |
39 | UploadBaseFactory $uploadBaseFactory |
40 | ) { |
41 | $this->config = $config; |
42 | $this->wikiLinkParserFactory = $wikiLinkParserFactory; |
43 | $this->restrictionStore = $restrictionStore; |
44 | $this->httpRequestExecutor = $httpRequestExecutor; |
45 | $this->sourceSiteLocator = $sourceSiteLocator; |
46 | $this->duplicateFileRevisionChecker = $duplicateFileRevisionChecker; |
47 | $this->uploadBaseFactory = $uploadBaseFactory; |
48 | } |
49 | |
50 | /** |
51 | * @return ImportPlan A valid ImportPlan |
52 | * @throws ImportException |
53 | */ |
54 | public function newPlan( ImportRequest $importRequest, ImportDetails $importDetails, User $user ) { |
55 | $context = RequestContext::getMain(); |
56 | $commonsHelperServer = $this->config->get( 'FileImporterCommonsHelperServer' ); |
57 | |
58 | if ( $commonsHelperServer ) { |
59 | $commonsHelperConfigRetriever = new CommonsHelperConfigRetriever( |
60 | $this->httpRequestExecutor, |
61 | $commonsHelperServer, |
62 | $this->config->get( 'FileImporterCommonsHelperBasePageName' ) |
63 | ); |
64 | $commonsHelperHelpPage = $this->config->get( 'FileImporterCommonsHelperHelpPage' ) ?: |
65 | $commonsHelperServer; |
66 | } |
67 | |
68 | $sourceSite = $this->sourceSiteLocator->getSourceSite( $importDetails->getSourceUrl() ); |
69 | $interWikiPrefix = $sourceSite->getLinkPrefix( $importDetails->getSourceUrl() ); |
70 | $importPlan = new ImportPlan( $importRequest, $importDetails, $this->config, $context, $interWikiPrefix ); |
71 | |
72 | $planValidator = new ImportPlanValidator( |
73 | $this->duplicateFileRevisionChecker, |
74 | $sourceSite->getImportTitleChecker(), |
75 | $this->uploadBaseFactory, |
76 | $commonsHelperConfigRetriever ?? null, |
77 | $commonsHelperHelpPage ?? null, |
78 | $this->wikiLinkParserFactory, |
79 | $this->restrictionStore |
80 | ); |
81 | $planValidator->validate( $importPlan, $user ); |
82 | |
83 | return $importPlan; |
84 | } |
85 | |
86 | } |