| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
require_once __DIR__ . '/Maintenance.php'; |
| 5 |
|
| 6 |
|
| 7 |
use MediaWiki\Site\SiteExporter; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class ExportSites extends Maintenance { |
| 18 |
|
| 19 |
public function __construct() { |
| 20 |
parent::__construct(); |
| 21 |
|
| 22 |
$this->addDescription( 'Exports site definitions from the sites table to XML file' ); |
| 23 |
|
| 24 |
$this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.md). ' . |
| 25 |
'Use "php://stdout" to write to stdout.', true |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function execute() { |
| 33 |
$file = $this->getArg( 0 ); |
| 34 |
|
| 35 |
if ( $file === 'php://output' || $file === 'php://stdout' ) { |
| 36 |
$this->mQuiet = true; |
| 37 |
} |
| 38 |
|
| 39 |
$handle = fopen( $file, 'w' ); |
| 40 |
|
| 41 |
if ( !$handle ) { |
| 42 |
$this->fatalError( "Failed to open $file for writing.\n" ); |
| 43 |
} |
| 44 |
|
| 45 |
$exporter = new SiteExporter( $handle ); |
| 46 |
|
| 47 |
$siteLookup = $this->getServiceContainer()->getSiteLookup(); |
| 48 |
$exporter->exportSites( $siteLookup->getSites() ); |
| 49 |
|
| 50 |
fclose( $handle ); |
| 51 |
|
| 52 |
$this->output( "Exported sites to " . realpath( $file ) . ".\n" ); |
| 53 |
} |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
$maintClass = ExportSites::class; |
| 59 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 60 |
|