2declare( strict_types = 1 );
9use MediaWiki\Languages\LanguageConverterFactory;
23use Wikimedia\Assert\Assert;
24use Wikimedia\Parsoid\Config\PageConfig;
25use Wikimedia\Parsoid\Parsoid;
43 private Parsoid $parsoid;
45 private LanguageConverterFactory $languageConverterFactory;
56 LanguageConverterFactory $languageConverterFactory,
59 $this->parsoid = $parsoid;
60 $this->pageConfigFactory = $pageConfigFactory;
61 $this->languageConverterFactory = $languageConverterFactory;
62 $this->dataAccess = $dataAccess;
72 private function genParserOutput(
88 $htmlVariantLanguage =
null;
111 $langCode = $pageConfig->getPageLanguageBcp47();
114 $lang = $langFactory->getLanguage( $langCode );
115 $langConv = $this->languageConverterFactory->getLanguageConverter( $lang );
116 $htmlVariantLanguage = $langFactory->getLanguage( $langConv->getPreferredVariant() );
118 $htmlVariantLanguage = $langCode;
121 $oldPageConfig =
null;
122 $oldPageBundle =
null;
129 $doSample = ( $sampleRate && mt_rand( 1, $sampleRate ) === 1 );
130 if ( $doSample && $previousOutput !==
null && $previousOutput->
getCacheRevisionId() ) {
133 $oldPageConfig = $this->pageConfigFactory->createFromParserOptions(
135 Title::newFromLinkTarget( $pageConfig->getLinkTarget() ),
146 'pageBundle' =>
true,
147 'wrapSections' =>
true,
148 'logLinterData' =>
true,
149 'body_only' =>
false,
150 'htmlVariantLanguage' => $htmlVariantLanguage,
151 'offsetType' =>
'byte',
152 'outputContentVersion' => Parsoid::defaultHTMLVersion(),
153 'previousOutput' => $oldPageBundle,
154 'previousInput' => $oldPageConfig,
156 'sampleStats' => $doSample,
158 'userAgent' => RequestContext::getMain()->getRequest()->getHeader(
'User-Agent' ),
161 $parserOutput->resetParseStartTime();
165 $pageBundle = $this->parsoid->wikitext2html(
175 $parserOutput->setExtensionData(
176 self::PARSOID_TITLE_KEY,
177 Title::newFromLinkTarget( $pageConfig->getLinkTarget() )->getPrefixedDBkey()
184 $parserOutput->setFromParserOptions( $options );
186 $parserOutput->recordTimeProfile();
187 $this->dataAccess->makeLimitReport( $pageConfig, $options, $parserOutput );
193 'type' => $previousOutput ===
null ?
'full' :
'selective',
194 'wiki' => WikiMap::getCurrentWikiId(),
196 'has_async_content' =>
197 $parserOutput->getOutputFlag( ParserOutputFlags::HAS_ASYNC_CONTENT )
200 $parserOutput->getOutputFlag( ParserOutputFlags::ASYNC_NOT_READY )
204 ->getCounter(
'Parsoid_parse_cpu_seconds' )
205 ->setLabels( $labels )
206 ->incrementBy( $parserOutput->getTimeProfile(
'cpu' ) );
208 ->getCounter(
'Parsoid_parse_total' )
209 ->setLabels( $labels )
213 $parserOutput->addModuleStyles( [
'mediawiki.skinning.content.parsoid' ] );
218 $parserOutput->setExtensionData(
219 'core:parsoid-version', Parsoid::version()
221 $parserOutput->setExtensionData(
222 'core:html-version', Parsoid::defaultHTMLVersion()
225 return $parserOutput;
250 bool $linestart =
true,
bool $clearState =
true, ?
int $revId =
null,
253 Assert::invariant( $linestart,
'$linestart=false is not yet supported' );
254 Assert::invariant( $clearState,
'$clearState=false is not yet supported' );
255 $title = Title::newFromPageReference( $page );
260 $pageConfig = $revId ===
null || $revId === 0 ? null : $this->pageConfigFactory->createFromParserOptions(
269 $text = $content->getText();
271 if ( !( $pageConfig && $pageConfig->getPageMainContent() === $text ) ) {
277 if ( $revId !==
null ) {
278 $revisionRecord->setId( $revId );
280 $revisionRecord->setSlot(
281 SlotRecord::newUnsaved(
283 $content ??
new WikitextContent( $text )
286 $pageConfig = $this->pageConfigFactory->createFromParserOptions(
294 return $this->genParserOutput( $pageConfig, $options, $previousOutput );
313 $title = Title::newFromPageReference( $page );
318 $pageConfig = $this->pageConfigFactory->createFromParserOptions(
325 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 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.