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 'core:html-version', Parsoid::defaultHTMLVersion()
193 return $parserOutput;
216 bool $linestart =
true,
bool $clearState =
true, ?
int $revId =
null
218 Assert::invariant( $linestart,
'$linestart=false is not yet supported' );
219 Assert::invariant( $clearState,
'$clearState=false is not yet supported' );
220 $title = Title::newFromPageReference( $page );
225 $pageConfig = $revId ===
null ? null : $this->pageConfigFactory->create(
232 if ( !( $pageConfig && $pageConfig->getPageMainContent() === $text ) ) {
238 if ( $revId !==
null ) {
239 $revisionRecord->setId( $revId );
241 $revisionRecord->setSlot(
242 SlotRecord::newUnsaved(
247 $pageConfig = $this->pageConfigFactory->create(
256 return $this->genParserOutput( $pageConfig, $options );
274 $title =
Title::newFromPageReference( $page );
279 $pageConfig = $this->pageConfigFactory->create(
287 return $this->genParserOutput( $pageConfig, $options );
301 if ( $cpuTime !==
null ) {
303 sprintf(
"%.3f", $cpuTime )
309 sprintf(
"%.3f", $wallTime )
312 $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.