Localisation updates from https://translatewiki.net.
[mediawiki.git] / maintenance / exportSites.php
blob4adcf14eb5790894ed19c53a0e4bfe9e8e7cac06
1 <?php
3 // @codeCoverageIgnoreStart
4 require_once __DIR__ . '/Maintenance.php';
5 // @codeCoverageIgnoreEnd
7 use MediaWiki\Maintenance\Maintenance;
8 use MediaWiki\Site\SiteExporter;
10 /**
11 * Maintenance script for exporting site definitions from the sites table to XML.
13 * @since 1.25
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
30 /**
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' ) {
37 $this->mQuiet = true;
40 $handle = fopen( $file, 'w' );
42 if ( !$handle ) {
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() );
51 fclose( $handle );
53 $this->output( "Exported sites to " . realpath( $file ) . ".\n" );
58 // @codeCoverageIgnoreStart
59 $maintClass = ExportSites::class;
60 require_once RUN_MAINTENANCE_IF_MAIN;
61 // @codeCoverageIgnoreEnd