Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ExportPage | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\Gadgets\Special; |
| 4 | |
| 5 | use ErrorPageError; |
| 6 | use InvalidArgumentException; |
| 7 | use MediaWiki\Extension\Gadgets\GadgetRepo; |
| 8 | use MediaWiki\HTMLForm\HTMLForm; |
| 9 | use MediaWiki\MainConfigNames; |
| 10 | use MediaWiki\SpecialPage\SpecialPage; |
| 11 | |
| 12 | class ExportPage extends ActionPage { |
| 13 | |
| 14 | public function __construct( |
| 15 | SpecialGadgets $specialPage, |
| 16 | private readonly GadgetRepo $gadgetRepo, |
| 17 | ) { |
| 18 | parent::__construct( $specialPage ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Exports a gadget with its dependencies in a serialized form |
| 23 | * @param array $params |
| 24 | */ |
| 25 | public function execute( array $params ) { |
| 26 | if ( !isset( $params[0] ) ) { |
| 27 | $this->specialPage->getOutput()->setStatusCode( 400 ); |
| 28 | throw new ErrorPageError( 'error', 'gadgets-subpage-toofewparams' ); |
| 29 | } |
| 30 | $gadget = $params[0]; |
| 31 | |
| 32 | $output = $this->specialPage->getOutput(); |
| 33 | try { |
| 34 | $g = $this->gadgetRepo->getGadget( $gadget ); |
| 35 | } catch ( InvalidArgumentException ) { |
| 36 | $output->showErrorPage( 'error', 'gadgets-not-found', [ $gadget ] ); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | $output->setPageTitleMsg( $this->msg( 'gadgets-export-title' ) ); |
| 41 | $output->addWikiMsg( 'gadgets-export-text', $gadget, $g->getDefinition() ); |
| 42 | |
| 43 | $exportList = "MediaWiki:gadget-$gadget\n"; |
| 44 | foreach ( $g->getScriptsAndStyles() as $page ) { |
| 45 | $exportList .= "$page\n"; |
| 46 | } |
| 47 | |
| 48 | $htmlForm = HTMLForm::factory( 'ooui', [], $this->specialPage->getContext() ); |
| 49 | $htmlForm |
| 50 | ->setTitle( SpecialPage::getTitleFor( 'Export' ) ) |
| 51 | ->addHiddenField( 'pages', $exportList ) |
| 52 | ->addHiddenField( 'wpDownload', '1' ) |
| 53 | ->addHiddenField( 'templates', '1' ) |
| 54 | ->setAction( $this->specialPage->getConfig()->get( MainConfigNames::Script ) ) |
| 55 | ->setMethod( 'get' ) |
| 56 | ->setSubmitText( $this->msg( 'gadgets-export-download' )->text() ) |
| 57 | ->prepareForm() |
| 58 | ->displayForm( false ); |
| 59 | } |
| 60 | |
| 61 | } |