3 // @codeCoverageIgnoreStart
4 require_once __DIR__
. '/Maintenance.php';
5 // @codeCoverageIgnoreEnd
7 use MediaWiki\Maintenance\Maintenance
;
8 use MediaWiki\Site\SiteExporter
;
11 * Maintenance script for exporting site definitions from the sites table to XML.
15 * @license GPL-2.0-or-later
16 * @author Daniel Kinzler
18 class ExportSites
extends Maintenance
{
20 public function __construct() {
21 parent
::__construct();
23 $this->addDescription( 'Exports site definitions from the sites table to XML file' );
25 $this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.md). ' .
26 'Use "php://stdout" to write to stdout.', true
31 * Do the actual work. All child classes will need to implement this
33 public function execute() {
34 $file = $this->getArg( 0 );
36 if ( $file === 'php://output' ||
$file === 'php://stdout' ) {
40 $handle = fopen( $file, 'w' );
43 $this->fatalError( "Failed to open $file for writing.\n" );
46 $exporter = new SiteExporter( $handle );
48 $siteLookup = $this->getServiceContainer()->getSiteLookup();
49 $exporter->exportSites( $siteLookup->getSites() );
53 $this->output( "Exported sites to " . realpath( $file ) . ".\n" );
58 // @codeCoverageIgnoreStart
59 $maintClass = ExportSites
::class;
60 require_once RUN_MAINTENANCE_IF_MAIN
;
61 // @codeCoverageIgnoreEnd