20 private WikiExporter $wikiExporter;
21 private ?Closure $exportPageCallback;
23 public function __construct(
25 WikiExporterFactory $wikiExporterFactory,
26 IConnectionProvider $dbProvider
28 $this->wikiExporter = $wikiExporterFactory->getWikiExporter(
29 $dbProvider->getReplicaDatabase(),
34 public function export(
TranslatableBundle $bundle,
bool $includeTalkPages,
bool $includeSubPages ):
string {
35 $classifiedSubpages = $this->subpageListBuilder->getSubpagesPerType( $bundle, $includeTalkPages );
37 $sink =
new DumpStringOutput();
38 $this->wikiExporter->setOutputSink( $sink );
39 $this->wikiExporter->openStream();
42 $this->exportPages( [ $bundle->
getTitle() ],
'translatable bundle' );
43 $this->exportPages( $classifiedSubpages[
'translationPages' ],
'translation' );
44 $this->exportPages( $classifiedSubpages[
'translationUnitPages' ],
'translation unit' );
47 $talkPages = $includeTalkPages ? $classifiedSubpages[
'talkPages' ] : [];
48 $talkPages = array_filter( $talkPages,
static function ( $val ) {
51 $this->exportPages( $talkPages,
'talk pages' );
54 $includeTalkPages ? $classifiedSubpages[
'translatableTalkPages' ] : [],
58 $includeSubPages ? $classifiedSubpages[
'normalSubpages' ] : [],
62 $this->wikiExporter->closeStream();
67 public function setExportPageCallback( callable $callable ) {
68 $this->exportPageCallback = Closure::fromCallable( $callable );
75 private function exportPages( array $pagesForExport,
string $pageType ):
void {
76 if ( $this->exportPageCallback ) {
77 ( $this->exportPageCallback )( $pagesForExport, $pageType );
80 foreach ( $pagesForExport as $page ) {
81 $this->wikiExporter->pageByTitle( $page );