Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
14 / 16 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ExportSites | |
87.50% |
14 / 16 |
|
50.00% |
1 / 2 |
5.05 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
81.82% |
9 / 11 |
|
0.00% |
0 / 1 |
4.10 | |||
| 1 | <?php |
| 2 | |
| 3 | // @codeCoverageIgnoreStart |
| 4 | require_once __DIR__ . '/Maintenance.php'; |
| 5 | // @codeCoverageIgnoreEnd |
| 6 | |
| 7 | use MediaWiki\Maintenance\Maintenance; |
| 8 | use MediaWiki\Site\SiteExporter; |
| 9 | |
| 10 | /** |
| 11 | * Maintenance script for exporting site definitions from the sites table to XML. |
| 12 | * |
| 13 | * @since 1.25 |
| 14 | * |
| 15 | * @license GPL-2.0-or-later |
| 16 | * @author Daniel Kinzler |
| 17 | */ |
| 18 | class ExportSites extends Maintenance { |
| 19 | |
| 20 | public function __construct() { |
| 21 | parent::__construct(); |
| 22 | |
| 23 | $this->addDescription( 'Exports site definitions from the sites table to XML file' ); |
| 24 | |
| 25 | $this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.md). ' . |
| 26 | 'Use "php://stdout" to write to stdout.', true |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Do the actual work. All child classes will need to implement this |
| 32 | */ |
| 33 | public function execute() { |
| 34 | $file = $this->getArg( 0 ); |
| 35 | |
| 36 | if ( $file === 'php://output' || $file === 'php://stdout' ) { |
| 37 | $this->mQuiet = true; |
| 38 | } |
| 39 | |
| 40 | $handle = fopen( $file, 'w' ); |
| 41 | |
| 42 | if ( !$handle ) { |
| 43 | $this->fatalError( "Failed to open $file for writing.\n" ); |
| 44 | } |
| 45 | |
| 46 | $exporter = new SiteExporter( $handle ); |
| 47 | |
| 48 | $siteLookup = $this->getServiceContainer()->getSiteLookup(); |
| 49 | $exporter->exportSites( $siteLookup->getSites() ); |
| 50 | |
| 51 | fclose( $handle ); |
| 52 | |
| 53 | $this->output( "Exported sites to " . realpath( $file ) . ".\n" ); |
| 54 | } |
| 55 | |
| 56 | } |
| 57 | |
| 58 | // @codeCoverageIgnoreStart |
| 59 | $maintClass = ExportSites::class; |
| 60 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 61 | // @codeCoverageIgnoreEnd |