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