Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.45% |
42 / 44 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ChangeFileNameForm | |
95.45% |
42 / 44 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| getHtml | |
95.45% |
42 / 44 |
|
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 ) { |
| 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 | ImportIdentityFormSnippet::newFromImportPlan( $importPlan, [ 'intendedFileName' ] ) |
| 60 | ->getHtml() . |
| 61 | new ButtonInputWidget( |
| 62 | [ |
| 63 | 'classes' => [ 'mw-importfile-backButton' ], |
| 64 | 'label' => $this->msg( 'fileimporter-submit-title' )->plain(), |
| 65 | 'type' => 'submit', |
| 66 | 'flags' => [ 'primary', 'progressive' ], |
| 67 | ] |
| 68 | ) . |
| 69 | Html::closeElement( 'form' ); |
| 70 | } |
| 71 | |
| 72 | } |