MediaWiki  1.33.0
RemexDriver.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Tidy;
4 
5 use RemexHtml\Serializer\Serializer;
6 use RemexHtml\Serializer\SerializerWithTracer;
7 use RemexHtml\Tokenizer\Tokenizer;
8 use RemexHtml\TreeBuilder\Dispatcher;
9 use RemexHtml\TreeBuilder\TreeBuilder;
10 use RemexHtml\TreeBuilder\TreeMutationTracer;
11 
12 class RemexDriver extends TidyDriverBase {
15  private $mungerTrace;
16  private $pwrap;
17 
18  public function __construct( array $config ) {
19  $config += [
20  'treeMutationTrace' => false,
21  'serializerTrace' => false,
22  'mungerTrace' => false,
23  'pwrap' => true
24  ];
25  $this->treeMutationTrace = $config['treeMutationTrace'];
26  $this->serializerTrace = $config['serializerTrace'];
27  $this->mungerTrace = $config['mungerTrace'];
28  $this->pwrap = $config['pwrap'];
29  parent::__construct( $config );
30  }
31 
32  public function tidy( $text ) {
33  $traceCallback = function ( $msg ) {
34  wfDebug( "RemexHtml: $msg" );
35  };
36 
37  $formatter = new RemexCompatFormatter;
38  if ( $this->serializerTrace ) {
39  $serializer = new SerializerWithTracer( $formatter, null, $traceCallback );
40  } else {
41  $serializer = new Serializer( $formatter );
42  }
43  if ( $this->pwrap ) {
44  $munger = new RemexCompatMunger( $serializer, $this->mungerTrace );
45  } else {
46  $munger = $serializer;
47  }
48  if ( $this->treeMutationTrace ) {
49  $tracer = new TreeMutationTracer( $munger, $traceCallback );
50  } else {
51  $tracer = $munger;
52  }
53  $treeBuilder = new TreeBuilder( $tracer, [
54  'ignoreErrors' => true,
55  'ignoreNulls' => true,
56  ] );
57  $dispatcher = new Dispatcher( $treeBuilder );
58  $tokenizer = new Tokenizer( $dispatcher, $text, [
59  'ignoreErrors' => true,
60  'ignoreCharRefs' => true,
61  'ignoreNulls' => true,
62  'skipPreprocess' => true,
63  ] );
64 
65  $tokenizer->execute( [
66  'fragmentNamespace' => \RemexHtml\HTMLData::NS_HTML,
67  'fragmentName' => 'body'
68  ] );
69  return $serializer->getResult();
70  }
71 }
MediaWiki\Tidy\RemexCompatMunger
Definition: RemexCompatMunger.php:17
MediaWiki\Tidy\RemexDriver\$treeMutationTrace
$treeMutationTrace
Definition: RemexDriver.php:13
MediaWiki\Tidy\RemexCompatFormatter
Definition: RemexCompatFormatter.php:12
MediaWiki\Tidy\RemexDriver\$pwrap
$pwrap
Definition: RemexDriver.php:16
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Tidy\RemexDriver
Definition: RemexDriver.php:12
MediaWiki\Tidy\RemexDriver\$serializerTrace
$serializerTrace
Definition: RemexDriver.php:14
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Tidy\RemexDriver\$mungerTrace
$mungerTrace
Definition: RemexDriver.php:15
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:949
MediaWiki\Tidy\TidyDriverBase
Base class for HTML cleanup utilities.
Definition: TidyDriverBase.php:8
MediaWiki\Tidy\RemexDriver\tidy
tidy( $text)
Clean up HTML.
Definition: RemexDriver.php:32
MediaWiki\Tidy\RemexDriver\__construct
__construct(array $config)
Definition: RemexDriver.php:18
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1985
MediaWiki\Tidy\TidyDriverBase\$config
$config
Definition: TidyDriverBase.php:9
MediaWiki\Tidy
Definition: RemexCompatFormatter.php:3