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