MediaWiki master
exportSites.php
Go to the documentation of this file.
1<?php
2
3// @codeCoverageIgnoreStart
4require_once __DIR__ . '/Maintenance.php';
5// @codeCoverageIgnoreEnd
6
9
18class ExportSites extends Maintenance {
19
20 public function __construct() {
21 parent::__construct();
22
23 $this->addDescription( 'Exports site definitions from the sites table to XML file' );
24
25 $this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.md). ' .
26 'Use "php://stdout" to write to stdout.', true
27 );
28 }
29
33 public function execute() {
34 $file = $this->getArg( 0 );
35
36 if ( $file === 'php://output' || $file === 'php://stdout' ) {
37 $this->mQuiet = true;
38 }
39
40 $handle = fopen( $file, 'w' );
41
42 if ( !$handle ) {
43 $this->fatalError( "Failed to open $file for writing.\n" );
44 }
45
46 $exporter = new SiteExporter( $handle );
47
48 $siteLookup = $this->getServiceContainer()->getSiteLookup();
49 $exporter->exportSites( $siteLookup->getSites() );
50
51 fclose( $handle );
52
53 $this->output( "Exported sites to " . realpath( $file ) . ".\n" );
54 }
55
56}
57
58// @codeCoverageIgnoreStart
59$maintClass = ExportSites::class;
60require_once RUN_MAINTENANCE_IF_MAIN;
61// @codeCoverageIgnoreEnd
Maintenance script for exporting site definitions from the sites table to XML.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Utility for exporting site entries to XML.
$maintClass