MediaWiki master
OutputTransformPipeline.php
Go to the documentation of this file.
1<?php
2declare( strict_types = 1 );
3
5
8
13
15 private array $stages = [];
16
18 $this->stages[] = $stage;
19 return $this;
20 }
21
61 public function run( ParserOutput $in, ParserOptions $popts, array $options ): ParserOutput {
62 // Initialize some $options from the ParserOutput
63 $options += [
64 'wrapperDivClass' => $in->getWrapperDivClass(),
65 ];
66 $oldWatcher = false;
67 if ( $options['allowClone'] ?? true ) {
68 $out = clone $in;
69 $oldWatcher = $popts->registerWatcher( $out->recordOption( ... ) );
70 } else {
71 // T353257: This should be a clone, but we've need to suppress it
72 // for some legacy codepaths.
73 $out = $in;
74 }
75
76 foreach ( $this->stages as $stage ) {
77 if ( $stage->shouldRun( $out, $popts, $options ) ) {
78 // Some stages may (for now) modify $options. See OutputTransformStage documentation for more info.
79 $out = $stage->transform( $out, $popts, $options );
80 }
81 }
82 if ( $oldWatcher !== false ) {
83 $popts->registerWatcher( $oldWatcher );
84 }
85 return $out;
86 }
87}
run(ParserOutput $in, ParserOptions $popts, array $options)
Runs the pipeline on the ParserOutput, yielding a transformed ParserOutput.
Classes implementing the OutputTransformStage aim at being added to a pipeline of transformations tha...
Set options of the Parser.
registerWatcher( $callback)
Registers a callback for tracking which ParserOptions which are used.
ParserOutput is a rendering of a Content object or a message.