MediaWiki  master
exportSites.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . '/Maintenance.php';
4 
13 class ExportSites extends Maintenance {
14 
15  public function __construct() {
16  $this->addDescription( 'Exports site definitions the sites table to XML file' );
17 
18  $this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.md). ' .
19  'Use "php://stdout" to write to stdout.', true
20  );
21 
22  parent::__construct();
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;
54 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:486
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:327
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:55
ExportSites\__construct
__construct()
Default constructor.
Definition: exportSites.php:15
ExportSites\execute
execute()
Do the actual work.
Definition: exportSites.php:28
$maintClass
$maintClass
Definition: exportSites.php:53
SiteExporter
Definition: SiteExporter.php:30
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:298
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:433
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:351
ExportSites
Maintenance script for exporting site definitions from XML into the sites table.
Definition: exportSites.php:13