diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2024-09-06 19:37:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2024-09-06 19:37:11 +0000 |
commit | e9409ac31da01480342674d4bb0210f245a2a6ce (patch) | |
tree | bbc6edc88320c1a8a1a56c83227abd19606b7a4a /includes/parser/ParserOutput.php | |
parent | 1243bdf8ec02e25eb49aa852ca25bf3430b873c7 (diff) | |
parent | cd3240f04464281e5238eb418472373c5c43df3e (diff) | |
download | mediawikicore-e9409ac31da01480342674d4bb0210f245a2a6ce.tar.gz mediawikicore-e9409ac31da01480342674d4bb0210f245a2a6ce.zip |
Merge "Introduce runOutputPipeline and clone by default"
Diffstat (limited to 'includes/parser/ParserOutput.php')
-rw-r--r-- | includes/parser/ParserOutput.php | 78 |
1 files changed, 69 insertions, 9 deletions
diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 543036c9e50f..767c3e6c56e5 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -421,6 +421,8 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector { * T293512: in the future, ParserOutput::getText() will be deprecated in favor of invoking the * ParserOutputTransform pipeline directly on a ParserOutput. * @param array $options (since 1.31) Transformations to apply to the HTML + * - allowClone: (bool) Whether to clone the ParserOutput before + * applying transformations. Default is false. * - allowTOC: (bool) Show the TOC, assuming there were enough headings * to generate one and `__NOTOC__` wasn't used. Default is true, * but might be statefully overridden. @@ -456,10 +458,74 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector { * the default output pipeline on a ParserOutput. */ public function getText( $options = [] ) { - $pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline(); $oldText = $this->mRawText; // T353257 + $options += [ 'allowClone' => false ]; + $po = $this->runPipelineInternal( null, $options ); + $newText = $po->getContentHolderText(); + // T353257: for back-compat only mutations to metadata performed by + // the pipeline should be preserved; mutations to $mText should be + // discarded. + $this->setRawText( $oldText ); + return $newText; + } + + /** + * @unstable This method is transitional and will be replaced by a method + * in another class, maybe ContentRenderer. It allows us to break our + * porting work into two steps; in the first we bring ParserOptions to + * to each ::getText() callsite to ensure it is made available to the + * postprocessing pipeline. In the second we move this functionality + * into the Content hierarchy and out of ParserOutput, which should become + * a pure value object. + * + * @param ParserOptions $popts + * @param array $options (since 1.31) Transformations to apply to the HTML + * - allowClone: (bool) Whether to clone the ParserOutput before + * applying transformations. Default is true. + * - allowTOC: (bool) Show the TOC, assuming there were enough headings + * to generate one and `__NOTOC__` wasn't used. Default is true, + * but might be statefully overridden. + * - injectTOC: (bool) Replace the TOC_PLACEHOLDER with TOC contents; + * otherwise the marker will be left in the article (and the skin + * will be responsible for replacing or removing it). Default is + * true. + * - enableSectionEditLinks: (bool) Include section edit links, assuming + * section edit link tokens are present in the HTML. Default is true, + * but might be statefully overridden. + * - userLang: (Language) Language object used for localizing UX messages, + * for example the heading of the table of contents. If omitted, will + * use the language of the main request context. + * - skin: (Skin) Skin object used for transforming section edit links. + * - unwrap: (bool) Return text without a wrapper div. Default is false, + * meaning a wrapper div will be added if getWrapperDivClass() returns + * a non-empty string. + * - wrapperDivClass: (string) Wrap the output in a div and apply the given + * CSS class to that div. This overrides the output of getWrapperDivClass(). + * Setting this to an empty string has the same effect as 'unwrap' => true. + * - deduplicateStyles: (bool) When true, which is the default, `<style>` + * tags with the `data-mw-deduplicate` attribute set are deduplicated by + * value of the attribute: all but the first will be replaced by `<link + * rel="mw-deduplicated-inline-style" href="mw-data:..."/>` tags, where + * the scheme-specific-part of the href is the (percent-encoded) value + * of the `data-mw-deduplicate` attribute. + * - absoluteURLs: (bool) use absolute URLs in all links. Default: false + * - includeDebugInfo: (bool) render PP limit report in HTML. Default: false + * It is planned to eventually deprecate this $options array and to be able to + * pass its content in the $popts ParserOptions. + * @return ParserOutput + */ + public function runOutputPipeline( ParserOptions $popts, array $options = [] ): ParserOutput { + return $this->runPipelineInternal( $popts, $options ); + } + + /** + * Temporary helper method to allow running the pipeline with null $popts for now, although + * passing a null ParserOptions is a temporary backward-compatibility hack and will be deprecated. + */ + private function runPipelineInternal( ?ParserOptions $popts, array $options = [] ): ParserOutput { + $pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline(); $options += [ - 'suppressClone' => true, // T353257 + 'allowClone' => true, 'allowTOC' => true, 'injectTOC' => true, 'enableSectionEditLinks' => !$this->getOutputFlag( ParserOutputFlags::NO_SECTION_EDIT_LINKS ), @@ -472,13 +538,7 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector { 'includeDebugInfo' => false, 'isParsoidContent' => PageBundleParserOutputConverter::hasPageBundle( $this ), ]; - $po = $pipeline->run( $this, null, $options ); - $newText = $po->getContentHolderText(); - // T353257: for back-compat only mutations to metadata performed by - // the pipeline should be preserved; mutations to $mText should be - // discarded. - $this->setRawText( $oldText ); - return $newText; + return $pipeline->run( $this, null, $options ); } /** |