2declare( strict_types = 1 );
9use MediaWiki\Languages\LanguageConverterFactory;
23use Wikimedia\Assert\Assert;
24use Wikimedia\Parsoid\Config\PageConfig;
25use Wikimedia\Parsoid\Parsoid;
45 private Parsoid $parsoid,
47 private readonly LanguageConverterFactory $languageConverterFactory,
59 private function genParserOutput(
75 $htmlVariantLanguage =
null;
98 $langCode = $pageConfig->getPageLanguageBcp47();
102 $lang = $langFactory->getLanguage( $langCode );
103 $langConv = $this->languageConverterFactory->getLanguageConverter( $lang );
104 $htmlVariantLanguage = $langFactory->getLanguage( $langConv->getPreferredVariant() );
106 $htmlVariantLanguage = $langCode;
109 $oldPageConfig =
null;
110 $oldPageBundle =
null;
117 $doSample = ( $sampleRate && mt_rand( 1, $sampleRate ) === 1 );
118 if ( $doSample && $previousOutput !==
null && $previousOutput->
getCacheRevisionId() ) {
121 $oldPageConfig = $this->pageConfigFactory->createFromParserOptions(
123 Title::newFromLinkTarget( $pageConfig->getLinkTarget() ),
134 'pageBundle' =>
true,
135 'wrapSections' =>
true,
136 'logLinterData' =>
true,
137 'body_only' =>
false,
138 'htmlVariantLanguage' => $htmlVariantLanguage,
139 'offsetType' =>
'byte',
140 'outputContentVersion' => Parsoid::defaultHTMLVersion(),
141 'previousOutput' => $oldPageBundle,
142 'previousInput' => $oldPageConfig,
144 'sampleStats' => $doSample,
146 'userAgent' => RequestContext::getMain()->getRequest()->getHeader(
'User-Agent' ),
149 $parserOutput->resetParseStartTime();
153 $pageBundle = $this->parsoid->wikitext2html(
163 $parserOutput->setTitle( $pageConfig->getLinkTarget() );
165 $parserOutput->setExtensionData(
166 self::PARSOID_TITLE_KEY,
167 Title::newFromLinkTarget( $pageConfig->getLinkTarget() )->getPrefixedDBkey()
174 $parserOutput->setFromParserOptions( $options );
176 $parserOutput->recordTimeProfile();
177 $this->dataAccess->makeLimitReport( $pageConfig, $options, $parserOutput );
183 'type' => $previousOutput ===
null ?
'full' :
'selective',
184 'wiki' => WikiMap::getCurrentWikiId(),
186 'has_async_content' =>
187 $parserOutput->getOutputFlag( ParserOutputFlags::HAS_ASYNC_CONTENT )
190 $parserOutput->getOutputFlag( ParserOutputFlags::ASYNC_NOT_READY )
194 ->getCounter(
'Parsoid_parse_cpu_seconds' )
195 ->setLabels( $labels )
196 ->incrementBy( $parserOutput->getTimeProfile(
'cpu' ) );
198 ->getCounter(
'Parsoid_parse_total' )
199 ->setLabels( $labels )
203 $parserOutput->addModuleStyles( [
'mediawiki.skinning.content.parsoid' ] );
208 $parserOutput->setExtensionData(
209 'core:parsoid-version', Parsoid::version()
211 $parserOutput->setExtensionData(
212 'core:html-version', Parsoid::defaultHTMLVersion()
215 $parserOutput->setJsConfigVar(
216 'wgParsoidHtmlVersion', Parsoid::defaultHTMLVersion()
219 return $parserOutput;
244 bool $linestart =
true,
bool $clearState =
true, ?
int $revId =
null,
247 Assert::invariant( $linestart,
'$linestart=false is not yet supported' );
248 Assert::invariant( $clearState,
'$clearState=false is not yet supported' );
249 $title = Title::newFromPageReference( $page );
254 $pageConfig = $revId ===
null || $revId === 0 ? null : $this->pageConfigFactory->createFromParserOptions(
263 $text = $content->getText();
265 if ( !( $pageConfig && $pageConfig->getPageMainContent() === $text ) ) {
271 if ( $revId !==
null ) {
272 $revisionRecord->setId( $revId );
274 $revisionRecord->setSlot(
275 SlotRecord::newUnsaved(
277 $content ??
new WikitextContent( $text )
280 $pageConfig = $this->pageConfigFactory->createFromParserOptions(
288 return $this->genParserOutput( $pageConfig, $options, $previousOutput );
307 $title = Title::newFromPageReference( $page );
312 $pageConfig = $this->pageConfigFactory->createFromParserOptions(
319 return $this->genParserOutput( $pageConfig, $options,
null );
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.
Group all the pieces relevant to the context of a request into one instance.
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 HtmlPageBundle equivalent to the given ParserOutput.
static parserOutputFromPageBundle(HtmlPageBundle $pageBundle, ?ParserOutput $originalParserOutput=null)
Creates a ParserOutput object containing the relevant data from the given HtmlPageBundle object.