2declare( strict_types = 1 );
15use Wikimedia\Bcp47Code\Bcp47Code;
16use Wikimedia\Parsoid\Config\SiteConfig;
17use Wikimedia\Parsoid\Core\HtmlPageBundle;
24 private readonly
Title $pageTitle;
28 private ?
Language $pageLanguageOverride =
null;
36 private readonly SiteConfig $siteConfig,
50 $this->pageLanguageOverride = $this->languageFactory->getLanguage(
67 HtmlPageBundle $pageBundle,
68 Bcp47Code $targetVariant,
69 ?Bcp47Code $sourceVariant =
null
72 $pageBundle, title: $this->pageIdentity,
73 siteConfig: $this->siteConfig
76 $parserOutput, $targetVariant, $sourceVariant
79 $modifiedParserOutput,
80 siteConfig: $this->siteConfig,
96 Bcp47Code $targetVariant,
97 ?Bcp47Code $sourceVariant =
null
99 if ( !$parserOutput->getContentHolder()->isParsoidContent() ) {
101 return $parserOutput;
103 $targetVariant = $this->languageFactory->getLanguage( $targetVariant );
105 $popts->setVariant( $targetVariant );
106 $popts->setUseParsoid(
true );
107 $parent = fn ( $l ) => $l ===
null ? null :
108 $this->languageFactory->getParentLanguage( $l ) ??
109 $this->languageFactory->getLanguage( $l );
110 $popts->setTargetLanguage(
111 $parent( $sourceVariant ) ??
112 $parent( $this->pageLanguageOverride ) ??
113 $parent( $parserOutput->getLanguage() ) ??
114 $this->pageTitle->getPageLanguage()
119 $parserOutput->setExtensionData(
120 'core:parsoid-languageconverter',
'postprocess'
122 return $this->languageConverterPipeline->run(
123 $parserOutput, $popts, []
if(!defined('MW_SETUP_CALLBACK'))
Provides methods for conversion between HtmlPageBundle and ParserOutput.
static htmlPageBundleFromParserOutput(ParserOutput $parserOutput, SiteConfig $siteConfig, bool $bodyOnly=false,)
Returns a Parsoid HtmlPageBundle equivalent to the given ParserOutput.
Interface for objects (potentially) representing an editable wiki page.