MediaWiki REL1_39
exportSites.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/Maintenance.php';
4
13class ExportSites extends Maintenance {
14
15 public function __construct() {
16 parent::__construct();
17
18 $this->addDescription( 'Exports site definitions the sites table to XML file' );
19
20 $this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.md). ' .
21 'Use "php://stdout" to write to stdout.', true
22 );
23 }
24
28 public function execute() {
29 $file = $this->getArg( 0 );
30
31 if ( $file === 'php://output' || $file === 'php://stdout' ) {
32 $this->mQuiet = true;
33 }
34
35 $handle = fopen( $file, 'w' );
36
37 if ( !$handle ) {
38 $this->fatalError( "Failed to open $file for writing.\n" );
39 }
40
41 $exporter = new SiteExporter( $handle );
42
43 $siteLookup = \MediaWiki\MediaWikiServices::getInstance()->getSiteLookup();
44 $exporter->exportSites( $siteLookup->getSites() );
45
46 fclose( $handle );
47
48 $this->output( "Exported sites to " . realpath( $file ) . ".\n" );
49 }
50
51}
52
53$maintClass = ExportSites::class;
54require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script for exporting site definitions from XML into the sites table.
__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)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
$maintClass
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42