26use InvalidArgumentException;
29use Psr\Log\LoggerInterface;
30use Psr\Log\NullLogger;
70 $this->roleRegistery = $roleRegistry;
72 $this->saveParseLogger =
new NullLogger();
105 User $forUser =
null,
108 if ( $rev->
getWikiId() !== $this->dbDomain ) {
109 throw new InvalidArgumentException(
'Mismatching wiki ID ' . $rev->
getWikiId() );
112 $audience = $hints[
'audience']
122 $options = ParserOptions::newCanonical( $forUser ?:
'canonical' );
125 $useMaster = $hints[
'use-master'] ??
false;
127 $dbIndex = $useMaster
131 $options->setSpeculativeRevIdCallback(
function () use ( $dbIndex ) {
134 $options->setSpeculativePageIdCallback(
function () use ( $dbIndex ) {
160 if ( isset( $hints[
'known-revision-output'] ) ) {
161 $renderedRevision->setRevisionParserOutput( $hints[
'known-revision-output'] );
164 return $renderedRevision;
170 $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
172 $db = $this->loadBalancer->getConnectionRef( $dbIndex, [], $this->dbDomain, $flags );
174 return 1 + (int)$db->selectField(
185 $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
187 $db = $this->loadBalancer->getConnectionRef( $dbIndex, [], $this->dbDomain, $flags );
189 return 1 + (int)$db->selectField(
209 $slots = $revision->getSlots()->getSlots();
211 $withHtml = $hints[
'generate-html'] ??
true;
227 $options->registerWatcher( [ $combinedOutput,
'recordOption' ] );
229 foreach ( $slots as $role => $slot ) {
231 $slotOutput[$role] = $out;
234 $combinedOutput->mergeInternalMetaDataFrom( $out );
235 $combinedOutput->mergeTrackingMetaDataFrom( $out );
242 foreach ( $slotOutput as $role => $out ) {
243 $roleHandler = $this->roleRegistery->getRoleHandler( $role );
246 $layout = $roleHandler->getOutputLayoutHints();
247 $display = $layout[
'display'] ??
'section';
249 if ( $display ===
'none' ) {
258 $headText = Html::element(
'mw:slotheader', [], $role );
259 $html .= Html::rawElement(
'h1', [
'class' =>
'mw-slot-header' ], $headText );
264 $html .= $out->getRawText();
265 $combinedOutput->mergeHtmlMetaDataFrom( $out );
268 $combinedOutput->setText( $html );
271 $options->registerWatcher(
null );
272 return $combinedOutput;
This class is a collection of static functions that serve two purposes:
Set options of the Parser.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...