MediaWiki REL1_40
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
43 public static function parserOutputFromPageBundle(
44 PageBundle $pageBundle, ?ParserOutput $parserOutput = null
45 ): ParserOutput {
46 if ( $parserOutput === null ) {
47 $parserOutput = new ParserOutput( $pageBundle->html );
48 } else {
49 $parserOutput->setText( $pageBundle->html );
50 }
51 $parserOutput->setExtensionData(
52 self::PARSOID_PAGE_BUNDLE_KEY,
53 [
54 'parsoid' => $pageBundle->parsoid,
55 'mw' => $pageBundle->mw,
56 'version' => $pageBundle->version,
57 'headers' => $pageBundle->headers,
58 'contentmodel' => $pageBundle->contentmodel,
59 ]
60 );
61
62 return $parserOutput;
63 }
64
72 public static function pageBundleFromParserOutput( ParserOutput $parserOutput ): PageBundle {
73 $pageBundleData = $parserOutput->getExtensionData( self::PARSOID_PAGE_BUNDLE_KEY );
74 return new PageBundle(
75 $parserOutput->getRawText(),
76 $pageBundleData['parsoid'] ?? [],
77 $pageBundleData['mw'] ?? [],
78 // It would be nice to have this be "null", but PageBundle::responseData()
79 // chocks on that: T325137.
80 $pageBundleData['version'] ?? '0.0.0',
81 $pageBundleData['headers'] ?? [],
82 $pageBundleData['contentmodel'] ?? null
83 );
84 }
85
86}
getExtensionData()
Get the extension data as: augmentor name => data.
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:88
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 $parserOutput=null)
Creates a ParserOutput object containing the relevant data from the given PageBundle object.
getRawText()
Get the cacheable text with <mw:editsection> markers still in it.
Copyright (C) 2011-2022 Wikimedia Foundation and others.