Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
SuggestManualTemplateAction | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace FileImporter\Remote\MediaWiki; |
4 | |
5 | use FileImporter\Data\ImportPlan; |
6 | use FileImporter\Interfaces\PostImportHandler; |
7 | use FileImporter\Services\WikidataTemplateLookup; |
8 | use MediaWiki\User\User; |
9 | use StatusValue; |
10 | |
11 | /** |
12 | * Display an educated guess about how to correctly mark a source file as having been imported to |
13 | * Commons. |
14 | * |
15 | * @license GPL-2.0-or-later |
16 | */ |
17 | class SuggestManualTemplateAction implements PostImportHandler { |
18 | |
19 | private WikidataTemplateLookup $templateLookup; |
20 | |
21 | public function __construct( WikidataTemplateLookup $templateLookup ) { |
22 | $this->templateLookup = $templateLookup; |
23 | } |
24 | |
25 | /** |
26 | * @return StatusValue Always good, i.e. never contains warnings. The status's value is a |
27 | * message specifier explaining the suggested manual action. |
28 | */ |
29 | public function execute( ImportPlan $importPlan, User $user ): StatusValue { |
30 | $sourceUrl = $importPlan->getDetails()->getSourceUrl(); |
31 | $templateName = $this->templateLookup->fetchNowCommonsLocalTitle( $sourceUrl ); |
32 | |
33 | if ( $templateName ) { |
34 | return StatusValue::newGood( [ |
35 | 'fileimporter-add-specific-template', |
36 | $sourceUrl->getUrl(), |
37 | $templateName, |
38 | $importPlan->getTitle()->getText() |
39 | ] ); |
40 | } |
41 | |
42 | return StatusValue::newGood( [ |
43 | 'fileimporter-add-unknown-template', |
44 | $sourceUrl->getUrl() |
45 | ] ); |
46 | } |
47 | |
48 | } |