16use Wikimedia\Assert\Assert;
17use Wikimedia\Parsoid\Config\PageConfig;
18use Wikimedia\Parsoid\Parsoid;
38 private Parsoid $parsoid;
58 $this->parsoid = $parsoid;
59 $this->pageConfigFactory = $pageConfigFactory;
60 $this->languageConverterFactory = $languageConverterFactory;
61 $this->legacyParserFactory = $legacyParserFactory;
62 $this->globalIdGenerator = $globalIdGenerator;
70 private function setParsoidRenderID( PageConfig $pageConfig,
ParserOutput $parserOutput ): void {
71 $parserOutput->setRenderId( $this->globalIdGenerator->newUUIDv1() );
84 private function genParserOutput(
100 $htmlVariantLanguage =
null;
123 $langCode = $pageConfig->getPageLanguageBcp47();
126 $lang = $langFactory->getLanguage( $langCode );
127 $langConv = $this->languageConverterFactory->getLanguageConverter( $lang );
128 $htmlVariantLanguage = $langFactory->getLanguage( $langConv->getPreferredVariant() );
130 $htmlVariantLanguage = $langCode;
135 'pageBundle' =>
true,
136 'wrapSections' =>
true,
137 'logLinterData' =>
true,
138 'body_only' =>
false,
139 'htmlVariantLanguage' => $htmlVariantLanguage,
140 'offsetType' =>
'byte',
141 'outputContentVersion' => Parsoid::defaultHTMLVersion()
148 $pageBundle = $this->parsoid->wikitext2html(
159 self::PARSOID_TITLE_KEY,
160 Title::newFromLinkTarget( $pageConfig->getLinkTarget() )->getPrefixedDBkey()
167 $revId = $pageConfig->getRevisionId();
168 if ( $revId !==
null ) {
172 $this->setParsoidRenderID( $pageConfig, $parserOutput );
178 $this->makeLimitReport( $options, $parserOutput );
181 $parserOutput->
addModuleStyles( [
'mediawiki.skinning.content.parsoid' ] );
187 'core:parsoid-version', Parsoid::version()
190 return $parserOutput;
213 bool $linestart =
true,
bool $clearState =
true, ?
int $revId =
null
215 Assert::invariant( $linestart,
'$linestart=false is not yet supported' );
216 Assert::invariant( $clearState,
'$clearState=false is not yet supported' );
217 $title = Title::newFromPageReference( $page );
222 $pageConfig = $revId ===
null ? null : $this->pageConfigFactory->create(
229 if ( !( $pageConfig && $pageConfig->getPageMainContent() === $text ) ) {
235 if ( $revId !==
null ) {
236 $revisionRecord->setId( $revId );
238 $revisionRecord->setSlot(
239 SlotRecord::newUnsaved(
244 $pageConfig = $this->pageConfigFactory->create(
253 return $this->genParserOutput( $pageConfig, $options );
271 $title =
Title::newFromPageReference( $page );
276 $pageConfig = $this->pageConfigFactory->create(
284 return $this->genParserOutput( $pageConfig, $options );
298 if ( $cpuTime !==
null ) {
300 sprintf(
"%.3f", $cpuTime )
306 sprintf(
"%.3f", $wallTime )
309 $parserOutput->
setLimitReportData(
'limitreport-timingprofile', [
'not yet supported' ] );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
setCacheTime( $t)
setCacheTime() sets the timestamp expressing when the page has been rendered.
getCacheExpiry()
Returns the number of seconds after which this object should expire.
Helper class used by MediaWiki to create Parsoid PageConfig objects.
static parserOutputFromPageBundle(PageBundle $pageBundle, ?ParserOutput $originalParserOutput=null)
Creates a ParserOutput object containing the relevant data from the given PageBundle object.
Set options of the Parser.
getRenderReason()
Returns reason for rendering the content.
getMaxIncludeSize()
Maximum size of template expansions, in bytes.
getUserLangObj()
Get the user language used by the parser for this page and split the parser cache.
getTargetLanguage()
Target language for the parse.
getUserIdentity()
Get the identity of the user for whom the parse is made.
getDisableContentConversion()
Whether content conversion should be disabled.
registerWatcher( $callback)
Registers a callback for tracking which ParserOptions which are used.
getInterfaceMessage()
Parsing an interface message?
Content object for wiki text pages.