MediaWiki REL1_40
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 {
12 public function reconstructAFE( $sourceStart ) {
13 // These checks are redundant with the parent, but here for performance
14 $entry = $this->afe->getTail();
15 if ( !$entry ) {
16 return;
17 }
18 if ( $entry instanceof Marker ) {
19 return;
20 }
21 if ( $entry->stackIndex !== null ) {
22 return;
23 }
24
25 // Don't reconstruct AFE in file figures to respect the spec,
26 // https://www.mediawiki.org/wiki/Specs/HTML#Media
27 $len = $this->stack->length();
28 while ( $len > 0 ) {
29 $i = $this->stack->item( $len - 1 );
30 if ( $i->htmlName === 'figcaption' ) {
31 break;
32 }
33 if ( $i->htmlName === 'figure' ) {
34 foreach ( $i->attrs->getValues() as $k => $v ) {
35 if ( $k === 'typeof' && preg_match( '/\bmw:File\b/', $v ) ) {
36 return;
37 }
38 }
39 break;
40 }
41 $len -= 1;
42 }
43 parent::reconstructAFE( $sourceStart );
44 }
45}