Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
96.15% |
50 / 52 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ChangeFileNameForm | |
96.15% |
50 / 52 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
getHtml | |
96.15% |
50 / 52 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace FileImporter\Html; |
4 | |
5 | use FileImporter\Data\ImportPlan; |
6 | use MediaWiki\Html\Html; |
7 | use MediaWiki\Title\MalformedTitleException; |
8 | use OOUI\ButtonInputWidget; |
9 | use OOUI\FieldLayout; |
10 | use OOUI\FieldsetLayout; |
11 | use OOUI\TextInputWidget; |
12 | |
13 | /** |
14 | * Form allowing the user to select a new file name. |
15 | * |
16 | * @license GPL-2.0-or-later |
17 | * @author Addshore |
18 | */ |
19 | class ChangeFileNameForm extends SpecialPageHtmlFragment { |
20 | |
21 | public function getHtml( ImportPlan $importPlan ): string { |
22 | try { |
23 | $filenameValue = $importPlan->getFileName(); |
24 | } catch ( MalformedTitleException $ex ) { |
25 | $filenameValue = $importPlan->getRequest()->getIntendedName(); |
26 | } |
27 | |
28 | return Html::openElement( |
29 | 'form', |
30 | [ |
31 | 'action' => $this->getPageTitle()->getLocalURL(), |
32 | 'method' => 'POST', |
33 | ] |
34 | ) . |
35 | ( new FieldsetLayout( [ |
36 | 'items' => [ new FieldLayout( |
37 | new TextInputWidget( |
38 | [ |
39 | 'name' => 'intendedFileName', |
40 | 'value' => $filenameValue, |
41 | 'suggestions' => false, |
42 | 'autofocus' => true, |
43 | 'required' => true, |
44 | ] |
45 | ), |
46 | [ |
47 | 'align' => 'top', |
48 | 'label' => $this->msg( 'fileimporter-newfilename' )->plain(), |
49 | ] |
50 | ) ] |
51 | ] ) ) . |
52 | // TODO allow changing the case of the file extension |
53 | Html::element( |
54 | 'p', |
55 | [], |
56 | $this->msg( 'fileimporter-extensionlabel' )->plain() . |
57 | ' .' . $importPlan->getFileExtension() |
58 | ) . |
59 | ( new ImportIdentityFormSnippet( [ |
60 | 'clientUrl' => $importPlan->getRequest()->getUrl(), |
61 | 'intendedWikitext' => $importPlan->getFileInfoText(), |
62 | 'actionStats' => json_encode( $importPlan->getActionStats() ), |
63 | 'validationWarnings' => json_encode( $importPlan->getValidationWarnings() ), |
64 | 'importDetailsHash' => $importPlan->getRequest()->getImportDetailsHash(), |
65 | 'intendedRevisionSummary' => $importPlan->getRequest()->getIntendedSummary(), |
66 | 'automateSourceWikiCleanup' => $importPlan->getAutomateSourceWikiCleanUp(), |
67 | 'automateSourceWikiDelete' => $importPlan->getAutomateSourceWikiDelete(), |
68 | ] ) )->getHtml() . |
69 | new ButtonInputWidget( |
70 | [ |
71 | 'classes' => [ 'mw-importfile-backButton' ], |
72 | 'label' => $this->msg( 'fileimporter-submit-title' )->plain(), |
73 | 'type' => 'submit', |
74 | 'flags' => [ 'primary', 'progressive' ], |
75 | ] |
76 | ) . |
77 | Html::closeElement( 'form' ); |
78 | } |
79 | |
80 | } |