3 require_once __DIR__
. '/Maintenance.php';
6 * Maintenance script for importing site definitions from XML into the sites table.
10 * @license GPL-2.0-or-later
11 * @author Daniel Kinzler
13 class ImportSites
extends Maintenance
{
15 public function __construct() {
16 parent
::__construct();
18 $this->addDescription( 'Imports site definitions from XML into the sites table.' );
20 $this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.md). ' .
21 'Use "php://stdin" to read from stdin.', true
28 public function execute() {
29 $file = $this->getArg( 0 );
31 $siteStore = \MediaWiki\MediaWikiServices
::getInstance()->getSiteStore();
32 $importer = new SiteImporter( $siteStore );
33 $importer->setExceptionCallback( [ $this, 'reportException' ] );
35 $importer->importFromFile( $file );
37 $this->output( "Done.\n" );
41 * Outputs a message via the output() method.
43 * @param Exception $ex
45 public function reportException( Exception
$ex ) {
46 $msg = $ex->getMessage();
47 $this->output( "$msg\n" );
51 $maintClass = ImportSites
::class;
52 require_once RUN_MAINTENANCE_IF_MAIN
;