MediaWiki REL1_41
PageBundleParserOutputConverter.php
Go to the documentation of this file.
1<?php
2
4
6use Wikimedia\Parsoid\Core\PageBundle;
7
19 public const PARSOID_PAGE_BUNDLE_KEY = 'parsoid-page-bundle';
20
25 private function __construct() {
26 }
27
42 public static function parserOutputFromPageBundle(
43 PageBundle $pageBundle, ?ParserOutput $originalParserOutput = null
44 ): ParserOutput {
45 $parserOutput = new ParserOutput( $pageBundle->html );
46
47 if ( $originalParserOutput ) {
48 $parserOutput->mergeHtmlMetaDataFrom( $originalParserOutput );
49 $parserOutput->mergeTrackingMetaDataFrom( $originalParserOutput );
50 $parserOutput->mergeInternalMetaDataFrom( $originalParserOutput );
51 }
52
53 $parserOutput->setExtensionData(
54 self::PARSOID_PAGE_BUNDLE_KEY,
55 [
56 'parsoid' => $pageBundle->parsoid,
57 'mw' => $pageBundle->mw,
58 'version' => $pageBundle->version,
59 'headers' => $pageBundle->headers,
60 'contentmodel' => $pageBundle->contentmodel,
61 ]
62 );
63
64 return $parserOutput;
65 }
66
74 public static function pageBundleFromParserOutput( ParserOutput $parserOutput ): PageBundle {
75 $pageBundleData = $parserOutput->getExtensionData( self::PARSOID_PAGE_BUNDLE_KEY );
76 return new PageBundle(
77 $parserOutput->getRawText(),
78 $pageBundleData['parsoid'] ?? [],
79 $pageBundleData['mw'] ?? [],
80 // It would be nice to have this be "null", but PageBundle::responseData()
81 // chocks on that: T325137.
82 $pageBundleData['version'] ?? '0.0.0',
83 $pageBundleData['headers'] ?? [],
84 $pageBundleData['contentmodel'] ?? null
85 );
86 }
87
88 public static function hasPageBundle( ParserOutput $parserOutput ) {
89 return $parserOutput->getExtensionData( self::PARSOID_PAGE_BUNDLE_KEY ) !== null;
90 }
91}
getExtensionData()
Get the extension data as: augmentor name => data.
Provides methods for conversion between PageBundle and ParserOutput TODO: Convert to a trait once we ...
static pageBundleFromParserOutput(ParserOutput $parserOutput)
Returns a Parsoid PageBundle equivalent to the given ParserOutput.
static parserOutputFromPageBundle(PageBundle $pageBundle, ?ParserOutput $originalParserOutput=null)
Creates a ParserOutput object containing the relevant data from the given PageBundle object.
Rendered output of a wiki page, as parsed from wikitext.
mergeHtmlMetaDataFrom(ParserOutput $source)
Merges HTML metadata such as head items, JS config vars, and HTTP cache control info from $source int...
getExtensionData( $key)
Gets extensions data previously attached to this ParserOutput using setExtensionData().
getRawText()
Get the cacheable text with <mw:editsection> markers still in it.
Copyright (C) 2011-2022 Wikimedia Foundation and others.