MediaWiki  1.30.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\Tokenizer\Tokenizer;
7 use RemexHtml\TreeBuilder\Dispatcher;
8 use RemexHtml\TreeBuilder\TreeBuilder;
9 use RemexHtml\TreeBuilder\TreeMutationTracer;
10 
11 class RemexDriver extends TidyDriverBase {
12  private $trace;
13  private $pwrap;
14 
15  public function __construct( array $config ) {
16  $config += [
17  'treeMutationTrace' => false,
18  'pwrap' => true
19  ];
20  $this->trace = $config['treeMutationTrace'];
21  $this->pwrap = $config['pwrap'];
22  parent::__construct( $config );
23  }
24 
25  public function tidy( $text ) {
26  $formatter = new RemexCompatFormatter;
27  $serializer = new Serializer( $formatter );
28  if ( $this->pwrap ) {
29  $munger = new RemexCompatMunger( $serializer );
30  } else {
31  $munger = $serializer;
32  }
33  if ( $this->trace ) {
34  $tracer = new TreeMutationTracer( $munger, function ( $msg ) {
35  wfDebug( "RemexHtml: $msg" );
36  } );
37  } else {
38  $tracer = $munger;
39  }
40  $treeBuilder = new TreeBuilder( $tracer, [
41  'ignoreErrors' => true,
42  'ignoreNulls' => true,
43  ] );
44  $dispatcher = new Dispatcher( $treeBuilder );
45  $tokenizer = new Tokenizer( $dispatcher, $text, [
46  'ignoreErrors' => true,
47  'ignoreCharRefs' => true,
48  'ignoreNulls' => true,
49  'skipPreprocess' => true,
50  ] );
51  $tokenizer->execute( [
52  'fragmentNamespace' => \RemexHtml\HTMLData::NS_HTML,
53  'fragmentName' => 'body'
54  ] );
55  return $serializer->getResult();
56  }
57 }
MediaWiki\Tidy\RemexCompatMunger
Definition: RemexCompatMunger.php:17
MediaWiki\Tidy\RemexDriver\$trace
$trace
Definition: RemexDriver.php:12
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\RemexCompatFormatter
Definition: RemexCompatFormatter.php:12
MediaWiki\Tidy\RemexDriver\$pwrap
$pwrap
Definition: RemexDriver.php:13
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:11
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:1047
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:25
MediaWiki\Tidy\RemexDriver\__construct
__construct(array $config)
Definition: RemexDriver.php:15
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:1965
MediaWiki\Tidy\TidyDriverBase\$config
$config
Definition: TidyDriverBase.php:9
MediaWiki\Tidy
Definition: Balancer.php:26
array
the array() calling protocol came about after MediaWiki 1.4rc1.