MediaWiki REL1_37
importSites.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/Maintenance.php';
4
13class ImportSites extends Maintenance {
14
15 public function __construct() {
16 $this->addDescription( 'Imports site definitions from XML into the sites table.' );
17
18 $this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.md). ' .
19 'Use "php://stdin" to read from stdin.', true
20 );
21
22 parent::__construct();
23 }
24
28 public function execute() {
29 $file = $this->getArg( 0 );
30
31 $siteStore = \MediaWiki\MediaWikiServices::getInstance()->getSiteStore();
32 $importer = new SiteImporter( $siteStore );
33 $importer->setExceptionCallback( [ $this, 'reportException' ] );
34
35 $importer->importFromFile( $file );
36
37 $this->output( "Done.\n" );
38 }
39
45 public function reportException( Exception $ex ) {
46 $msg = $ex->getMessage();
47 $this->output( "$msg\n" );
48 }
49}
50
51$maintClass = ImportSites::class;
52require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script for importing site definitions from XML into the sites table.
reportException(Exception $ex)
Outputs a message via the output() method.
execute()
Do the import.
__construct()
Default constructor.
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.
$maintClass
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42