exportSites.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. $basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) : __DIR__ . '/..';
  3. require_once $basePath . '/maintenance/Maintenance.php';
  4. /**
  5. * Maintenance script for exporting site definitions from XML into the sites table.
  6. *
  7. * @since 1.25
  8. *
  9. * @licence GNU GPL v2+
  10. * @author Daniel Kinzler
  11. */
  12. class ExportSites extends Maintenance {
  13. public function __construct() {
  14. $this->addDescription( 'Exports site definitions the sites table to XML file' );
  15. $this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.txt). ' .
  16. 'Use "php://stdout" to write to stdout.', true
  17. );
  18. parent::__construct();
  19. }
  20. /**
  21. * Do the actual work. All child classes will need to implement this
  22. */
  23. public function execute() {
  24. $file = $this->getArg( 0 );
  25. if ( $file === 'php://output' || $file === 'php://stdout' ) {
  26. $this->mQuiet = true;
  27. }
  28. $handle = fopen( $file, 'w' );
  29. if ( !$handle ) {
  30. $this->error( "Failed to open $file for writing.\n", 1 );
  31. }
  32. $exporter = new SiteExporter( $handle );
  33. $siteLookup = \MediaWiki\MediaWikiServices::getInstance()->getSiteLookup();
  34. $exporter->exportSites( $siteLookup->getSites() );
  35. fclose( $handle );
  36. $this->output( "Exported sites to " . realpath( $file ) . ".\n" );
  37. }
  38. }
  39. $maintClass = 'ExportSites';
  40. require_once RUN_MAINTENANCE_IF_MAIN;