MediaWiki master
RemexCompatBuilder.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Tidy;
4
5use Wikimedia\RemexHtml\TreeBuilder\Marker;
6use Wikimedia\RemexHtml\TreeBuilder\TreeBuilder;
7
11class RemexCompatBuilder extends TreeBuilder {
13 public function reconstructAFE( $sourceStart ) {
14 // These checks are redundant with the parent, but here for performance
15 $entry = $this->afe->getTail();
16 if ( !$entry || $entry instanceof Marker || $entry->stackIndex !== null ) {
17 return;
18 }
19
20 // Don't reconstruct AFE in file figures to respect the spec,
21 // https://www.mediawiki.org/wiki/Specs/HTML#Media
22 $len = $this->stack->length();
23 while ( $len > 0 ) {
24 $i = $this->stack->item( $len - 1 );
25 if ( $i->htmlName === 'figcaption' ) {
26 break;
27 }
28 if ( $i->htmlName === 'figure' ) {
29 foreach ( $i->attrs->getValues() as $k => $v ) {
30 if ( $k === 'typeof' && preg_match( '/\bmw:File\b/', $v ) ) {
31 return;
32 }
33 }
34 break;
35 }
36 $len--;
37 }
38 parent::reconstructAFE( $sourceStart );
39 }
40}