48 private $saveParseLogger;
51 private $loadBalancer;
54 private $roleRegistery;
57 private $contentRenderer;
74 $this->loadBalancer = $loadBalancer;
75 $this->roleRegistery = $roleRegistry;
76 $this->contentRenderer = $contentRenderer;
77 $this->dbDomain = $dbDomain;
78 $this->saveParseLogger =
new NullLogger();
84 public function setLogger( LoggerInterface $saveParseLogger ) {
85 $this->saveParseLogger = $saveParseLogger;
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 ) {
140 return $this->getSpeculativeRevId( $dbIndex );
142 $options->setSpeculativePageIdCallback(
function () use ( $dbIndex ) {
143 return $this->getSpeculativePageId( $dbIndex );
156 $this->contentRenderer,
158 return $this->combineSlotOutput( $rrev, $hints );
166 if ( isset( $hints[
'known-revision-output'] ) ) {
167 $renderedRevision->setRevisionParserOutput( $hints[
'known-revision-output'] );
170 return $renderedRevision;
173 private function getSpeculativeRevId( $dbIndex ) {
176 $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
178 $db = $this->loadBalancer->getConnectionRef( $dbIndex, [], $this->dbDomain, $flags );
180 return 1 + (int)$db->selectField(
188 private function getSpeculativePageId( $dbIndex ) {
191 $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
193 $db = $this->loadBalancer->getConnectionRef( $dbIndex, [], $this->dbDomain, $flags );
195 return 1 + (int)$db->selectField(
213 private function combineSlotOutput( RenderedRevision $rrev, array $hints = [] ) {
214 $revision = $rrev->getRevision();
215 $slots = $revision->getSlots()->getSlots();
217 $withHtml = $hints[
'generate-html'] ??
true;
232 $options = $rrev->getOptions();
233 $options->registerWatcher( [ $combinedOutput,
'recordOption' ] );
235 foreach ( $slots as $role => $slot ) {
236 $out = $rrev->getSlotParserOutput( $role, $hints );
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' ) {
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;
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).