MediaWiki master
ContentDOMTransformStage.php
Go to the documentation of this file.
1<?php
2
4
8use Wikimedia\Parsoid\Core\PageBundle;
9use Wikimedia\Parsoid\DOM\Document;
10use Wikimedia\Parsoid\Mocks\MockEnv;
11use Wikimedia\Parsoid\Utils\ContentUtils;
12use Wikimedia\Parsoid\Utils\DOMCompat;
13use Wikimedia\Parsoid\Utils\DOMDataUtils;
14use Wikimedia\Parsoid\Utils\DOMUtils;
15
25
29 public function transform( ParserOutput $po, ?ParserOptions $popts, array &$options ): ParserOutput {
30 // TODO will use HTMLHolder in the future
31 $doc = null;
33 if ( $hasPageBundle ) {
35 $doc = DOMUtils::parseHTML( $po->getContentHolderText() );
36 PageBundle::apply( $doc, $pb );
37 DOMDataUtils::prepareDoc( $doc );
38 DOMDataUtils::visitAndLoadDataAttribs(
39 DOMCompat::getBody( $doc )
40 );
41 } else {
42 $doc = ContentUtils::createAndLoadDocument(
44 );
45 }
46
47 $doc = $this->transformDOM( $doc, $po, $popts, $options );
48
49 // TODO will use HTMLHolder in the future
50 if ( $hasPageBundle ) {
51 DOMDataUtils::visitAndStoreDataAttribs(
52 DOMCompat::getBody( $doc ),
53 [
54 'storeInPageBundle' => true,
55 'env' => new MockEnv( [] ),
56 ]
57 );
58 $pb = DOMDataUtils::getPageBundle( $doc );
60 $pb, $po
61 );
62 $text = ContentUtils::toXML( DOMCompat::getBody( $doc ), [
63 'innerXML' => true,
64 ] );
65 } else {
66 $text = ContentUtils::ppToXML( DOMCompat::getBody( $doc ), [
67 'innerXML' => true,
68 ] );
69 }
70 $po->setContentHolderText( $text );
71 return $po;
72 }
73
75 abstract public function transformDOM(
76 Document $dom, ParserOutput $po, ?ParserOptions $popts, array &$options
77 ): Document;
78
79}
OutputTransformStages that modify the content as a HTML DOM tree.
transformDOM(Document $dom, ParserOutput $po, ?ParserOptions $popts, array &$options)
Applies the transformation to a DOM document.
transform(ParserOutput $po, ?ParserOptions $popts, array &$options)
Transforms the input ParserOutput into the returned ParserOutput.The returned ParserOutput can explic...
ParserOutput is a rendering of a Content object or a message.
getContentHolderText()
Returns the content holder text of the ParserOutput.
setContentHolderText(string $s)
Sets the content holder text of the ParserOutput.
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.
Set options of the Parser.
Classes implementing the OutputTransformStage aim at being added to a pipeline of transformations tha...