Debian Codegraph @

maintenance/exportSites.php

raw symbols SCIP
1 <?php
2
3 // @codeCoverageIgnoreStart
4 require_once __DIR__ . '/Maintenance.php';
5 // @codeCoverageIgnoreEnd
6
7 use MediaWiki\Site\SiteExporter;
8
9 /**
10 * Maintenance script for exporting site definitions from the sites table to XML.
11 *
12 * @since 1.25
13 *
14 * @license GPL-2.0-or-later
15 * @author Daniel Kinzler
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 * Do the actual work. All child classes will need to implement this
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 // @codeCoverageIgnoreStart
58 $maintClass = ExportSites::class;
59 require_once RUN_MAINTENANCE_IF_MAIN;
60 // @codeCoverageIgnoreEnd