Use the new RemexHtml trace features. Add two more tracing modes.
Fix missing member variable declarations and remove unused local
variables.
Change-Id: I512462e1019f9a466684abfa4aab7697b324d5b1
+ /** @var Serializer */
+ private $serializer;
+
+ /** @var bool */
+ private $trace;
+
/**
* @param Serializer $serializer
/**
* @param Serializer $serializer
- public function __construct( Serializer $serializer ) {
+ public function __construct( Serializer $serializer, $trace = false ) {
$this->serializer = $serializer;
$this->serializer = $serializer;
}
public function startDocument( $fragmentNamespace, $fragmentName ) {
}
public function startDocument( $fragmentNamespace, $fragmentName ) {
}
private function trace( $msg ) {
}
private function trace( $msg ) {
- // echo "[RCM] $msg\n";
+ if ( $this->trace ) {
+ wfDebug( "[RCM] $msg" );
+ }
) {
list( $parent, $newRef ) = $this->getParentForInsert( $preposition, $refElement );
$parentData = $parent->snData;
) {
list( $parent, $newRef ) = $this->getParentForInsert( $preposition, $refElement );
$parentData = $parent->snData;
- $parentNs = $parent->namespace;
- $parentName = $parent->name;
$elementName = $element->htmlName;
$inline = isset( self::$onlyInlineElements[$elementName] );
$under = $preposition === TreeBuilder::UNDER;
$elementName = $element->htmlName;
$inline = isset( self::$onlyInlineElements[$elementName] );
$under = $preposition === TreeBuilder::UNDER;
if ( $under && $parentData->isPWrapper && !$inline ) {
// [B/b] The element is non-inline and the parent is a p-wrapper,
if ( $under && $parentData->isPWrapper && !$inline ) {
// [B/b] The element is non-inline and the parent is a p-wrapper,
$root = $serializer->getRootNode();
$nodes = [];
$removableNodes = [];
$root = $serializer->getRootNode();
$nodes = [];
$removableNodes = [];
while ( $node !== $cloneEnd ) {
$nextParent = $serializer->getParentNode( $node );
if ( $nextParent === $root ) {
while ( $node !== $cloneEnd ) {
$nextParent = $serializer->getParentNode( $node );
if ( $nextParent === $root ) {
namespace MediaWiki\Tidy;
use RemexHtml\Serializer\Serializer;
namespace MediaWiki\Tidy;
use RemexHtml\Serializer\Serializer;
+use RemexHtml\Serializer\SerializerWithTracer;
use RemexHtml\Tokenizer\Tokenizer;
use RemexHtml\TreeBuilder\Dispatcher;
use RemexHtml\TreeBuilder\TreeBuilder;
use RemexHtml\TreeBuilder\TreeMutationTracer;
class RemexDriver extends TidyDriverBase {
use RemexHtml\Tokenizer\Tokenizer;
use RemexHtml\TreeBuilder\Dispatcher;
use RemexHtml\TreeBuilder\TreeBuilder;
use RemexHtml\TreeBuilder\TreeMutationTracer;
class RemexDriver extends TidyDriverBase {
+ private $treeMutationTrace;
+ private $serializerTrace;
+ private $mungerTrace;
private $pwrap;
public function __construct( array $config ) {
$config += [
'treeMutationTrace' => false,
private $pwrap;
public function __construct( array $config ) {
$config += [
'treeMutationTrace' => false,
+ 'serializerTrace' => false,
+ 'mungerTrace' => false,
- $this->trace = $config['treeMutationTrace'];
+ $this->treeMutationTrace = $config['treeMutationTrace'];
+ $this->serializerTrace = $config['serializerTrace'];
+ $this->mungerTrace = $config['mungerTrace'];
$this->pwrap = $config['pwrap'];
parent::__construct( $config );
}
public function tidy( $text ) {
$this->pwrap = $config['pwrap'];
parent::__construct( $config );
}
public function tidy( $text ) {
+ $traceCallback = function ( $msg ) {
+ wfDebug( "RemexHtml: $msg" );
+ };
+
$formatter = new RemexCompatFormatter;
$formatter = new RemexCompatFormatter;
- $serializer = new Serializer( $formatter );
+ if ( $this->serializerTrace ) {
+ $serializer = new SerializerWithTracer( $formatter, null, $traceCallback );
+ } else {
+ $serializer = new Serializer( $formatter );
+ }
- $munger = new RemexCompatMunger( $serializer );
+ $munger = new RemexCompatMunger( $serializer, $this->mungerTrace );
} else {
$munger = $serializer;
}
} else {
$munger = $serializer;
}
- if ( $this->trace ) {
- $tracer = new TreeMutationTracer( $munger, function ( $msg ) {
- wfDebug( "RemexHtml: $msg" );
- } );
+ if ( $this->treeMutationTrace ) {
+ $tracer = new TreeMutationTracer( $munger, $traceCallback );
} else {
$tracer = $munger;
}
} else {
$tracer = $munger;
}
'ignoreNulls' => true,
'skipPreprocess' => true,
] );
'ignoreNulls' => true,
'skipPreprocess' => true,
] );
$tokenizer->execute( [
'fragmentNamespace' => \RemexHtml\HTMLData::NS_HTML,
'fragmentName' => 'body'
$tokenizer->execute( [
'fragmentNamespace' => \RemexHtml\HTMLData::NS_HTML,
'fragmentName' => 'body'