| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
require_once __DIR__ . '/Maintenance.php'; |
| 5 |
|
| 6 |
|
| 7 |
use MediaWiki\Site\SiteImporter; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class ImportSites extends Maintenance { |
| 18 |
|
| 19 |
public function __construct() { |
| 20 |
parent::__construct(); |
| 21 |
|
| 22 |
$this->addDescription( 'Imports site definitions from XML into the sites table.' ); |
| 23 |
|
| 24 |
$this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.md). ' . |
| 25 |
'Use "php://stdin" to read from stdin.', true |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function execute() { |
| 33 |
$file = $this->getArg( 0 ); |
| 34 |
|
| 35 |
$siteStore = $this->getServiceContainer()->getSiteStore(); |
| 36 |
$importer = new SiteImporter( $siteStore ); |
| 37 |
$importer->setExceptionCallback( [ $this, 'reportException' ] ); |
| 38 |
|
| 39 |
$importer->importFromFile( $file ); |
| 40 |
|
| 41 |
$this->output( "Done.\n" ); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function reportException( Exception $ex ) { |
| 50 |
$msg = $ex->getMessage(); |
| 51 |
$this->output( "$msg\n" ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
$maintClass = ImportSites::class; |
| 57 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 58 |
|