20 private WikiExporter $wikiExporter;
22 private ?Closure $exportPageCallback;
24 public function __construct(
26 WikiExporterFactory $wikiExporterFactory,
27 IConnectionProvider $dbProvider
29 $this->wikiExporter = $wikiExporterFactory->getWikiExporter(
30 $dbProvider->getReplicaDatabase(),
35 public function export(
TranslatableBundle $bundle,
bool $includeTalkPages,
bool $includeSubPages ):
string {
36 $classifiedSubpages = $this->subpageListBuilder->getSubpagesPerType( $bundle, $includeTalkPages );
38 $sink =
new DumpStringOutput();
39 $this->wikiExporter->setOutputSink( $sink );
40 $this->wikiExporter->openStream();
43 $this->exportPages( [ $bundle->
getTitle() ],
'translatable bundle' );
44 $this->exportPages( $classifiedSubpages[
'translationPages' ],
'translation' );
45 $this->exportPages( $classifiedSubpages[
'translationUnitPages' ],
'translation unit' );
48 $talkPages = $includeTalkPages ? $classifiedSubpages[
'talkPages' ] : [];
49 $talkPages = array_filter( $talkPages,
static function ( $val ) {
52 $this->exportPages( $talkPages,
'talk pages' );
55 $includeTalkPages ? $classifiedSubpages[
'translatableTalkPages' ] : [],
59 $includeSubPages ? $classifiedSubpages[
'normalSubpages' ] : [],
63 $this->wikiExporter->closeStream();
70 $this->exportPageCallback = Closure::fromCallable( $callable );
77 private function exportPages( array $pagesForExport,
string $pageType ): void {
78 if ( $this->exportPageCallback ) {
79 ( $this->exportPageCallback )( $pagesForExport, $pageType );
82 foreach ( $pagesForExport as $page ) {
83 $this->wikiExporter->pageByTitle( $page );