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  $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;
52 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:44
ImportSites\reportException
reportException(Exception $ex)
Outputs a message via the output() method.
Definition: importSites.php:45
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:327
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
SiteImporter
Definition: SiteImporter.php:30
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:55
ImportSites\__construct
__construct()
Default constructor.
Definition: importSites.php:15
ImportSites
Maintenance script for importing site definitions from XML into the sites table.
Definition: importSites.php:13
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:298
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:433
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:351
ImportSites\execute
execute()
Do the import.
Definition: importSites.php:28
$maintClass
$maintClass
Definition: importSites.php:51