Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ImportIdentityFormSnippet | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getHtml | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace FileImporter\Html; |
4 | |
5 | use MediaWiki\Html\Html; |
6 | |
7 | /** |
8 | * Collection of input elements that are used to persist the request from page load to page load. |
9 | * |
10 | * @license GPL-2.0-or-later |
11 | * @author Addshore |
12 | */ |
13 | class ImportIdentityFormSnippet { |
14 | |
15 | private array $identityParts; |
16 | |
17 | private const IDENTITY_KEYS = [ |
18 | 'clientUrl', |
19 | 'intendedFileName', |
20 | 'intendedRevisionSummary', |
21 | 'intendedWikitext', |
22 | 'actionStats', |
23 | 'validationWarnings', |
24 | 'importDetailsHash', |
25 | 'automateSourceWikiCleanup', |
26 | 'automateSourceWikiDelete' |
27 | ]; |
28 | |
29 | /** |
30 | * @param array $identityParts Keys: |
31 | * - clientUrl, as initial input by the user |
32 | * - intendedFileName, either generated from the client URL or passed by the user |
33 | * - importDetailsHash, generated from the first import request, to ensure we know what |
34 | * we are importing |
35 | */ |
36 | public function __construct( array $identityParts ) { |
37 | $this->identityParts = $identityParts; |
38 | } |
39 | |
40 | public function getHtml(): string { |
41 | $html = ''; |
42 | |
43 | foreach ( self::IDENTITY_KEYS as $identityKey ) { |
44 | if ( array_key_exists( $identityKey, $this->identityParts ) ) { |
45 | $html .= Html::element( |
46 | 'input', |
47 | [ |
48 | 'type' => 'hidden', |
49 | 'name' => $identityKey, |
50 | 'value' => $this->identityParts[$identityKey], |
51 | ] |
52 | ); |
53 | } |
54 | } |
55 | |
56 | return $html; |
57 | } |
58 | |
59 | } |