20use Wikimedia\Assert\Assert;
21use Wikimedia\Parsoid\Config\PageConfig;
22use Wikimedia\Parsoid\Parsoid;
40 private Parsoid $parsoid;
57 $this->parsoid = $parsoid;
58 $this->pageConfigFactory = $pageConfigFactory;
59 $this->languageConverterFactory = $languageConverterFactory;
60 $this->legacyParserFactory = $legacyParserFactory;
70 private function genParserOutput(
86 $htmlVariantLanguage =
null;
109 $langCode = $pageConfig->getPageLanguageBcp47();
112 $lang = $langFactory->getLanguage( $langCode );
113 $langConv = $this->languageConverterFactory->getLanguageConverter( $lang );
114 $htmlVariantLanguage = $langFactory->getLanguage( $langConv->getPreferredVariant() );
116 $htmlVariantLanguage = $langCode;
119 $oldPageConfig =
null;
120 $oldPageBundle =
null;
127 $doSample = ( $sampleRate && mt_rand( 1, $sampleRate ) === 1 );
128 if ( $doSample && $previousOutput !==
null && $previousOutput->
getCacheRevisionId() ) {
131 $oldPageConfig = $this->pageConfigFactory->create(
132 Title::newFromLinkTarget( $pageConfig->getLinkTarget() ),
145 'pageBundle' =>
true,
146 'wrapSections' =>
true,
147 'logLinterData' =>
true,
148 'body_only' =>
false,
149 'htmlVariantLanguage' => $htmlVariantLanguage,
150 'offsetType' =>
'byte',
151 'outputContentVersion' => Parsoid::defaultHTMLVersion(),
152 'previousOutput' => $oldPageBundle,
153 'previousInput' => $oldPageConfig,
154 'sampleStats' => $doSample,
158 $parserOutput->resetParseStartTime();
162 $pageBundle = $this->parsoid->wikitext2html(
172 $parserOutput->setExtensionData(
173 self::PARSOID_TITLE_KEY,
174 Title::newFromLinkTarget( $pageConfig->getLinkTarget() )->getPrefixedDBkey()
181 $parserOutput->setFromParserOptions( $options );
183 $parserOutput->recordTimeProfile();
190 'type' => $previousOutput ===
null ?
'full' :
'selective',
191 'wiki' => WikiMap::getCurrentWikiId(),
195 ->getCounter(
'Parsoid_parse_cpu_seconds' )
196 ->setLabels( $labels )
197 ->incrementBy( $parserOutput->getTimeProfile(
'cpu' ) );
199 ->getCounter(
'Parsoid_parse_total' )
200 ->setLabels( $labels )
204 $parserOutput->addModuleStyles( [
'mediawiki.skinning.content.parsoid' ] );
209 $parserOutput->setExtensionData(
210 'core:parsoid-version', Parsoid::version()
212 $parserOutput->setExtensionData(
213 'core:html-version', Parsoid::defaultHTMLVersion()
216 return $parserOutput;
241 bool $linestart =
true,
bool $clearState =
true, ?
int $revId =
null,
244 Assert::invariant( $linestart,
'$linestart=false is not yet supported' );
245 Assert::invariant( $clearState,
'$clearState=false is not yet supported' );
246 $title = Title::newFromPageReference( $page );
251 $pageConfig = $revId ===
null || $revId === 0 ? null : $this->pageConfigFactory->create(
261 $text = $content->getText();
263 if ( !( $pageConfig && $pageConfig->getPageMainContent() === $text ) ) {
269 if ( $revId !==
null ) {
270 $revisionRecord->setId( $revId );
272 $revisionRecord->setSlot(
273 SlotRecord::newUnsaved(
275 $content ??
new WikitextContent( $text )
278 $pageConfig = $this->pageConfigFactory->create(
287 return $this->genParserOutput( $pageConfig, $options, $previousOutput );
306 $title = Title::newFromPageReference( $page );
311 $pageConfig = $this->pageConfigFactory->create(
319 return $this->genParserOutput( $pageConfig, $options,
null );
333 if ( $cpuTime !==
null ) {
335 sprintf(
"%.3f", $cpuTime )
341 sprintf(
"%.3f", $wallTime )
344 $parserOutput->
setLimitReportData(
'limitreport-timingprofile', [
'not yet supported' ] );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Content object implementation for representing flat text.
Content object for wiki text pages.
A class containing constants representing the names of configuration variables.
const ParsoidSelectiveUpdateSampleRate
Name constant for the ParsoidSelectiveUpdateSampleRate setting, for use with Config::get()
Helper class used by MediaWiki to create Parsoid PageConfig objects.
static pageBundleFromParserOutput(ParserOutput $parserOutput)
Returns a Parsoid PageBundle equivalent to the given ParserOutput.
static parserOutputFromPageBundle(PageBundle $pageBundle, ?ParserOutput $originalParserOutput=null)
Creates a ParserOutput object containing the relevant data from the given PageBundle object.