Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ProcessEmbeddedDocs | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
| processNode | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
72 | |||
| run | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\Parsoid\Wt2Html\DOM\Processors; |
| 5 | |
| 6 | use stdClass; |
| 7 | use Wikimedia\Parsoid\Config\Env; |
| 8 | use Wikimedia\Parsoid\Core\DOMCompat; |
| 9 | use Wikimedia\Parsoid\DOM\DocumentFragment; |
| 10 | use Wikimedia\Parsoid\DOM\Element; |
| 11 | use Wikimedia\Parsoid\DOM\Node; |
| 12 | use Wikimedia\Parsoid\Utils\ContentUtils; |
| 13 | use Wikimedia\Parsoid\Utils\DOMDataUtils; |
| 14 | use Wikimedia\Parsoid\Utils\DOMUtils; |
| 15 | use Wikimedia\Parsoid\Utils\PipelineUtils; |
| 16 | use Wikimedia\Parsoid\Utils\WTUtils; |
| 17 | use Wikimedia\Parsoid\Wt2Html\Wt2HtmlDOMProcessor; |
| 18 | |
| 19 | class ProcessEmbeddedDocs implements Wt2HtmlDOMProcessor { |
| 20 | private Env $env; |
| 21 | |
| 22 | private function processNode( Node $root, ?stdClass $tplInfo = null ): void { |
| 23 | $node = $root->firstChild; |
| 24 | |
| 25 | while ( $node !== null ) { |
| 26 | if ( !$node instanceof Element ) { |
| 27 | $node = $node->nextSibling; |
| 28 | continue; |
| 29 | } |
| 30 | |
| 31 | if ( !$tplInfo && WTUtils::isFirstEncapsulationWrapperNode( $node ) ) { |
| 32 | $aboutSibs = WTUtils::getAboutSiblings( |
| 33 | $node, DOMCompat::getAttribute( $node, 'about' ) |
| 34 | ); |
| 35 | $tplInfo = (object)[ |
| 36 | 'first' => $node, |
| 37 | 'last' => end( $aboutSibs ), |
| 38 | 'dsr' => DOMDataUtils::getDataParsoid( $node )->dsr ?? null, |
| 39 | 'isTemplated' => DOMUtils::hasTypeOf( $node, 'mw:Transclusion' ), |
| 40 | ]; |
| 41 | } |
| 42 | |
| 43 | ContentUtils::processAttributeEmbeddedDom( |
| 44 | $this->env->getSiteConfig(), |
| 45 | $node, |
| 46 | function ( DocumentFragment $df ) use ( $tplInfo ) { |
| 47 | PipelineUtils::processContentInPipeline( |
| 48 | $this->env, |
| 49 | $this->env->topFrame, |
| 50 | $df, |
| 51 | [ |
| 52 | 'pipelineType' => 'fullparse-embedded-docs-dom-to-dom', |
| 53 | 'pipelineOpts' => [], |
| 54 | 'sol' => true, |
| 55 | 'tplInfo' => ( $tplInfo->isTemplated ?? false ) ? $tplInfo : null, |
| 56 | ], |
| 57 | ); |
| 58 | return true; // might have been changed. |
| 59 | } |
| 60 | ); |
| 61 | |
| 62 | $this->processNode( $node, $tplInfo ); |
| 63 | |
| 64 | if ( $tplInfo && $tplInfo->last === $node ) { |
| 65 | $tplInfo = null; |
| 66 | } |
| 67 | |
| 68 | $node = $node->nextSibling; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * DOM Postprocessor entry function to walk DOM rooted at $root |
| 74 | * and convert the DSR offsets as needed. |
| 75 | * @see ConvertUtils::convertOffsets |
| 76 | * |
| 77 | * @inheritDoc |
| 78 | */ |
| 79 | public function run( |
| 80 | Env $env, Node $root, array $options = [], bool $atTopLevel = false |
| 81 | ): void { |
| 82 | $this->env = $env; |
| 83 | $this->processNode( $root ); |
| 84 | } |
| 85 | } |