2015-02-02 10:58:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2021-01-08 02:16:02 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2015-02-02 10:58:14 +00:00
|
|
|
|
2023-12-14 18:36:16 +00:00
|
|
|
use MediaWiki\Site\SiteExporter;
|
|
|
|
|
|
2015-02-02 10:58:14 +00:00
|
|
|
/**
|
2024-09-16 10:48:43 +00:00
|
|
|
* Maintenance script for exporting site definitions from the sites table to XML.
|
2015-02-02 10:58:14 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.25
|
|
|
|
|
*
|
2018-05-23 23:23:42 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2015-02-02 10:58:14 +00:00
|
|
|
* @author Daniel Kinzler
|
|
|
|
|
*/
|
|
|
|
|
class ExportSites extends Maintenance {
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
2022-07-31 20:08:45 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
|
2024-09-16 10:48:43 +00:00
|
|
|
$this->addDescription( 'Exports site definitions from the sites table to XML file' );
|
2015-02-02 10:58:14 +00:00
|
|
|
|
2020-01-05 22:22:48 +00:00
|
|
|
$this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.md). ' .
|
2015-06-15 06:35:58 +00:00
|
|
|
'Use "php://stdout" to write to stdout.', true
|
|
|
|
|
);
|
2015-02-02 10:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do the actual work. All child classes will need to implement this
|
|
|
|
|
*/
|
|
|
|
|
public function execute() {
|
|
|
|
|
$file = $this->getArg( 0 );
|
|
|
|
|
|
|
|
|
|
if ( $file === 'php://output' || $file === 'php://stdout' ) {
|
|
|
|
|
$this->mQuiet = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$handle = fopen( $file, 'w' );
|
|
|
|
|
|
2015-06-17 20:01:00 +00:00
|
|
|
if ( !$handle ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Failed to open $file for writing.\n" );
|
2015-02-02 10:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$exporter = new SiteExporter( $handle );
|
|
|
|
|
|
2023-08-31 09:21:12 +00:00
|
|
|
$siteLookup = $this->getServiceContainer()->getSiteLookup();
|
2015-10-12 08:05:45 +00:00
|
|
|
$exporter->exportSites( $siteLookup->getSites() );
|
2015-02-02 10:58:14 +00:00
|
|
|
|
|
|
|
|
fclose( $handle );
|
|
|
|
|
|
|
|
|
|
$this->output( "Exported sites to " . realpath( $file ) . ".\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = ExportSites::class;
|
2015-06-17 20:01:00 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|