X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/maintenance/importSites.php diff --git a/maintenance/importSites.php b/maintenance/importSites.php new file mode 100644 index 00000000..57223442 --- /dev/null +++ b/maintenance/importSites.php @@ -0,0 +1,54 @@ +addDescription( 'Imports site definitions from XML into the sites table.' ); + + $this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.txt). ' . + 'Use "php://stdin" to read from stdin.', true + ); + + parent::__construct(); + } + + /** + * Do the import. + */ + public function execute() { + $file = $this->getArg( 0 ); + + $siteStore = \MediaWiki\MediaWikiServices::getInstance()->getSiteStore(); + $importer = new SiteImporter( $siteStore ); + $importer->setExceptionCallback( [ $this, 'reportException' ] ); + + $importer->importFromFile( $file ); + + $this->output( "Done.\n" ); + } + + /** + * Outputs a message via the output() method. + * + * @param Exception $ex + */ + public function reportException( Exception $ex ) { + $msg = $ex->getMessage(); + $this->output( "$msg\n" ); + } +} + +$maintClass = 'ImportSites'; +require_once RUN_MAINTENANCE_IF_MAIN;