26use InvalidArgumentException;
31use Psr\Log\LoggerInterface;
32use Psr\Log\NullLogger;
75 $this->roleRegistery = $roleRegistry;
78 $this->saveParseLogger =
new NullLogger();
114 if ( $rev->
getWikiId() !== $this->dbDomain ) {
115 throw new InvalidArgumentException(
'Mismatching wiki ID ' . $rev->
getWikiId() );
118 $audience = $hints[
'audience']
128 $options = ParserOptions::newCanonical(
129 $forPerformer ? $forPerformer->getUser() :
'canonical'
133 $usePrimary = $hints[
'use-master'] ??
false;
135 $dbIndex = $usePrimary
139 $options->setSpeculativeRevIdCallback(
function () use ( $dbIndex ) {
142 $options->setSpeculativePageIdCallback(
function () use ( $dbIndex ) {
156 $this->contentRenderer,
166 if ( isset( $hints[
'known-revision-output'] ) ) {
167 $renderedRevision->setRevisionParserOutput( $hints[
'known-revision-output'] );
170 return $renderedRevision;
176 $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
178 $db = $this->loadBalancer->getConnectionRef( $dbIndex, [], $this->dbDomain, $flags );
180 return 1 + (int)$db->selectField(
191 $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
193 $db = $this->loadBalancer->getConnectionRef( $dbIndex, [], $this->dbDomain, $flags );
195 return 1 + (int)$db->selectField(
215 $slots = $revision->getSlots()->getSlots();
217 $withHtml = $hints[
'generate-html'] ??
true;
233 $options->registerWatcher( [ $combinedOutput,
'recordOption' ] );
235 foreach ( $slots as $role => $slot ) {
237 $slotOutput[$role] = $out;
240 $combinedOutput->mergeInternalMetaDataFrom( $out );
241 $combinedOutput->mergeTrackingMetaDataFrom( $out );
248 foreach ( $slotOutput as $role => $out ) {
249 $roleHandler = $this->roleRegistery->getRoleHandler( $role );
252 $layout = $roleHandler->getOutputLayoutHints();
253 $display = $layout[
'display'] ??
'section';
255 if ( $display ===
'none' ) {
264 $headText = Html::element(
'mw:slotheader', [], $role );
265 $html .= Html::rawElement(
'h1', [
'class' =>
'mw-slot-header' ], $headText );
270 $html .= $out->getRawText();
271 $combinedOutput->mergeHtmlMetaDataFrom( $out );
274 $combinedOutput->setText( $html );
277 $options->registerWatcher(
null );
278 return $combinedOutput;
This class is a collection of static functions that serve two purposes:
A service to render content.
Set options of the Parser.