MediaWiki master
OutputTransformPipeline.php
Go to the documentation of this file.
1<?php
2declare( strict_types = 1 );
3
5
9
14
16 private array $stages = [];
17
19 $this->stages[] = $stage;
20 return $this;
21 }
22
62 public function run( ParserOutput $in, ParserOptions $popts, array $options ): ParserOutput {
63 // Initialize some $options from the ParserOutput
64 $options += [
65 'enableSectionEditLinks' => !$in->getOutputFlag( ParserOutputFlags::NO_SECTION_EDIT_LINKS ),
66 'wrapperDivClass' => $in->getWrapperDivClass(),
67 ];
68 $oldWatcher = false;
69 if ( $options['allowClone'] ?? true ) {
70 $out = clone $in;
71 $oldWatcher = $popts->registerWatcher( $out->recordOption( ... ) );
72 } else {
73 // T353257: This should be a clone, but we've need to suppress it
74 // for some legacy codepaths.
75 $out = $in;
76 }
77
78 foreach ( $this->stages as $stage ) {
79 if ( $stage->shouldRun( $out, $popts, $options ) ) {
80 // Some stages may (for now) modify $options. See OutputTransformStage documentation for more info.
81 $out = $stage->transform( $out, $popts, $options );
82 }
83 }
84 if ( $oldWatcher !== false ) {
85 $popts->registerWatcher( $oldWatcher );
86 }
87 return $out;
88 }
89}
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.