16use Wikimedia\Assert\Assert;
17use Wikimedia\Parsoid\Config\PageConfig;
18use Wikimedia\Parsoid\Parsoid;
35 private $pageConfigFactory;
38 private $languageConverterFactory;
41 private $legacyParserFactory;
44 private $globalIdGenerator;
60 $this->parsoid = $parsoid;
61 $this->pageConfigFactory = $pageConfigFactory;
62 $this->languageConverterFactory = $languageConverterFactory;
63 $this->legacyParserFactory = $legacyParserFactory;
64 $this->globalIdGenerator = $globalIdGenerator;
72 private function setParsoidRenderID(
int $revId,
ParserOutput $parserOutput ): void {
73 $parserOutput->setParsoidRenderId(
89 private function genParserOutput(
99 $htmlVariantLanguage =
null;
122 $langCode = $pageConfig->getPageLanguageBcp47();
125 $lang = $langFactory->getLanguage( $langCode );
126 $langConv = $this->languageConverterFactory->getLanguageConverter( $lang );
127 $htmlVariantLanguage = $langFactory->getLanguage( $langConv->getPreferredVariant() );
129 $htmlVariantLanguage = $langCode;
139 'pageBundle' =>
true,
140 'wrapSections' =>
true,
141 'logLinterData' =>
true,
142 'body_only' =>
false,
143 'htmlVariantLanguage' => $htmlVariantLanguage,
144 'offsetType' =>
'byte',
145 'outputContentVersion' => Parsoid::defaultHTMLVersion()
150 $pageBundle = $this->parsoid->wikitext2html(
162 $revId = $pageConfig->getRevisionId();
163 if ( $revId !==
null ) {
164 $this->setParsoidRenderID( $revId, $parserOutput );
176 $this->makeLimitReport( $options, $parserOutput );
182 'core:parsoid-version', Parsoid::version()
185 return $parserOutput;
208 bool $linestart =
true,
bool $clearState =
true, ?
int $revId =
null
210 Assert::invariant( $linestart,
'$linestart=false is not yet supported' );
211 Assert::invariant( $clearState,
'$clearState=false is not yet supported' );
212 $title = Title::newFromPageReference( $page );
217 $pageConfig = $revId ===
null ? null : $this->pageConfigFactory->create(
224 if ( !( $pageConfig && $pageConfig->getPageMainContent() === $text ) ) {
230 if ( $revId !==
null ) {
231 $revisionRecord->setId( $revId );
233 $revisionRecord->setSlot(
234 SlotRecord::newUnsaved(
239 $pageConfig = $this->pageConfigFactory->create(
248 return $this->genParserOutput( $pageConfig, $options );
266 $title =
Title::newFromPageReference( $page );
271 $pageConfig = $this->pageConfigFactory->create(
279 return $this->genParserOutput( $pageConfig, $options );
293 if ( $cpuTime !==
null ) {
295 sprintf(
"%.3f", $cpuTime )
301 sprintf(
"%.3f", $wallTime )
304 $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.
getWrapOutputClass()
Class to use to wrap output from Parser::parse()
registerWatcher( $callback)
Registers a callback for tracking which ParserOptions which are used.
getInterfaceMessage()
Parsing an interface message?
Rendered output of a wiki page, as parsed from wikitext.
addWrapperDivClass( $class)
Add a CSS class to use for the wrapping div.
setLimitReportData( $key, $value)
Sets parser limit report data for a key.
hasReducedExpiry()
Check whether the cache TTL was lowered from the site default.
setExtensionData( $key, $value)
Attaches arbitrary data to this ParserObject.
getTimeSinceStart( $clock)
Returns the time since resetParseStartTime() was last called.
Content object for wiki text pages.