MediaWiki  master
importSites.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . '/Maintenance.php';
4 
13 class ImportSites extends Maintenance {
14 
15  public function __construct() {
16  parent::__construct();
17 
18  $this->addDescription( 'Imports site definitions from XML into the sites table.' );
19 
20  $this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.md). ' .
21  'Use "php://stdin" to read from stdin.', true
22  );
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;
52 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script for importing site definitions from XML into the sites table.
Definition: importSites.php:13
reportException(Exception $ex)
Outputs a message via the output() method.
Definition: importSites.php:45
execute()
Do the import.
Definition: importSites.php:28
__construct()
Default constructor.
Definition: importSites.php:15
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:66
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
Definition: importSites.php:51
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42