importStreamSource = ImportStreamSource::newFromFile( $file ); if ( !$this->importStreamSource->isGood() ) { $this->fail( "Import source for {$file} failed" ); } } private function doImport(): void { $services = $this->getServiceContainer(); if ( version_compare( MW_VERSION, '1.42', '>=' ) ) { $file = dirname( __DIR__ ) . '/seed-data.xml'; $this->seedTestUsers( $file ); $importer = $services->getWikiImporterFactory()->getWikiImporter( $this->importStreamSource->value, $this->getTestSysop()->getAuthority() ); } else { if ( self::$wasSeedDataImported ) { return; } self::$wasSeedDataImported = true; $file = dirname( __DIR__ ) . '/seed-data.xml'; $this->seedTestUsers( $file ); $importer = $services->getWikiImporterFactory()->getWikiImporter( $this->importStreamSource->value ); } $importer->disableStatisticsUpdate(); // Ensure we actually create local user accounts in the DB $importer->setUsernamePrefix( '', true ); $importer->doImport(); } /** * Import test accounts from seed data so that DPL queries can refer to them. * @param string $seedDataPath - path to seed data to be loaded */ private function seedTestUsers( string $seedDataPath ): void { $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; $doc->load( $seedDataPath ); $xpath = new DOMXPath( $doc ); $xpath->registerNamespace( 'mw', 'http://www.mediawiki.org/xml/export-0.11/' ); $userNodes = $xpath->query( '//mw:mediawiki/mw:page/mw:revision/mw:contributor/mw:username' ); $usersByName = []; $authManager = $this->getServiceContainer()->getAuthManager(); foreach ( $userNodes as $node ) { $userName = $node->nodeValue; // Already created if ( isset( $usersByName[$userName] ) ) { continue; } $usersByName[$userName] = true; $user = $this->newUserFromName( $userName ); if ( !$user || $user->idForName() !== 0 ) { // sanity return; } $status = $authManager->autoCreateUser( $user, $authManager::AUTOCREATE_SOURCE_MAINT, false ); if ( !$status->isOK() ) { return; } } } private function newUserFromName( string $name ): ?User { $services = $this->getServiceContainer(); return $services->getUserFactory()->newFromName( $name, UserFactory::RIGOR_CREATABLE ); } /** * Convenience function to return the list of page titles matching a DPL query * @param array $params - DPL invocation parameters * @param string $format * @return string[] */ protected function getDPLQueryResults( array $params, string $format = '%PAGE%' ): array { $params += [ // Use a custom format for executing the query to allow easily extracting results 'format' => "